Use outerPlanState macro instead of referring to leffttree.
authorRobert Haas <rhaas@postgresql.org>
Mon, 4 May 2015 20:13:07 +0000 (16:13 -0400)
committerRobert Haas <rhaas@postgresql.org>
Mon, 4 May 2015 20:17:36 +0000 (16:17 -0400)
This makes the executor code more consistent.  It also removes
an apparently superfluous NULL test in nodeGroup.c.

Qingqing Zhou, reviewed by Tom Lane, and further revised by me.

src/backend/executor/nodeAgg.c
src/backend/executor/nodeBitmapHeapscan.c
src/backend/executor/nodeGroup.c
src/backend/executor/nodeMaterial.c
src/backend/executor/nodeSort.c
src/backend/executor/nodeWindowAgg.c

index 9ff0eff6d7b90771b4649e9f41f783df0deed19b..4a8af7b3a7e0ab82ebb3d11efeeb84c0fd66210f 100644 (file)
@@ -2053,6 +2053,7 @@ void
 ExecReScanAgg(AggState *node)
 {
    ExprContext *econtext = node->ss.ps.ps_ExprContext;
+   PlanState   *outerPlan = outerPlanState(node);
    int         aggno;
 
    node->agg_done = false;
@@ -2075,7 +2076,7 @@ ExecReScanAgg(AggState *node)
         * parameter changes, then we can just rescan the existing hash table;
         * no need to build it again.
         */
-       if (node->ss.ps.lefttree->chgParam == NULL)
+       if (outerPlan->chgParam == NULL)
        {
            ResetTupleHashIterator(node->hashtable, &node->hashiter);
            return;
@@ -2133,8 +2134,8 @@ ExecReScanAgg(AggState *node)
     * if chgParam of subnode is not null then plan will be re-scanned by
     * first ExecProcNode.
     */
-   if (node->ss.ps.lefttree->chgParam == NULL)
-       ExecReScan(node->ss.ps.lefttree);
+   if (outerPlan->chgParam == NULL)
+       ExecReScan(outerPlan);
 }
 
 
index 8ea8b9f16be7792f23467e598df3d9f677825c92..40a06f163a63ff00a87f5714c2ea9cdc2085b10e 100644 (file)
@@ -449,6 +449,8 @@ ExecBitmapHeapScan(BitmapHeapScanState *node)
 void
 ExecReScanBitmapHeapScan(BitmapHeapScanState *node)
 {
+   PlanState   *outerPlan = outerPlanState(node);
+
    /* rescan to release any page pin */
    heap_rescan(node->ss.ss_currentScanDesc, NULL);
 
@@ -469,8 +471,8 @@ ExecReScanBitmapHeapScan(BitmapHeapScanState *node)
     * if chgParam of subnode is not null then plan will be re-scanned by
     * first ExecProcNode.
     */
-   if (node->ss.ps.lefttree->chgParam == NULL)
-       ExecReScan(node->ss.ps.lefttree);
+   if (outerPlan->chgParam == NULL)
+       ExecReScan(outerPlan);
 }
 
 /* ----------------------------------------------------------------
index 83d562e5119dd2e781ec48ceb96e98755e78704f..3f87716b8f11c35e746e3473d62b5ddac6380a98 100644 (file)
@@ -280,6 +280,8 @@ ExecEndGroup(GroupState *node)
 void
 ExecReScanGroup(GroupState *node)
 {
+   PlanState   *outerPlan = outerPlanState(node);
+
    node->grp_done = FALSE;
    node->ss.ps.ps_TupFromTlist = false;
    /* must clear first tuple */
@@ -289,7 +291,6 @@ ExecReScanGroup(GroupState *node)
     * if chgParam of subnode is not null then plan will be re-scanned by
     * first ExecProcNode.
     */
-   if (node->ss.ps.lefttree &&
-       node->ss.ps.lefttree->chgParam == NULL)
-       ExecReScan(node->ss.ps.lefttree);
+   if (outerPlan->chgParam == NULL)
+       ExecReScan(outerPlan);
 }
index 115882586948db5bf00740f7942a11967667d700..8ff4352a66acf1750469e16e8cb225fe7aea51fd 100644 (file)
@@ -317,6 +317,8 @@ ExecMaterialRestrPos(MaterialState *node)
 void
 ExecReScanMaterial(MaterialState *node)
 {
+   PlanState   *outerPlan = outerPlanState(node);
+
    ExecClearTuple(node->ss.ps.ps_ResultTupleSlot);
 
    if (node->eflags != 0)
@@ -339,13 +341,13 @@ ExecReScanMaterial(MaterialState *node)
         * Otherwise we can just rewind and rescan the stored output. The
         * state of the subnode does not change.
         */
-       if (node->ss.ps.lefttree->chgParam != NULL ||
+       if (outerPlan->chgParam != NULL ||
            (node->eflags & EXEC_FLAG_REWIND) == 0)
        {
            tuplestore_end(node->tuplestorestate);
            node->tuplestorestate = NULL;
-           if (node->ss.ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ss.ps.lefttree);
+           if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
            node->eof_underlying = false;
        }
        else
@@ -359,8 +361,8 @@ ExecReScanMaterial(MaterialState *node)
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ss.ps.lefttree->chgParam == NULL)
-           ExecReScan(node->ss.ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+           ExecReScan(outerPlan);
        node->eof_underlying = false;
    }
 }
index a815cde2ccf153f823ca88743a59e4ef1f505fd9..732f3c38dbb3551166583ede128df85850ea1ce6 100644 (file)
@@ -290,6 +290,8 @@ ExecSortRestrPos(SortState *node)
 void
 ExecReScanSort(SortState *node)
 {
+   PlanState   *outerPlan = outerPlanState(node);
+
    /*
     * If we haven't sorted yet, just return. If outerplan's chgParam is not
     * NULL then it will be re-scanned by ExecProcNode, else no reason to
@@ -308,7 +310,7 @@ ExecReScanSort(SortState *node)
     *
     * Otherwise we can just rewind and rescan the sorted output.
     */
-   if (node->ss.ps.lefttree->chgParam != NULL ||
+   if (outerPlan->chgParam != NULL ||
        node->bounded != node->bounded_Done ||
        node->bound != node->bound_Done ||
        !node->randomAccess)
@@ -321,8 +323,8 @@ ExecReScanSort(SortState *node)
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ss.ps.lefttree->chgParam == NULL)
-           ExecReScan(node->ss.ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+           ExecReScan(outerPlan);
    }
    else
        tuplesort_rescan((Tuplesortstate *) node->tuplesortstate);
index a06790d94a14a42ce86f91e2c4a13cfb79ec8f0d..bf0c98d8783d12d35edfd09e646442c3d792371c 100644 (file)
@@ -2057,6 +2057,7 @@ ExecEndWindowAgg(WindowAggState *node)
 void
 ExecReScanWindowAgg(WindowAggState *node)
 {
+   PlanState   *outerPlan = outerPlanState(node);
    ExprContext *econtext = node->ss.ps.ps_ExprContext;
 
    node->all_done = false;
@@ -2082,8 +2083,8 @@ ExecReScanWindowAgg(WindowAggState *node)
     * if chgParam of subnode is not null then plan will be re-scanned by
     * first ExecProcNode.
     */
-   if (node->ss.ps.lefttree->chgParam == NULL)
-       ExecReScan(node->ss.ps.lefttree);
+   if (outerPlan->chgParam == NULL)
+       ExecReScan(outerPlan);
 }
 
 /*