Append and SubqueryScan nodes were not passing changed-parameter signals down
authorTom Lane <[email protected]>
Tue, 8 May 2001 19:48:02 +0000 (19:48 +0000)
committerTom Lane <[email protected]>
Tue, 8 May 2001 19:48:02 +0000 (19:48 +0000)
to their children, leading to misbehavior if they had any children that paid
attention to chgParam (most plan node types don't).  Append's bug has been
there a long time, but nobody had noticed because it used to be difficult
to create a query where an Append would be used below the top level of a
plan; so there were never any parameters getting passed down.  SubqueryScan
is new in 7.1 ... and I'd modeled its behavior on Append :-(

src/backend/executor/nodeAppend.c
src/backend/executor/nodeSubqueryscan.c

index 0d09ea778ec9d03a5bc820d3729d31022dfd638b..0a67cf22661e06136bc1fbac4dfd4e1a86de322d 100644 (file)
@@ -362,14 +362,25 @@ ExecReScanAppend(Append *node, ExprContext *exprCtxt, Plan *parent)
 
        for (i = 0; i < nplans; i++)
        {
-               Plan       *rescanNode;
+               Plan       *subnode;
 
-               appendstate->as_whichplan = i;
-               rescanNode = (Plan *) nth(i, node->appendplans);
-               if (rescanNode->chgParam == NULL)
+               subnode = (Plan *) nth(i, node->appendplans);
+               /*
+                * ExecReScan doesn't know about my subplans, so I have to do
+                * changed-parameter signaling myself.
+                */
+               if (node->plan.chgParam != NULL)
+                       SetChangedParamList(subnode, node->plan.chgParam);
+               /*
+                * if chgParam of subnode is not null then plan will be re-scanned by
+                * first ExecProcNode.
+                */
+               if (subnode->chgParam == NULL)
                {
+                       /* make sure estate is correct for this subnode (needed??) */
+                       appendstate->as_whichplan = i;
                        exec_append_initialize_next(node);
-                       ExecReScan((Plan *) rescanNode, exprCtxt, (Plan *) node);
+                       ExecReScan(subnode, exprCtxt, (Plan *) node);
                }
        }
        appendstate->as_whichplan = 0;
index 465b7b30c1b962e9138c18555b80ecadb79c4f48..aebb5826b3ace6fa4e2d2b7cfa775874c9f7b5b7 100644 (file)
@@ -267,7 +267,18 @@ ExecSubqueryReScan(SubqueryScan *node, ExprContext *exprCtxt, Plan *parent)
                return;
        }
 
-       ExecReScan(node->subplan, NULL, node->subplan);
+       /*
+        * ExecReScan doesn't know about my subplan, so I have to do
+        * changed-parameter signaling myself.
+        */
+       if (node->scan.plan.chgParam != NULL)
+               SetChangedParamList(node->subplan, node->scan.plan.chgParam);
+       /*
+        * if chgParam of subnode is not null then plan will be re-scanned by
+        * first ExecProcNode.
+        */
+       if (node->subplan->chgParam == NULL)
+               ExecReScan(node->subplan, NULL, node->subplan);
 
        subquerystate->csstate.css_ScanTupleSlot = NULL;
 }