1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-13 07:41:39 +03:00

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 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
This commit is contained in:
Tom Lane
2022-07-07 11:23:40 -04:00
parent 62c46eee22
commit 8821054210
14 changed files with 56 additions and 37 deletions

View File

@ -117,11 +117,11 @@ ExecReScan(PlanState *node)
if (splan->plan->extParam != NULL) if (splan->plan->extParam != NULL)
UpdateChangedParamSet(splan, node->chgParam); UpdateChangedParamSet(splan, node->chgParam);
} }
/* Well. Now set chgParam for left/right trees. */ /* Well. Now set chgParam for child trees. */
if (node->lefttree != NULL) if (outerPlanState(node) != NULL)
UpdateChangedParamSet(node->lefttree, node->chgParam); UpdateChangedParamSet(outerPlanState(node), node->chgParam);
if (node->righttree != NULL) if (innerPlanState(node) != NULL)
UpdateChangedParamSet(node->righttree, node->chgParam); UpdateChangedParamSet(innerPlanState(node), node->chgParam);
} }
/* Call expression callbacks */ /* Call expression callbacks */

View File

@ -396,7 +396,7 @@ search_plan_tree(PlanState *node, Oid table_oid,
*/ */
case T_ResultState: case T_ResultState:
case T_LimitState: case T_LimitState:
result = search_plan_tree(node->lefttree, result = search_plan_tree(outerPlanState(node),
table_oid, table_oid,
pending_rescan); pending_rescan);
break; break;

View File

@ -3388,7 +3388,7 @@ ExecInitAgg(Agg *node, EState *estate, int eflags)
if (phaseidx > 0) if (phaseidx > 0)
{ {
aggnode = list_nth_node(Agg, node->chain, phaseidx - 1); aggnode = list_nth_node(Agg, node->chain, phaseidx - 1);
sortnode = castNode(Sort, aggnode->plan.lefttree); sortnode = castNode(Sort, outerPlan(aggnode));
} }
else else
{ {

View File

@ -168,13 +168,13 @@ ExecGather(PlanState *pstate)
/* Initialize, or re-initialize, shared state needed by workers. */ /* Initialize, or re-initialize, shared state needed by workers. */
if (!node->pei) if (!node->pei)
node->pei = ExecInitParallelPlan(node->ps.lefttree, node->pei = ExecInitParallelPlan(outerPlanState(node),
estate, estate,
gather->initParam, gather->initParam,
gather->num_workers, gather->num_workers,
node->tuples_needed); node->tuples_needed);
else else
ExecParallelReinitialize(node->ps.lefttree, ExecParallelReinitialize(outerPlanState(node),
node->pei, node->pei,
gather->initParam); gather->initParam);

View File

@ -212,13 +212,13 @@ ExecGatherMerge(PlanState *pstate)
/* Initialize, or re-initialize, shared state needed by workers. */ /* Initialize, or re-initialize, shared state needed by workers. */
if (!node->pei) if (!node->pei)
node->pei = ExecInitParallelPlan(node->ps.lefttree, node->pei = ExecInitParallelPlan(outerPlanState(node),
estate, estate,
gm->initParam, gm->initParam,
gm->num_workers, gm->num_workers,
node->tuples_needed); node->tuples_needed);
else else
ExecParallelReinitialize(node->ps.lefttree, ExecParallelReinitialize(outerPlanState(node),
node->pei, node->pei,
gm->initParam); gm->initParam);

View File

@ -2212,12 +2212,14 @@ ExecHashTableResetMatchFlags(HashJoinTable hashtable)
void void
ExecReScanHash(HashState *node) ExecReScanHash(HashState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
/* /*
* if chgParam of subnode is not null then plan will be re-scanned by * if chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->ps.lefttree); ExecReScan(outerPlan);
} }

View File

@ -1290,6 +1290,9 @@ ExecHashJoinGetSavedTuple(HashJoinState *hjstate,
void void
ExecReScanHashJoin(HashJoinState *node) 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, * 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 * 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 != NULL)
{ {
if (node->hj_HashTable->nbatch == 1 && 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. * Okay to reuse the hash table; needn't rescan inner, either.
@ -1328,7 +1331,7 @@ ExecReScanHashJoin(HashJoinState *node)
else else
{ {
/* must destroy and rebuild hash table */ /* must destroy and rebuild hash table */
HashState *hashNode = castNode(HashState, innerPlanState(node)); HashState *hashNode = castNode(HashState, innerPlan);
Assert(hashNode->hashtable == node->hj_HashTable); Assert(hashNode->hashtable == node->hj_HashTable);
/* accumulate stats from old hash table, if wanted */ /* 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 * if chgParam of subnode is not null then plan will be re-scanned
* by first ExecProcNode. * by first ExecProcNode.
*/ */
if (node->js.ps.righttree->chgParam == NULL) if (innerPlan->chgParam == NULL)
ExecReScan(node->js.ps.righttree); ExecReScan(innerPlan);
} }
} }
@ -1368,8 +1371,8 @@ ExecReScanHashJoin(HashJoinState *node)
* if chgParam of subnode is not null then plan will be re-scanned by * if chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->js.ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->js.ps.lefttree); ExecReScan(outerPlan);
} }
void void

View File

@ -542,6 +542,8 @@ ExecEndLimit(LimitState *node)
void void
ExecReScanLimit(LimitState *node) ExecReScanLimit(LimitState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
/* /*
* Recompute limit/offset in case parameters changed, and reset the state * Recompute limit/offset in case parameters changed, and reset the state
* machine. We must do this before rescanning our child node, in case * 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 * if chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->ps.lefttree); ExecReScan(outerPlan);
} }

View File

@ -394,10 +394,12 @@ ExecEndLockRows(LockRowsState *node)
void void
ExecReScanLockRows(LockRowsState *node) ExecReScanLockRows(LockRowsState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
/* /*
* if chgParam of subnode is not null then plan will be re-scanned by * if chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->ps.lefttree); ExecReScan(outerPlan);
} }

View File

@ -1658,6 +1658,9 @@ ExecEndMergeJoin(MergeJoinState *node)
void void
ExecReScanMergeJoin(MergeJoinState *node) ExecReScanMergeJoin(MergeJoinState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
PlanState *innerPlan = innerPlanState(node);
ExecClearTuple(node->mj_MarkedTupleSlot); ExecClearTuple(node->mj_MarkedTupleSlot);
node->mj_JoinState = EXEC_MJ_INITIALIZE_OUTER; 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 * if chgParam of subnodes is not null then plans will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->js.ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->js.ps.lefttree); ExecReScan(outerPlan);
if (node->js.ps.righttree->chgParam == NULL) if (innerPlan->chgParam == NULL)
ExecReScan(node->js.ps.righttree); ExecReScan(innerPlan);
} }

View File

@ -339,6 +339,8 @@ ExecEndProjectSet(ProjectSetState *node)
void void
ExecReScanProjectSet(ProjectSetState *node) ExecReScanProjectSet(ProjectSetState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
/* Forget any incompletely-evaluated SRFs */ /* Forget any incompletely-evaluated SRFs */
node->pending_srf_tuples = false; 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 * If chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->ps.lefttree); ExecReScan(outerPlan);
} }

View File

@ -259,6 +259,8 @@ ExecEndResult(ResultState *node)
void void
ExecReScanResult(ResultState *node) ExecReScanResult(ResultState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
node->rs_done = false; node->rs_done = false;
node->rs_checkqual = (node->resconstantqual != NULL); 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 * If chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->ps.lefttree && if (outerPlan && outerPlan->chgParam == NULL)
node->ps.lefttree->chgParam == NULL) ExecReScan(outerPlan);
ExecReScan(node->ps.lefttree);
} }

View File

@ -597,6 +597,8 @@ ExecEndSetOp(SetOpState *node)
void void
ExecReScanSetOp(SetOpState *node) ExecReScanSetOp(SetOpState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
ExecClearTuple(node->ps.ps_ResultTupleSlot); ExecClearTuple(node->ps.ps_ResultTupleSlot);
node->setop_done = false; node->setop_done = false;
node->numOutput = 0; node->numOutput = 0;
@ -617,7 +619,7 @@ ExecReScanSetOp(SetOpState *node)
* parameter changes, then we can just rescan the existing hash table; * parameter changes, then we can just rescan the existing hash table;
* no need to build it again. * no need to build it again.
*/ */
if (node->ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
{ {
ResetTupleHashIterator(node->hashtable, &node->hashiter); ResetTupleHashIterator(node->hashtable, &node->hashiter);
return; return;
@ -646,6 +648,6 @@ ExecReScanSetOp(SetOpState *node)
* if chgParam of subnode is not null then plan will be re-scanned by * if chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->ps.lefttree); ExecReScan(outerPlan);
} }

View File

@ -180,6 +180,8 @@ ExecEndUnique(UniqueState *node)
void void
ExecReScanUnique(UniqueState *node) ExecReScanUnique(UniqueState *node)
{ {
PlanState *outerPlan = outerPlanState(node);
/* must clear result tuple so first input tuple is returned */ /* must clear result tuple so first input tuple is returned */
ExecClearTuple(node->ps.ps_ResultTupleSlot); 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 * if chgParam of subnode is not null then plan will be re-scanned by
* first ExecProcNode. * first ExecProcNode.
*/ */
if (node->ps.lefttree->chgParam == NULL) if (outerPlan->chgParam == NULL)
ExecReScan(node->ps.lefttree); ExecReScan(outerPlan);
} }