*/
if (!OidIsValid(param->ptype) && ext_params->paramFetch)
(*ext_params->paramFetch) (ext_params, i + 1);
+
/*
- * If parameter type is still not defined assume it is
- * unused
+ * If the parameter type is still not defined, assume that
+ * it is unused. But we put a default INT4OID type for such
+ * unused parameters to keep the parameter pushdown code
+ * happy.
+ *
+ * These unused parameters are never accessed during
+ * execution and we will just a null value for these
+ * "dummy" parameters. But including them here ensures that
+ * we send down the parameters in the correct order and at
+ * the position that the datanode needs
*/
- if (!OidIsValid(param->ptype))
- continue;
+ if (OidIsValid(param->ptype))
+ {
+ rstmt.remoteparams[paramno].paramused = 1;
+ rstmt.remoteparams[paramno].paramtype = param->ptype;
+ }
+ else
+ {
+ rstmt.remoteparams[paramno].paramused = 0;
+ rstmt.remoteparams[paramno].paramtype = INT4OID;
+ }
rstmt.remoteparams[paramno].paramkind = PARAM_EXTERN;
rstmt.remoteparams[paramno].paramid = i + 1;
- rstmt.remoteparams[paramno].paramtype = param->ptype;
paramno++;
}
/* store actual number of parameters */
rstmt.remoteparams[paramno].paramkind = PARAM_EXEC;
rstmt.remoteparams[paramno].paramid = i;
rstmt.remoteparams[paramno].paramtype = prmdata->ptype;
+ rstmt.remoteparams[paramno].paramused = 1;
/* Will scan plan tree to find out data type of the param */
if (prmdata->ptype == InvalidOid)
defineParams = bms_add_member(defineParams, i);
static void
-append_param_data(StringInfo buf, Oid ptype, Datum value, bool isnull)
+append_param_data(StringInfo buf, Oid ptype, int pused, Datum value, bool isnull)
{
uint32 n32;
+ /* Assume unused parameters to have null values */
+ if (!pused)
+ ptype = INT4OID;
+
if (isnull)
{
n32 = htonl(-1);
{
RemoteParam *rparam = &remoteparams[i];
int ptype = rparam->paramtype;
+ int pused = rparam->paramused;
if (rparam->paramkind == PARAM_EXTERN)
{
ParamExternData *param;
param = &(estate->es_param_list_info->params[rparam->paramid - 1]);
- append_param_data(&buf, ptype, param->value, param->isnull);
+ append_param_data(&buf, ptype, pused, param->value, param->isnull);
}
else
{
}
if (!param->done)
param->isnull = true;
- append_param_data(&buf, ptype, param->value, param->isnull);
+ append_param_data(&buf, ptype, pused, param->value, param->isnull);
}
}
$$;
ERROR: Internal subtransactions not supported in Postgres-XL
CONTEXT: PL/pgSQL function inline_code_block line 2 during statement block entry
+-- Check parameter handling
+BEGIN;
+DROP TABLE IF EXISTS testcase_13;
+NOTICE: table "testcase_13" does not exist, skipping
+CREATE TABLE testcase_13 (patient_id integer);
+INSERT INTO testcase_13 VALUES (1);
+DO $$
+DECLARE
+ r RECORD;
+BEGIN
+FOR r IN SELECT * FROM testcase_13 LOOP
+ RAISE INFO 'r.patient_id=%', r.patient_id;
+ IF (SELECT EXISTS (
+ SELECT FROM testcase_13 WHERE patient_id = r.patient_id
+ ))
+ THEN
+ RAISE INFO 'condition true';
+ END IF;
+ END LOOP;
+END $$;
+INFO: r.patient_id=1
+INFO: condition true
+ROLLBACK;