Remove stray references to lefttree/righttree in the executor.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Jul 2022 15:23:40 +0000 (11:23 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 7 Jul 2022 15:23:40 +0000 (11:23 -0400)
The general convention in the executor is to refer to child plans
and planstates via the outerPlan[State] and innerPlan[State]
macros, but a few places didn't do it like that.  For consistency
and readability, convert all the stragglers to use the macros.
(See also commit 40f42d2a3, which did some similar cleanup a few
years ago, but missed these cases.)

Richard Guo

Discussion: https://postgr.es/m/CAMbWs4-vYhh1xsa_veah4PUed2Xq=Ed_YH3=Mqt5A3Y=EgfCEg@mail.gmail.com

14 files changed:
src/backend/executor/execAmi.c
src/backend/executor/execCurrent.c
src/backend/executor/nodeAgg.c
src/backend/executor/nodeGather.c
src/backend/executor/nodeGatherMerge.c
src/backend/executor/nodeHash.c
src/backend/executor/nodeHashjoin.c
src/backend/executor/nodeLimit.c
src/backend/executor/nodeLockRows.c
src/backend/executor/nodeMergejoin.c
src/backend/executor/nodeProjectSet.c
src/backend/executor/nodeResult.c
src/backend/executor/nodeSetOp.c
src/backend/executor/nodeUnique.c

index b6245994f02961a39dc23e76e9ff1b3e95a6286e..44b2e0b82dfe0843fe0fa4304df31c94235fa109 100644 (file)
@@ -117,11 +117,11 @@ ExecReScan(PlanState *node)
                        if (splan->plan->extParam != NULL)
                                UpdateChangedParamSet(splan, node->chgParam);
                }
-               /* Well. Now set chgParam for left/right trees. */
-               if (node->lefttree != NULL)
-                       UpdateChangedParamSet(node->lefttree, node->chgParam);
-               if (node->righttree != NULL)
-                       UpdateChangedParamSet(node->righttree, node->chgParam);
+               /* Well. Now set chgParam for child trees. */
+               if (outerPlanState(node) != NULL)
+                       UpdateChangedParamSet(outerPlanState(node), node->chgParam);
+               if (innerPlanState(node) != NULL)
+                       UpdateChangedParamSet(innerPlanState(node), node->chgParam);
        }
 
        /* Call expression callbacks */
index b34b180bc4713374c8740114dd14760435924a6f..487107d7b986cba5cd2cec5729bc715f3bfd585e 100644 (file)
@@ -396,7 +396,7 @@ search_plan_tree(PlanState *node, Oid table_oid,
                         */
                case T_ResultState:
                case T_LimitState:
-                       result = search_plan_tree(node->lefttree,
+                       result = search_plan_tree(outerPlanState(node),
                                                                          table_oid,
                                                                          pending_rescan);
                        break;
index 139b2bd5f9b007cdc44a961bd305c67d1d4ae168..2fc606cf29d1179da19c68c5d85cf2085a788a84 100644 (file)
@@ -3388,7 +3388,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
                if (phaseidx > 0)
                {
                        aggnode = list_nth_node(Agg, node->chain, phaseidx - 1);
-                       sortnode = castNode(Sort, aggnode->plan.lefttree);
+                       sortnode = castNode(Sort, outerPlan(aggnode));
                }
                else
                {
index 4f8a17df7da23ae86d7df752fa509b8293a20ba3..1283d5b737a1dd4da4c8f9bc859136e76cf32ecf 100644 (file)
@@ -168,13 +168,13 @@ ExecGather(PlanState *pstate)
 
                        /* Initialize, or re-initialize, shared state needed by workers. */
                        if (!node->pei)
-                               node->pei = ExecInitParallelPlan(node->ps.lefttree,
+                               node->pei = ExecInitParallelPlan(outerPlanState(node),
                                                                                                 estate,
                                                                                                 gather->initParam,
                                                                                                 gather->num_workers,
                                                                                                 node->tuples_needed);
                        else
-                               ExecParallelReinitialize(node->ps.lefttree,
+                               ExecParallelReinitialize(outerPlanState(node),
                                                                                 node->pei,
                                                                                 gather->initParam);
 
index a488cc6d8be4b9cf7794fbf5b5b55e04189d4785..3b1007f3526384ea2c88b9628ed57e088895f4b0 100644 (file)
@@ -212,13 +212,13 @@ ExecGatherMerge(PlanState *pstate)
 
                        /* Initialize, or re-initialize, shared state needed by workers. */
                        if (!node->pei)
-                               node->pei = ExecInitParallelPlan(node->ps.lefttree,
+                               node->pei = ExecInitParallelPlan(outerPlanState(node),
                                                                                                 estate,
                                                                                                 gm->initParam,
                                                                                                 gm->num_workers,
                                                                                                 node->tuples_needed);
                        else
-                               ExecParallelReinitialize(node->ps.lefttree,
+                               ExecParallelReinitialize(outerPlanState(node),
                                                                                 node->pei,
                                                                                 gm->initParam);
 
index 3510a4247c1d1e7fe5d28a0ca205d5f143b67a43..123079c16ccabedb5143782cf8bce29e89293bcc 100644 (file)
@@ -2212,12 +2212,14 @@ ExecHashTableResetMatchFlags(HashJoinTable hashtable)
 void
 ExecReScanHash(HashState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+
        /*
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }
 
 
index 88b870655e91f2c9ec62df0012bd1b11836e6867..87403e247813c081686ab696a5c1208fe1f1c6f7 100644 (file)
@@ -1290,6 +1290,9 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
 void
 ExecReScanHashJoin(HashJoinState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+       PlanState  *innerPlan = innerPlanState(node);
+
        /*
         * In a multi-batch join, we currently have to do rescans the hard way,
         * primarily because batch temp files may have already been released. But
@@ -1300,7 +1303,7 @@ ExecReScanHashJoin(HashJoinState *node)
        if (node->hj_HashTable != NULL)
        {
                if (node->hj_HashTable->nbatch == 1 &&
-                       node->js.ps.righttree->chgParam == NULL)
+                       innerPlan->chgParam == NULL)
                {
                        /*
                         * Okay to reuse the hash table; needn't rescan inner, either.
@@ -1328,7 +1331,7 @@ ExecReScanHashJoin(HashJoinState *node)
                else
                {
                        /* must destroy and rebuild hash table */
-                       HashState  *hashNode = castNode(HashState, innerPlanState(node));
+                       HashState  *hashNode = castNode(HashState, innerPlan);
 
                        Assert(hashNode->hashtable == node->hj_HashTable);
                        /* accumulate stats from old hash table, if wanted */
@@ -1350,8 +1353,8 @@ ExecReScanHashJoin(HashJoinState *node)
                         * if chgParam of subnode is not null then plan will be re-scanned
                         * by first ExecProcNode.
                         */
-                       if (node->js.ps.righttree->chgParam == NULL)
-                               ExecReScan(node->js.ps.righttree);
+                       if (innerPlan->chgParam == NULL)
+                               ExecReScan(innerPlan);
                }
        }
 
@@ -1368,8 +1371,8 @@ ExecReScanHashJoin(HashJoinState *node)
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->js.ps.lefttree->chgParam == NULL)
-               ExecReScan(node->js.ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }
 
 void
index 1b91b123faf84011668bf9ca32ac43dc39dc63af..75e4302b94eee2c54dbaf79e6f88892522e0f358 100644 (file)
@@ -542,6 +542,8 @@ ExecEndLimit(LimitState *node)
 void
 ExecReScanLimit(LimitState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+
        /*
         * Recompute limit/offset in case parameters changed, and reset the state
         * machine.  We must do this before rescanning our child node, in case
@@ -553,6 +555,6 @@ ExecReScanLimit(LimitState *node)
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }
index 1a9dab25dd6add51d171ef567d574310f613474c..a74813c7aa797e0a0541dbabba4ba64615aa3e4c 100644 (file)
@@ -394,10 +394,12 @@ ExecEndLockRows(LockRowsState *node)
 void
 ExecReScanLockRows(LockRowsState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+
        /*
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }
index 864e3baf86b2e5a2879aa148031abe1ad430e94f..fed345eae54ffac6c6e588a3464243ed42c512d4 100644 (file)
@@ -1658,6 +1658,9 @@ ExecEndMergeJoin(MergeJoinState *node)
 void
 ExecReScanMergeJoin(MergeJoinState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+       PlanState  *innerPlan = innerPlanState(node);
+
        ExecClearTuple(node->mj_MarkedTupleSlot);
 
        node->mj_JoinState = EXEC_MJ_INITIALIZE_OUTER;
@@ -1670,8 +1673,8 @@ ExecReScanMergeJoin(MergeJoinState *node)
         * if chgParam of subnodes is not null then plans will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->js.ps.lefttree->chgParam == NULL)
-               ExecReScan(node->js.ps.lefttree);
-       if (node->js.ps.righttree->chgParam == NULL)
-               ExecReScan(node->js.ps.righttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
+       if (innerPlan->chgParam == NULL)
+               ExecReScan(innerPlan);
 }
index ea40d61b0b01d9414af9e94421307336f58c183e..adabfa2882dedf7e18690c1ad6739c1e481d2050 100644 (file)
@@ -339,6 +339,8 @@ ExecEndProjectSet(ProjectSetState *node)
 void
 ExecReScanProjectSet(ProjectSetState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+
        /* Forget any incompletely-evaluated SRFs */
        node->pending_srf_tuples = false;
 
@@ -346,6 +348,6 @@ ExecReScanProjectSet(ProjectSetState *node)
         * If chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }
index d0413e05de1f8e243489451b01176552d9f02b36..78a744ba8523b534fbaf3e966b176f5c1b796033 100644 (file)
@@ -259,6 +259,8 @@ ExecEndResult(ResultState *node)
 void
 ExecReScanResult(ResultState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+
        node->rs_done = false;
        node->rs_checkqual = (node->resconstantqual != NULL);
 
@@ -266,7 +268,6 @@ ExecReScanResult(ResultState *node)
         * If chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ps.lefttree &&
-               node->ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ps.lefttree);
+       if (outerPlan && outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }
index 4b428cfa39fd16e384114a192ef428f742e86e4e..8af12f96e72364fd0da69d16fc90ea92fe0d7508 100644 (file)
@@ -597,6 +597,8 @@ ExecEndSetOp(SetOpState *node)
 void
 ExecReScanSetOp(SetOpState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+
        ExecClearTuple(node->ps.ps_ResultTupleSlot);
        node->setop_done = false;
        node->numOutput = 0;
@@ -617,7 +619,7 @@ ExecReScanSetOp(SetOpState *node)
                 * parameter changes, then we can just rescan the existing hash table;
                 * no need to build it again.
                 */
-               if (node->ps.lefttree->chgParam == NULL)
+               if (outerPlan->chgParam == NULL)
                {
                        ResetTupleHashIterator(node->hashtable, &node->hashiter);
                        return;
@@ -646,6 +648,6 @@ ExecReScanSetOp(SetOpState *node)
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }
index 6c99d13a39c6f4dc92f4d9f3fa77768533e329b4..d1399feabb3085c28b0d862263f5703e7d7b6245 100644 (file)
@@ -180,6 +180,8 @@ ExecEndUnique(UniqueState *node)
 void
 ExecReScanUnique(UniqueState *node)
 {
+       PlanState  *outerPlan = outerPlanState(node);
+
        /* must clear result tuple so first input tuple is returned */
        ExecClearTuple(node->ps.ps_ResultTupleSlot);
 
@@ -187,6 +189,6 @@ ExecReScanUnique(UniqueState *node)
         * if chgParam of subnode is not null then plan will be re-scanned by
         * first ExecProcNode.
         */
-       if (node->ps.lefttree->chgParam == NULL)
-               ExecReScan(node->ps.lefttree);
+       if (outerPlan->chgParam == NULL)
+               ExecReScan(outerPlan);
 }