Explicitly track if a subplan has been executed and a valid value is computed
authorPavan Deolasee <[email protected]>
Wed, 20 Jul 2016 10:06:14 +0000 (15:36 +0530)
committerPavan Deolasee <[email protected]>
Wed, 20 Jul 2016 10:11:48 +0000 (15:41 +0530)
or not.

This works around a problem noted in issue #102, but not a full solution to the
problem. It seems there are places where InitPlan is attached to a node which
will be executed on the remote node. Even so coordinator tries to find push a
PARAM_EXEC parameter value for a remote subplan and fails because the value is
not and will never be computed on the coordinator. We for now send NULL value
for such cases to avoid a server crash

src/backend/executor/nodeNestloop.c
src/backend/executor/nodeSubplan.c
src/backend/pgxc/pool/execRemote.c
src/include/nodes/params.h

index e66bcdade716aadbee0074c4210cc549ff82bb8f..27fcf2e562bd03c0e0c610af746334fb6603c6e7 100644 (file)
@@ -154,6 +154,7 @@ ExecNestLoop(NestLoopState *node)
                                prm->value = slot_getattr(outerTupleSlot,
                                                                                  nlp->paramval->varattno,
                                                                                  &(prm->isnull));
+                               prm->done = true;
                                /* Flag parameter value as changed */
                                innerPlan->chgParam = bms_add_member(innerPlan->chgParam,
                                                                                                         paramno);
index 4c6453766ed1d220b0c20c86cbfbd17c9690c061..aaad6b2c199e9f85483ed03886df4198a96f01bd 100644 (file)
@@ -289,6 +289,7 @@ ExecScanSubPlan(SubPlanState *node,
                                                                                           econtext,
                                                                                           &(prm->isnull),
                                                                                           NULL);
+               prm->done = true;
                planstate->chgParam = bms_add_member(planstate->chgParam, paramid);
        }
 
@@ -996,6 +997,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
                                                                                           econtext,
                                                                                           &(prm->isnull),
                                                                                           NULL);
+               prm->done = true;
                planstate->chgParam = bms_add_member(planstate->chgParam, paramid);
        }
 
@@ -1017,6 +1019,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
                        ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
 
                        prm->execPlan = NULL;
+                       prm->done = true;
                        prm->value = BoolGetDatum(true);
                        prm->isnull = false;
                        found = true;
@@ -1067,6 +1070,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
                        ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
 
                        prm->execPlan = NULL;
+                       prm->done = true;
                        prm->value = heap_getattr(node->curTuple, i, tdesc,
                                                                          &(prm->isnull));
                        i++;
@@ -1090,6 +1094,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
                                                                                        econtext->ecxt_per_query_memory,
                                                                                        true);
                prm->execPlan = NULL;
+               prm->done = true;
                prm->value = node->curArray;
                prm->isnull = false;
        }
@@ -1102,6 +1107,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
                        ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
 
                        prm->execPlan = NULL;
+                       prm->done = true;
                        prm->value = BoolGetDatum(false);
                        prm->isnull = false;
                }
@@ -1114,6 +1120,7 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
                                ParamExecData *prm = &(econtext->ecxt_param_exec_vals[paramid]);
 
                                prm->execPlan = NULL;
+                               prm->done = true;
                                prm->value = (Datum) 0;
                                prm->isnull = true;
                        }
index 9d9d20add569472bb32128493f7b621e63391e9a..91c105d1200e859fa60df45de04207aed6567eb5 100644 (file)
@@ -5713,7 +5713,10 @@ static int encode_parameters(int nparams, RemoteParam *remoteparams,
                                /* ExecSetParamPlan should have processed this param... */
                                Assert(param->execPlan == NULL);
                        }
+                       if (!param->done)
+                               param->isnull = true;
                        append_param_data(&buf, ptype, param->value, param->isnull);
+
                }
        }
 
index 5f7df26ba89db2ed9f0e9cf3276532f7a95a31ae..96613c72c81a8968f7ad07314ae2a474e3667c55 100644 (file)
@@ -100,6 +100,7 @@ typedef struct ParamExecData
        bool            isnull;
 #ifdef XCP
        Oid                     ptype;
+       bool            done;
 #endif
 } ParamExecData;