Skip to content

Commit 8821054

Browse files
committed
Remove stray references to lefttree/righttree in the executor.
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 40f42d2, 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
1 parent 62c46ee commit 8821054

14 files changed

+56
-37
lines changed

src/backend/executor/execAmi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ ExecReScan(PlanState *node)
117117
if (splan->plan->extParam != NULL)
118118
UpdateChangedParamSet(splan, node->chgParam);
119119
}
120-
/* Well. Now set chgParam for left/right trees. */
121-
if (node->lefttree != NULL)
122-
UpdateChangedParamSet(node->lefttree, node->chgParam);
123-
if (node->righttree != NULL)
124-
UpdateChangedParamSet(node->righttree, node->chgParam);
120+
/* Well. Now set chgParam for child trees. */
121+
if (outerPlanState(node) != NULL)
122+
UpdateChangedParamSet(outerPlanState(node), node->chgParam);
123+
if (innerPlanState(node) != NULL)
124+
UpdateChangedParamSet(innerPlanState(node), node->chgParam);
125125
}
126126

127127
/* Call expression callbacks */

src/backend/executor/execCurrent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ search_plan_tree(PlanState *node, Oid table_oid,
396396
*/
397397
case T_ResultState:
398398
case T_LimitState:
399-
result = search_plan_tree(node->lefttree,
399+
result = search_plan_tree(outerPlanState(node),
400400
table_oid,
401401
pending_rescan);
402402
break;

src/backend/executor/nodeAgg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3388,7 +3388,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
33883388
if (phaseidx > 0)
33893389
{
33903390
aggnode = list_nth_node(Agg, node->chain, phaseidx - 1);
3391-
sortnode = castNode(Sort, aggnode->plan.lefttree);
3391+
sortnode = castNode(Sort, outerPlan(aggnode));
33923392
}
33933393
else
33943394
{

src/backend/executor/nodeGather.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ ExecGather(PlanState *pstate)
168168

169169
/* Initialize, or re-initialize, shared state needed by workers. */
170170
if (!node->pei)
171-
node->pei = ExecInitParallelPlan(node->ps.lefttree,
171+
node->pei = ExecInitParallelPlan(outerPlanState(node),
172172
estate,
173173
gather->initParam,
174174
gather->num_workers,
175175
node->tuples_needed);
176176
else
177-
ExecParallelReinitialize(node->ps.lefttree,
177+
ExecParallelReinitialize(outerPlanState(node),
178178
node->pei,
179179
gather->initParam);
180180

src/backend/executor/nodeGatherMerge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ ExecGatherMerge(PlanState *pstate)
212212

213213
/* Initialize, or re-initialize, shared state needed by workers. */
214214
if (!node->pei)
215-
node->pei = ExecInitParallelPlan(node->ps.lefttree,
215+
node->pei = ExecInitParallelPlan(outerPlanState(node),
216216
estate,
217217
gm->initParam,
218218
gm->num_workers,
219219
node->tuples_needed);
220220
else
221-
ExecParallelReinitialize(node->ps.lefttree,
221+
ExecParallelReinitialize(outerPlanState(node),
222222
node->pei,
223223
gm->initParam);
224224

src/backend/executor/nodeHash.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,12 +2212,14 @@ ExecHashTableResetMatchFlags(HashJoinTable hashtable)
22122212
void
22132213
ExecReScanHash(HashState *node)
22142214
{
2215+
PlanState *outerPlan = outerPlanState(node);
2216+
22152217
/*
22162218
* if chgParam of subnode is not null then plan will be re-scanned by
22172219
* first ExecProcNode.
22182220
*/
2219-
if (node->ps.lefttree->chgParam == NULL)
2220-
ExecReScan(node->ps.lefttree);
2221+
if (outerPlan->chgParam == NULL)
2222+
ExecReScan(outerPlan);
22212223
}
22222224

22232225

src/backend/executor/nodeHashjoin.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,9 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
12901290
void
12911291
ExecReScanHashJoin(HashJoinState *node)
12921292
{
1293+
PlanState *outerPlan = outerPlanState(node);
1294+
PlanState *innerPlan = innerPlanState(node);
1295+
12931296
/*
12941297
* In a multi-batch join, we currently have to do rescans the hard way,
12951298
* primarily because batch temp files may have already been released. But
@@ -1300,7 +1303,7 @@ ExecReScanHashJoin(HashJoinState *node)
13001303
if (node->hj_HashTable != NULL)
13011304
{
13021305
if (node->hj_HashTable->nbatch == 1 &&
1303-
node->js.ps.righttree->chgParam == NULL)
1306+
innerPlan->chgParam == NULL)
13041307
{
13051308
/*
13061309
* Okay to reuse the hash table; needn't rescan inner, either.
@@ -1328,7 +1331,7 @@ ExecReScanHashJoin(HashJoinState *node)
13281331
else
13291332
{
13301333
/* must destroy and rebuild hash table */
1331-
HashState *hashNode = castNode(HashState, innerPlanState(node));
1334+
HashState *hashNode = castNode(HashState, innerPlan);
13321335

13331336
Assert(hashNode->hashtable == node->hj_HashTable);
13341337
/* accumulate stats from old hash table, if wanted */
@@ -1350,8 +1353,8 @@ ExecReScanHashJoin(HashJoinState *node)
13501353
* if chgParam of subnode is not null then plan will be re-scanned
13511354
* by first ExecProcNode.
13521355
*/
1353-
if (node->js.ps.righttree->chgParam == NULL)
1354-
ExecReScan(node->js.ps.righttree);
1356+
if (innerPlan->chgParam == NULL)
1357+
ExecReScan(innerPlan);
13551358
}
13561359
}
13571360

@@ -1368,8 +1371,8 @@ ExecReScanHashJoin(HashJoinState *node)
13681371
* if chgParam of subnode is not null then plan will be re-scanned by
13691372
* first ExecProcNode.
13701373
*/
1371-
if (node->js.ps.lefttree->chgParam == NULL)
1372-
ExecReScan(node->js.ps.lefttree);
1374+
if (outerPlan->chgParam == NULL)
1375+
ExecReScan(outerPlan);
13731376
}
13741377

13751378
void

src/backend/executor/nodeLimit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,8 @@ ExecEndLimit(LimitState *node)
542542
void
543543
ExecReScanLimit(LimitState *node)
544544
{
545+
PlanState *outerPlan = outerPlanState(node);
546+
545547
/*
546548
* Recompute limit/offset in case parameters changed, and reset the state
547549
* machine. We must do this before rescanning our child node, in case
@@ -553,6 +555,6 @@ ExecReScanLimit(LimitState *node)
553555
* if chgParam of subnode is not null then plan will be re-scanned by
554556
* first ExecProcNode.
555557
*/
556-
if (node->ps.lefttree->chgParam == NULL)
557-
ExecReScan(node->ps.lefttree);
558+
if (outerPlan->chgParam == NULL)
559+
ExecReScan(outerPlan);
558560
}

src/backend/executor/nodeLockRows.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,12 @@ ExecEndLockRows(LockRowsState *node)
394394
void
395395
ExecReScanLockRows(LockRowsState *node)
396396
{
397+
PlanState *outerPlan = outerPlanState(node);
398+
397399
/*
398400
* if chgParam of subnode is not null then plan will be re-scanned by
399401
* first ExecProcNode.
400402
*/
401-
if (node->ps.lefttree->chgParam == NULL)
402-
ExecReScan(node->ps.lefttree);
403+
if (outerPlan->chgParam == NULL)
404+
ExecReScan(outerPlan);
403405
}

src/backend/executor/nodeMergejoin.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,9 @@ ExecEndMergeJoin(MergeJoinState *node)
16581658
void
16591659
ExecReScanMergeJoin(MergeJoinState *node)
16601660
{
1661+
PlanState *outerPlan = outerPlanState(node);
1662+
PlanState *innerPlan = innerPlanState(node);
1663+
16611664
ExecClearTuple(node->mj_MarkedTupleSlot);
16621665

16631666
node->mj_JoinState = EXEC_MJ_INITIALIZE_OUTER;
@@ -1670,8 +1673,8 @@ ExecReScanMergeJoin(MergeJoinState *node)
16701673
* if chgParam of subnodes is not null then plans will be re-scanned by
16711674
* first ExecProcNode.
16721675
*/
1673-
if (node->js.ps.lefttree->chgParam == NULL)
1674-
ExecReScan(node->js.ps.lefttree);
1675-
if (node->js.ps.righttree->chgParam == NULL)
1676-
ExecReScan(node->js.ps.righttree);
1676+
if (outerPlan->chgParam == NULL)
1677+
ExecReScan(outerPlan);
1678+
if (innerPlan->chgParam == NULL)
1679+
ExecReScan(innerPlan);
16771680
}

src/backend/executor/nodeProjectSet.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,15 @@ ExecEndProjectSet(ProjectSetState *node)
339339
void
340340
ExecReScanProjectSet(ProjectSetState *node)
341341
{
342+
PlanState *outerPlan = outerPlanState(node);
343+
342344
/* Forget any incompletely-evaluated SRFs */
343345
node->pending_srf_tuples = false;
344346

345347
/*
346348
* If chgParam of subnode is not null then plan will be re-scanned by
347349
* first ExecProcNode.
348350
*/
349-
if (node->ps.lefttree->chgParam == NULL)
350-
ExecReScan(node->ps.lefttree);
351+
if (outerPlan->chgParam == NULL)
352+
ExecReScan(outerPlan);
351353
}

src/backend/executor/nodeResult.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,15 @@ ExecEndResult(ResultState *node)
259259
void
260260
ExecReScanResult(ResultState *node)
261261
{
262+
PlanState *outerPlan = outerPlanState(node);
263+
262264
node->rs_done = false;
263265
node->rs_checkqual = (node->resconstantqual != NULL);
264266

265267
/*
266268
* If chgParam of subnode is not null then plan will be re-scanned by
267269
* first ExecProcNode.
268270
*/
269-
if (node->ps.lefttree &&
270-
node->ps.lefttree->chgParam == NULL)
271-
ExecReScan(node->ps.lefttree);
271+
if (outerPlan && outerPlan->chgParam == NULL)
272+
ExecReScan(outerPlan);
272273
}

src/backend/executor/nodeSetOp.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ ExecEndSetOp(SetOpState *node)
597597
void
598598
ExecReScanSetOp(SetOpState *node)
599599
{
600+
PlanState *outerPlan = outerPlanState(node);
601+
600602
ExecClearTuple(node->ps.ps_ResultTupleSlot);
601603
node->setop_done = false;
602604
node->numOutput = 0;
@@ -617,7 +619,7 @@ ExecReScanSetOp(SetOpState *node)
617619
* parameter changes, then we can just rescan the existing hash table;
618620
* no need to build it again.
619621
*/
620-
if (node->ps.lefttree->chgParam == NULL)
622+
if (outerPlan->chgParam == NULL)
621623
{
622624
ResetTupleHashIterator(node->hashtable, &node->hashiter);
623625
return;
@@ -646,6 +648,6 @@ ExecReScanSetOp(SetOpState *node)
646648
* if chgParam of subnode is not null then plan will be re-scanned by
647649
* first ExecProcNode.
648650
*/
649-
if (node->ps.lefttree->chgParam == NULL)
650-
ExecReScan(node->ps.lefttree);
651+
if (outerPlan->chgParam == NULL)
652+
ExecReScan(outerPlan);
651653
}

src/backend/executor/nodeUnique.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,15 @@ ExecEndUnique(UniqueState *node)
180180
void
181181
ExecReScanUnique(UniqueState *node)
182182
{
183+
PlanState *outerPlan = outerPlanState(node);
184+
183185
/* must clear result tuple so first input tuple is returned */
184186
ExecClearTuple(node->ps.ps_ResultTupleSlot);
185187

186188
/*
187189
* if chgParam of subnode is not null then plan will be re-scanned by
188190
* first ExecProcNode.
189191
*/
190-
if (node->ps.lefttree->chgParam == NULL)
191-
ExecReScan(node->ps.lefttree);
192+
if (outerPlan->chgParam == NULL)
193+
ExecReScan(outerPlan);
192194
}

0 commit comments

Comments
 (0)