1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Clean up plantree representation of SubPlan-s --- SubLink does not appear

in the planned representation of a subplan at all any more, only SubPlan.
This means subselect.c doesn't scribble on its input anymore, which seems
like a good thing; and there are no longer three different possible
interpretations of a SubLink.  Simplify node naming and improve comments
in primnodes.h.  No change to stored rules, though.
This commit is contained in:
Tom Lane
2002-12-14 00:17:59 +00:00
parent 29cdab3d53
commit 2d8d66628a
24 changed files with 355 additions and 356 deletions

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.67 2002/12/13 19:45:52 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.68 2002/12/14 00:17:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -61,7 +61,7 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt)
foreach(lst, node->initPlan)
{
SubPlanExprState *sstate = (SubPlanExprState *) lfirst(lst);
SubPlanState *sstate = (SubPlanState *) lfirst(lst);
PlanState *splan = sstate->planstate;
if (splan->plan->extParam != NIL) /* don't care about child
@ -72,7 +72,7 @@ ExecReScan(PlanState *node, ExprContext *exprCtxt)
}
foreach(lst, node->subPlan)
{
SubPlanExprState *sstate = (SubPlanExprState *) lfirst(lst);
SubPlanState *sstate = (SubPlanState *) lfirst(lst);
PlanState *splan = sstate->planstate;
if (splan->plan->extParam != NIL)

View File

@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.33 2002/12/13 19:45:52 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execProcnode.c,v 1.34 2002/12/14 00:17:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -228,10 +228,10 @@ ExecInitNode(Plan *node, EState *estate)
subps = NIL;
foreach(subp, node->initPlan)
{
SubPlanExpr *subplan = (SubPlanExpr *) lfirst(subp);
SubPlanExprState *sstate;
SubPlan *subplan = (SubPlan *) lfirst(subp);
SubPlanState *sstate;
Assert(IsA(subplan, SubPlanExpr));
Assert(IsA(subplan, SubPlan));
sstate = ExecInitExprInitPlan(subplan, result);
ExecInitSubPlan(sstate, estate);
subps = lappend(subps, sstate);
@ -247,9 +247,9 @@ ExecInitNode(Plan *node, EState *estate)
subps = NIL;
foreach(subp, result->subPlan)
{
SubPlanExprState *sstate = (SubPlanExprState *) lfirst(subp);
SubPlanState *sstate = (SubPlanState *) lfirst(subp);
Assert(IsA(sstate, SubPlanExprState));
Assert(IsA(sstate, SubPlanState));
ExecInitSubPlan(sstate, estate);
subps = lappend(subps, sstate);
}
@ -500,9 +500,9 @@ ExecEndNode(PlanState *node)
/* Clean up initPlans and subPlans */
foreach(subp, node->initPlan)
ExecEndSubPlan((SubPlanExprState *) lfirst(subp));
ExecEndSubPlan((SubPlanState *) lfirst(subp));
foreach(subp, node->subPlan)
ExecEndSubPlan((SubPlanExprState *) lfirst(subp));
ExecEndSubPlan((SubPlanState *) lfirst(subp));
if (node->chgParam != NIL)
{

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.119 2002/12/13 19:45:52 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execQual.c,v 1.120 2002/12/14 00:17:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1794,8 +1794,8 @@ ExecEvalExpr(ExprState *expression,
}
break;
}
case T_SubPlanExpr:
retDatum = ExecSubPlan((SubPlanExprState *) expression,
case T_SubPlan:
retDatum = ExecSubPlan((SubPlanState *) expression,
econtext,
isNull);
break;
@ -1883,7 +1883,7 @@ ExecEvalExprSwitchContext(ExprState *expression,
* executions of the expression are needed. Typically the context will be
* the same as the per-query context of the associated ExprContext.
*
* Any Aggref and SubplanExpr nodes found in the tree are added to the lists
* Any Aggref and SubPlan nodes found in the tree are added to the lists
* of such nodes held by the parent PlanState. Otherwise, we do very little
* initialization here other than building the state-node tree. Any nontrivial
* work associated with initializing runtime info for a node should happen
@ -2003,31 +2003,26 @@ ExecInitExpr(Expr *node, PlanState *parent)
state = (ExprState *) bstate;
}
break;
case T_SubPlanExpr:
case T_SubPlan:
{
/* Keep this in sync with ExecInitExprInitPlan, below */
SubPlanExpr *subplanexpr = (SubPlanExpr *) node;
SubLink *sublink = subplanexpr->sublink;
SubPlanExprState *sstate = makeNode(SubPlanExprState);
SubPlan *subplan = (SubPlan *) node;
SubPlanState *sstate = makeNode(SubPlanState);
Assert(IsA(sublink, SubLink));
if (!parent)
elog(ERROR, "ExecInitExpr: SubPlanExpr not expected here");
elog(ERROR, "ExecInitExpr: SubPlan not expected here");
/*
* Here we just add the SubPlanExprState nodes to
* Here we just add the SubPlanState nodes to
* parent->subPlan. The subplans will be initialized later.
*/
parent->subPlan = lcons(sstate, parent->subPlan);
sstate->planstate = NULL;
sstate->args = (List *)
ExecInitExpr((Expr *) subplanexpr->args, parent);
if (sublink->lefthand)
elog(ERROR, "ExecInitExpr: sublink has not been transformed");
sstate->oper = (List *)
ExecInitExpr((Expr *) sublink->oper, parent);
ExecInitExpr((Expr *) subplan->oper, parent);
sstate->args = (List *)
ExecInitExpr((Expr *) subplan->args, parent);
state = (ExprState *) sstate;
}
@ -2145,26 +2140,20 @@ ExecInitExpr(Expr *node, PlanState *parent)
* subplan expr, except we do NOT want to add the node to the parent's
* subplan list.
*/
SubPlanExprState *
ExecInitExprInitPlan(SubPlanExpr *node, PlanState *parent)
SubPlanState *
ExecInitExprInitPlan(SubPlan *node, PlanState *parent)
{
SubLink *sublink = node->sublink;
SubPlanExprState *sstate = makeNode(SubPlanExprState);
SubPlanState *sstate = makeNode(SubPlanState);
Assert(IsA(sublink, SubLink));
if (!parent)
elog(ERROR, "ExecInitExpr: SubPlanExpr not expected here");
elog(ERROR, "ExecInitExpr: SubPlan not expected here");
/* The subplan's state will be initialized later */
sstate->planstate = NULL;
sstate->oper = (List *) ExecInitExpr((Expr *) node->oper, parent);
sstate->args = (List *) ExecInitExpr((Expr *) node->args, parent);
if (sublink->lefthand)
elog(ERROR, "ExecInitExpr: sublink has not been transformed");
sstate->oper = (List *) ExecInitExpr((Expr *) sublink->oper, parent);
sstate->xprstate.expr = (Expr *) node;
return sstate;

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubplan.c,v 1.37 2002/12/13 19:45:55 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/nodeSubplan.c,v 1.38 2002/12/14 00:17:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -30,15 +30,14 @@
* ----------------------------------------------------------------
*/
Datum
ExecSubPlan(SubPlanExprState *node,
ExecSubPlan(SubPlanState *node,
ExprContext *econtext,
bool *isNull)
{
SubPlan *subplan = (SubPlan *) node->xprstate.expr;
PlanState *planstate = node->planstate;
SubPlanExpr *subplan = (SubPlanExpr *) node->xprstate.expr;
SubLink *sublink = subplan->sublink;
SubLinkType subLinkType = sublink->subLinkType;
bool useor = sublink->useor;
SubLinkType subLinkType = subplan->subLinkType;
bool useor = subplan->useor;
MemoryContext oldcontext;
TupleTableSlot *slot;
Datum result;
@ -292,56 +291,56 @@ ExecSubPlan(SubPlanExprState *node,
* ----------------------------------------------------------------
*/
void
ExecInitSubPlan(SubPlanExprState *sstate, EState *estate)
ExecInitSubPlan(SubPlanState *node, EState *estate)
{
SubPlanExpr *expr = (SubPlanExpr *) sstate->xprstate.expr;
SubPlan *subplan = (SubPlan *) node->xprstate.expr;
EState *sp_estate;
/*
* Do access checking on the rangetable entries in the subquery.
* Here, we assume the subquery is a SELECT.
*/
ExecCheckRTPerms(expr->rtable, CMD_SELECT);
ExecCheckRTPerms(subplan->rtable, CMD_SELECT);
/*
* initialize state
*/
sstate->needShutdown = false;
sstate->curTuple = NULL;
node->needShutdown = false;
node->curTuple = NULL;
/*
* create an EState for the subplan
*/
sp_estate = CreateExecutorState();
sp_estate->es_range_table = expr->rtable;
sp_estate->es_range_table = subplan->rtable;
sp_estate->es_param_list_info = estate->es_param_list_info;
sp_estate->es_param_exec_vals = estate->es_param_exec_vals;
sp_estate->es_tupleTable =
ExecCreateTupleTable(ExecCountSlotsNode(expr->plan) + 10);
ExecCreateTupleTable(ExecCountSlotsNode(subplan->plan) + 10);
sp_estate->es_snapshot = estate->es_snapshot;
sp_estate->es_instrument = estate->es_instrument;
/*
* Start up the subplan
*/
sstate->planstate = ExecInitNode(expr->plan, sp_estate);
node->planstate = ExecInitNode(subplan->plan, sp_estate);
sstate->needShutdown = true; /* now we need to shutdown the subplan */
node->needShutdown = true; /* now we need to shutdown the subplan */
/*
* If this plan is un-correlated or undirect correlated one and want
* to set params for parent plan then prepare parameters.
*/
if (expr->setParam != NIL)
if (subplan->setParam != NIL)
{
List *lst;
foreach(lst, expr->setParam)
foreach(lst, subplan->setParam)
{
ParamExecData *prm = &(estate->es_param_exec_vals[lfirsti(lst)]);
prm->execPlan = sstate;
prm->execPlan = node;
}
/*
@ -366,11 +365,11 @@ ExecInitSubPlan(SubPlanExprState *sstate, EState *estate)
* ----------------------------------------------------------------
*/
void
ExecSetParamPlan(SubPlanExprState *node, ExprContext *econtext)
ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
{
SubPlan *subplan = (SubPlan *) node->xprstate.expr;
PlanState *planstate = node->planstate;
SubPlanExpr *subplan = (SubPlanExpr *) node->xprstate.expr;
SubLinkType subLinkType = subplan->sublink->subLinkType;
SubLinkType subLinkType = subplan->subLinkType;
MemoryContext oldcontext;
TupleTableSlot *slot;
List *lst;
@ -473,7 +472,7 @@ ExecSetParamPlan(SubPlanExprState *node, ExprContext *econtext)
* ----------------------------------------------------------------
*/
void
ExecEndSubPlan(SubPlanExprState *node)
ExecEndSubPlan(SubPlanState *node)
{
if (node->needShutdown)
{
@ -488,10 +487,10 @@ ExecEndSubPlan(SubPlanExprState *node)
}
void
ExecReScanSetParamPlan(SubPlanExprState *node, PlanState *parent)
ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent)
{
PlanState *planstate = node->planstate;
SubPlanExpr *subplan = (SubPlanExpr *) node->xprstate.expr;
SubPlan *subplan = (SubPlan *) node->xprstate.expr;
EState *estate = parent->state;
List *lst;