Commit c7ff7663 authored by Tom Lane's avatar Tom Lane

Get rid of the separate EState for subplans, and just let them share the

parent query's EState.  Now that there's a single flat rangetable for both
the main plan and subplans, there's no need anymore for a separate EState,
and removing it allows cleaning up some crufty code in nodeSubplan.c and
nodeSubqueryscan.c.  Should be a tad faster too, although any difference
will probably be hard to measure.  This is the last bit of subsidiary
mop-up work from changing to a flat rangetable.
parent 4756ff3d
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.288 2007/02/22 22:00:22 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.289 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -70,6 +70,7 @@ static void initResultRelInfo(ResultRelInfo *resultRelInfo, ...@@ -70,6 +70,7 @@ static void initResultRelInfo(ResultRelInfo *resultRelInfo,
List *rangeTable, List *rangeTable,
CmdType operation, CmdType operation,
bool doInstrument); bool doInstrument);
static void ExecEndPlan(PlanState *planstate, EState *estate);
static TupleTableSlot *ExecutePlan(EState *estate, PlanState *planstate, static TupleTableSlot *ExecutePlan(EState *estate, PlanState *planstate,
CmdType operation, CmdType operation,
long numberTuples, long numberTuples,
...@@ -466,6 +467,7 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -466,6 +467,7 @@ InitPlan(QueryDesc *queryDesc, int eflags)
PlanState *planstate; PlanState *planstate;
TupleDesc tupType; TupleDesc tupType;
ListCell *l; ListCell *l;
int i;
/* /*
* Do permissions checks * Do permissions checks
...@@ -551,15 +553,25 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -551,15 +553,25 @@ InitPlan(QueryDesc *queryDesc, int eflags)
} }
/* /*
* initialize the executor "tuple" table. We need slots for all the plan * Initialize the executor "tuple" table. We need slots for all the plan
* nodes, plus possibly output slots for the junkfilter(s). At this point * nodes, plus possibly output slots for the junkfilter(s). At this point
* we aren't sure if we need junkfilters, so just add slots for them * we aren't sure if we need junkfilters, so just add slots for them
* unconditionally. Also, if it's not a SELECT, set up a slot for use for * unconditionally. Also, if it's not a SELECT, set up a slot for use for
* trigger output tuples. * trigger output tuples. Also, one for RETURNING-list evaluation.
*/ */
{ {
int nSlots = ExecCountSlotsNode(plan); int nSlots;
/* Slots for the main plan tree */
nSlots = ExecCountSlotsNode(plan);
/* Add slots for subplans and initplans */
foreach(l, plannedstmt->subplans)
{
Plan *subplan = (Plan *) lfirst(l);
nSlots += ExecCountSlotsNode(subplan);
}
/* Add slots for junkfilter(s) */
if (plannedstmt->resultRelations != NIL) if (plannedstmt->resultRelations != NIL)
nSlots += list_length(plannedstmt->resultRelations); nSlots += list_length(plannedstmt->resultRelations);
else else
...@@ -584,7 +596,38 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -584,7 +596,38 @@ InitPlan(QueryDesc *queryDesc, int eflags)
estate->es_useEvalPlan = false; estate->es_useEvalPlan = false;
/* /*
* initialize the private state information for all the nodes in the query * Initialize private state information for each SubPlan. We must do
* this before running ExecInitNode on the main query tree, since
* ExecInitSubPlan expects to be able to find these entries.
*/
Assert(estate->es_subplanstates == NIL);
i = 1; /* subplan indices count from 1 */
foreach(l, plannedstmt->subplans)
{
Plan *subplan = (Plan *) lfirst(l);
PlanState *subplanstate;
int sp_eflags;
/*
* A subplan will never need to do BACKWARD scan nor MARK/RESTORE.
* If it is a parameterless subplan (not initplan), we suggest that it
* be prepared to handle REWIND efficiently; otherwise there is no
* need.
*/
sp_eflags = eflags & EXEC_FLAG_EXPLAIN_ONLY;
if (bms_is_member(i, plannedstmt->rewindPlanIDs))
sp_eflags |= EXEC_FLAG_REWIND;
subplanstate = ExecInitNode(subplan, estate, sp_eflags);
estate->es_subplanstates = lappend(estate->es_subplanstates,
subplanstate);
i++;
}
/*
* Initialize the private state information for all the nodes in the query
* tree. This opens files, allocates storage and leaves us ready to start * tree. This opens files, allocates storage and leaves us ready to start
* processing tuples. * processing tuples.
*/ */
...@@ -648,7 +691,6 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -648,7 +691,6 @@ InitPlan(QueryDesc *queryDesc, int eflags)
PlanState **appendplans; PlanState **appendplans;
int as_nplans; int as_nplans;
ResultRelInfo *resultRelInfo; ResultRelInfo *resultRelInfo;
int i;
/* Top plan had better be an Append here. */ /* Top plan had better be an Append here. */
Assert(IsA(plan, Append)); Assert(IsA(plan, Append));
...@@ -768,20 +810,6 @@ InitPlan(QueryDesc *queryDesc, int eflags) ...@@ -768,20 +810,6 @@ InitPlan(QueryDesc *queryDesc, int eflags)
resultRelInfo->ri_RelationDesc->rd_att); resultRelInfo->ri_RelationDesc->rd_att);
resultRelInfo++; resultRelInfo++;
} }
/*
* Because we already ran ExecInitNode() for the top plan node, any
* subplans we just attached to it won't have been initialized; so we
* have to do it here. (Ugly, but the alternatives seem worse.)
*/
foreach(l, planstate->subPlan)
{
SubPlanState *sstate = (SubPlanState *) lfirst(l);
Assert(IsA(sstate, SubPlanState));
if (sstate->planstate == NULL) /* already inited? */
ExecInitSubPlan(sstate, estate, eflags);
}
} }
queryDesc->tupDesc = tupType; queryDesc->tupDesc = tupType;
...@@ -945,7 +973,7 @@ ExecContextForcesOids(PlanState *planstate, bool *hasoids) ...@@ -945,7 +973,7 @@ ExecContextForcesOids(PlanState *planstate, bool *hasoids)
* tuple tables must be cleared or dropped to ensure pins are released. * tuple tables must be cleared or dropped to ensure pins are released.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
void static void
ExecEndPlan(PlanState *planstate, EState *estate) ExecEndPlan(PlanState *planstate, EState *estate)
{ {
ResultRelInfo *resultRelInfo; ResultRelInfo *resultRelInfo;
...@@ -963,6 +991,16 @@ ExecEndPlan(PlanState *planstate, EState *estate) ...@@ -963,6 +991,16 @@ ExecEndPlan(PlanState *planstate, EState *estate)
*/ */
ExecEndNode(planstate); ExecEndNode(planstate);
/*
* for subplans too
*/
foreach(l, estate->es_subplanstates)
{
PlanState *subplanstate = (PlanState *) lfirst(l);
ExecEndNode(subplanstate);
}
/* /*
* destroy the executor "tuple" table. * destroy the executor "tuple" table.
*/ */
...@@ -2205,13 +2243,10 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq) ...@@ -2205,13 +2243,10 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq)
EState *epqstate; EState *epqstate;
int rtsize; int rtsize;
MemoryContext oldcontext; MemoryContext oldcontext;
ListCell *l;
rtsize = list_length(estate->es_range_table); rtsize = list_length(estate->es_range_table);
/*
* It's tempting to think about using CreateSubExecutorState here, but
* at present we can't because of memory leakage concerns ...
*/
epq->estate = epqstate = CreateExecutorState(); epq->estate = epqstate = CreateExecutorState();
oldcontext = MemoryContextSwitchTo(epqstate->es_query_cxt); oldcontext = MemoryContextSwitchTo(epqstate->es_query_cxt);
...@@ -2256,9 +2291,34 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq) ...@@ -2256,9 +2291,34 @@ EvalPlanQualStart(evalPlanQual *epq, EState *estate, evalPlanQual *priorepq)
/* later stack entries share the same storage */ /* later stack entries share the same storage */
epqstate->es_evTuple = priorepq->estate->es_evTuple; epqstate->es_evTuple = priorepq->estate->es_evTuple;
/*
* Create sub-tuple-table; we needn't redo the CountSlots work though.
*/
epqstate->es_tupleTable = epqstate->es_tupleTable =
ExecCreateTupleTable(estate->es_tupleTable->size); ExecCreateTupleTable(estate->es_tupleTable->size);
/*
* Initialize private state information for each SubPlan. We must do
* this before running ExecInitNode on the main query tree, since
* ExecInitSubPlan expects to be able to find these entries.
*/
Assert(epqstate->es_subplanstates == NIL);
foreach(l, estate->es_plannedstmt->subplans)
{
Plan *subplan = (Plan *) lfirst(l);
PlanState *subplanstate;
subplanstate = ExecInitNode(subplan, epqstate, 0);
epqstate->es_subplanstates = lappend(epqstate->es_subplanstates,
subplanstate);
}
/*
* Initialize the private state information for all the nodes in the query
* tree. This opens files, allocates storage and leaves us ready to start
* processing tuples.
*/
epq->planstate = ExecInitNode(estate->es_plannedstmt->planTree, epqstate, 0); epq->planstate = ExecInitNode(estate->es_plannedstmt->planTree, epqstate, 0);
MemoryContextSwitchTo(oldcontext); MemoryContextSwitchTo(oldcontext);
...@@ -2276,11 +2336,19 @@ EvalPlanQualStop(evalPlanQual *epq) ...@@ -2276,11 +2336,19 @@ EvalPlanQualStop(evalPlanQual *epq)
{ {
EState *epqstate = epq->estate; EState *epqstate = epq->estate;
MemoryContext oldcontext; MemoryContext oldcontext;
ListCell *l;
oldcontext = MemoryContextSwitchTo(epqstate->es_query_cxt); oldcontext = MemoryContextSwitchTo(epqstate->es_query_cxt);
ExecEndNode(epq->planstate); ExecEndNode(epq->planstate);
foreach(l, epqstate->es_subplanstates)
{
PlanState *subplanstate = (PlanState *) lfirst(l);
ExecEndNode(subplanstate);
}
ExecDropTupleTable(epqstate->es_tupleTable, true); ExecDropTupleTable(epqstate->es_tupleTable, true);
epqstate->es_tupleTable = NULL; epqstate->es_tupleTable = NULL;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.60 2007/01/05 22:19:27 momjian Exp $ * $PostgreSQL: pgsql/src/backend/executor/execProcnode.c,v 1.61 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -278,26 +278,11 @@ ExecInitNode(Plan *node, EState *estate, int eflags) ...@@ -278,26 +278,11 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
SubPlanState *sstate; SubPlanState *sstate;
Assert(IsA(subplan, SubPlan)); Assert(IsA(subplan, SubPlan));
sstate = ExecInitExprInitPlan(subplan, result); sstate = ExecInitSubPlan(subplan, result);
ExecInitSubPlan(sstate, estate, eflags);
subps = lappend(subps, sstate); subps = lappend(subps, sstate);
} }
result->initPlan = subps; result->initPlan = subps;
/*
* Initialize any subPlans present in this node. These were found by
* ExecInitExpr during initialization of the PlanState. Note we must do
* this after initializing initPlans, in case their arguments contain
* subPlans (is that actually possible? perhaps not).
*/
foreach(l, result->subPlan)
{
SubPlanState *sstate = (SubPlanState *) lfirst(l);
Assert(IsA(sstate, SubPlanState));
ExecInitSubPlan(sstate, estate, eflags);
}
/* Set up instrumentation for this node if requested */ /* Set up instrumentation for this node if requested */
if (estate->es_instrument) if (estate->es_instrument)
result->instrument = InstrAlloc(1); result->instrument = InstrAlloc(1);
...@@ -610,20 +595,12 @@ ExecCountSlotsNode(Plan *node) ...@@ -610,20 +595,12 @@ ExecCountSlotsNode(Plan *node)
void void
ExecEndNode(PlanState *node) ExecEndNode(PlanState *node)
{ {
ListCell *subp;
/* /*
* do nothing when we get to the end of a leaf on tree. * do nothing when we get to the end of a leaf on tree.
*/ */
if (node == NULL) if (node == NULL)
return; return;
/* Clean up initPlans and subPlans */
foreach(subp, node->initPlan)
ExecEndSubPlan((SubPlanState *) lfirst(subp));
foreach(subp, node->subPlan)
ExecEndSubPlan((SubPlanState *) lfirst(subp));
if (node->chgParam != NULL) if (node->chgParam != NULL)
{ {
bms_free(node->chgParam); bms_free(node->chgParam);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.213 2007/02/06 17:35:20 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.214 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -3723,27 +3723,16 @@ ExecInitExpr(Expr *node, PlanState *parent) ...@@ -3723,27 +3723,16 @@ ExecInitExpr(Expr *node, PlanState *parent)
break; break;
case T_SubPlan: case T_SubPlan:
{ {
/* Keep this in sync with ExecInitExprInitPlan, below */
SubPlan *subplan = (SubPlan *) node; SubPlan *subplan = (SubPlan *) node;
SubPlanState *sstate = makeNode(SubPlanState); SubPlanState *sstate;
sstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecSubPlan;
if (!parent) if (!parent)
elog(ERROR, "SubPlan found with no parent plan"); elog(ERROR, "SubPlan found with no parent plan");
/* sstate = ExecInitSubPlan(subplan, parent);
* Here we just add the SubPlanState nodes to parent->subPlan.
* The subplans will be initialized later.
*/
parent->subPlan = lcons(sstate, parent->subPlan);
sstate->sub_estate = NULL;
sstate->planstate = NULL;
sstate->testexpr = /* Add SubPlanState nodes to parent->subPlan */
ExecInitExpr((Expr *) subplan->testexpr, parent); parent->subPlan = lcons(sstate, parent->subPlan);
sstate->args = (List *)
ExecInitExpr((Expr *) subplan->args, parent);
state = (ExprState *) sstate; state = (ExprState *) sstate;
} }
...@@ -4157,32 +4146,6 @@ ExecInitExpr(Expr *node, PlanState *parent) ...@@ -4157,32 +4146,6 @@ ExecInitExpr(Expr *node, PlanState *parent)
return state; return state;
} }
/*
* ExecInitExprInitPlan --- initialize a subplan expr that's being handled
* as an InitPlan. This is identical to ExecInitExpr's handling of a regular
* subplan expr, except we do NOT want to add the node to the parent's
* subplan list.
*/
SubPlanState *
ExecInitExprInitPlan(SubPlan *node, PlanState *parent)
{
SubPlanState *sstate = makeNode(SubPlanState);
if (!parent)
elog(ERROR, "SubPlan found with no parent plan");
/* The subplan's state will be initialized later */
sstate->sub_estate = NULL;
sstate->planstate = NULL;
sstate->testexpr = ExecInitExpr((Expr *) node->testexpr, parent);
sstate->args = (List *) ExecInitExpr((Expr *) node->args, parent);
sstate->xprstate.expr = (Expr *) node;
return sstate;
}
/* /*
* ExecPrepareExpr --- initialize for expression execution outside a normal * ExecPrepareExpr --- initialize for expression execution outside a normal
* Plan tree context. * Plan tree context.
......
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.146 2007/02/22 22:00:22 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/execUtils.c,v 1.147 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
/* /*
* INTERFACE ROUTINES * INTERFACE ROUTINES
* CreateExecutorState Create/delete executor working state * CreateExecutorState Create/delete executor working state
* CreateSubExecutorState
* FreeExecutorState * FreeExecutorState
* CreateExprContext * CreateExprContext
* CreateStandaloneExprContext * CreateStandaloneExprContext
...@@ -66,8 +65,6 @@ int NIndexTupleInserted; ...@@ -66,8 +65,6 @@ int NIndexTupleInserted;
int NIndexTupleProcessed; int NIndexTupleProcessed;
static EState *InternalCreateExecutorState(MemoryContext qcontext,
bool is_subquery);
static void ShutdownExprContext(ExprContext *econtext); static void ShutdownExprContext(ExprContext *econtext);
...@@ -152,7 +149,9 @@ DisplayTupleCount(FILE *statfp) ...@@ -152,7 +149,9 @@ DisplayTupleCount(FILE *statfp)
EState * EState *
CreateExecutorState(void) CreateExecutorState(void)
{ {
EState *estate;
MemoryContext qcontext; MemoryContext qcontext;
MemoryContext oldcontext;
/* /*
* Create the per-query context for this Executor run. * Create the per-query context for this Executor run.
...@@ -163,37 +162,6 @@ CreateExecutorState(void) ...@@ -163,37 +162,6 @@ CreateExecutorState(void)
ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE); ALLOCSET_DEFAULT_MAXSIZE);
return InternalCreateExecutorState(qcontext, false);
}
/* ----------------
* CreateSubExecutorState
*
* Create and initialize an EState node for a sub-query.
*
* Ideally, sub-queries probably shouldn't have their own EState at all,
* but right now this is necessary because they have their own rangetables
* and we access the rangetable via the EState. It is critical that a
* sub-query share the parent's es_query_cxt, else structures allocated by
* the sub-query (especially its result tuple descriptor) may disappear
* too soon during executor shutdown.
* ----------------
*/
EState *
CreateSubExecutorState(EState *parent_estate)
{
return InternalCreateExecutorState(parent_estate->es_query_cxt, true);
}
/*
* Guts of CreateExecutorState/CreateSubExecutorState
*/
static EState *
InternalCreateExecutorState(MemoryContext qcontext, bool is_subquery)
{
EState *estate;
MemoryContext oldcontext;
/* /*
* Make the EState node within the per-query context. This way, we don't * Make the EState node within the per-query context. This way, we don't
* need a separate pfree() operation for it at shutdown. * need a separate pfree() operation for it at shutdown.
...@@ -232,14 +200,14 @@ InternalCreateExecutorState(MemoryContext qcontext, bool is_subquery) ...@@ -232,14 +200,14 @@ InternalCreateExecutorState(MemoryContext qcontext, bool is_subquery)
estate->es_lastoid = InvalidOid; estate->es_lastoid = InvalidOid;
estate->es_rowMarks = NIL; estate->es_rowMarks = NIL;
estate->es_is_subquery = is_subquery;
estate->es_instrument = false; estate->es_instrument = false;
estate->es_select_into = false; estate->es_select_into = false;
estate->es_into_oids = false; estate->es_into_oids = false;
estate->es_exprcontexts = NIL; estate->es_exprcontexts = NIL;
estate->es_subplanstates = NIL;
estate->es_per_tuple_exprcontext = NULL; estate->es_per_tuple_exprcontext = NULL;
estate->es_plannedstmt = NULL; estate->es_plannedstmt = NULL;
...@@ -292,12 +260,9 @@ FreeExecutorState(EState *estate) ...@@ -292,12 +260,9 @@ FreeExecutorState(EState *estate)
/* /*
* Free the per-query memory context, thereby releasing all working * Free the per-query memory context, thereby releasing all working
* memory, including the EState node itself. In a subquery, we don't * memory, including the EState node itself.
* do this, leaving the memory cleanup to happen when the topmost query
* is closed down.
*/ */
if (!estate->es_is_subquery) MemoryContextDelete(estate->es_query_cxt);
MemoryContextDelete(estate->es_query_cxt);
} }
/* ---------------- /* ----------------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.86 2007/02/22 22:00:23 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/nodeSubplan.c,v 1.87 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
* INTERFACE ROUTINES * INTERFACE ROUTINES
* ExecSubPlan - process a subselect * ExecSubPlan - process a subselect
* ExecInitSubPlan - initialize a subselect * ExecInitSubPlan - initialize a subselect
* ExecEndSubPlan - shut down a subselect
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -37,7 +36,7 @@ static Datum ExecHashSubPlan(SubPlanState *node, ...@@ -37,7 +36,7 @@ static Datum ExecHashSubPlan(SubPlanState *node,
static Datum ExecScanSubPlan(SubPlanState *node, static Datum ExecScanSubPlan(SubPlanState *node,
ExprContext *econtext, ExprContext *econtext,
bool *isNull); bool *isNull);
static void buildSubPlanHash(SubPlanState *node); static void buildSubPlanHash(SubPlanState *node, ExprContext *econtext);
static bool findPartialMatch(TupleHashTable hashtable, TupleTableSlot *slot); static bool findPartialMatch(TupleHashTable hashtable, TupleTableSlot *slot);
static bool slotAllNulls(TupleTableSlot *slot); static bool slotAllNulls(TupleTableSlot *slot);
static bool slotNoNulls(TupleTableSlot *slot); static bool slotNoNulls(TupleTableSlot *slot);
...@@ -91,7 +90,7 @@ ExecHashSubPlan(SubPlanState *node, ...@@ -91,7 +90,7 @@ ExecHashSubPlan(SubPlanState *node,
* table. * table.
*/ */
if (node->hashtable == NULL || planstate->chgParam != NULL) if (node->hashtable == NULL || planstate->chgParam != NULL)
buildSubPlanHash(node); buildSubPlanHash(node, econtext);
/* /*
* The result for an empty subplan is always FALSE; no need to evaluate * The result for an empty subplan is always FALSE; no need to evaluate
...@@ -219,10 +218,10 @@ ExecScanSubPlan(SubPlanState *node, ...@@ -219,10 +218,10 @@ ExecScanSubPlan(SubPlanState *node,
/* /*
* We are probably in a short-lived expression-evaluation context. Switch * We are probably in a short-lived expression-evaluation context. Switch
* to the child plan's per-query context for manipulating its chgParam, * to the per-query context for manipulating the child plan's chgParam,
* calling ExecProcNode on it, etc. * calling ExecProcNode on it, etc.
*/ */
oldcontext = MemoryContextSwitchTo(node->sub_estate->es_query_cxt); oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
/* /*
* Set Params of this plan from parent plan correlation values. (Any * Set Params of this plan from parent plan correlation values. (Any
...@@ -299,11 +298,9 @@ ExecScanSubPlan(SubPlanState *node, ...@@ -299,11 +298,9 @@ ExecScanSubPlan(SubPlanState *node,
* node->curTuple keeps track of the copied tuple for eventual * node->curTuple keeps track of the copied tuple for eventual
* freeing. * freeing.
*/ */
MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
if (node->curTuple) if (node->curTuple)
heap_freetuple(node->curTuple); heap_freetuple(node->curTuple);
node->curTuple = ExecCopySlotTuple(slot); node->curTuple = ExecCopySlotTuple(slot);
MemoryContextSwitchTo(node->sub_estate->es_query_cxt);
result = heap_getattr(node->curTuple, 1, tdesc, isNull); result = heap_getattr(node->curTuple, 1, tdesc, isNull);
/* keep scanning subplan to make sure there's only one tuple */ /* keep scanning subplan to make sure there's only one tuple */
...@@ -416,7 +413,7 @@ ExecScanSubPlan(SubPlanState *node, ...@@ -416,7 +413,7 @@ ExecScanSubPlan(SubPlanState *node,
* buildSubPlanHash: load hash table by scanning subplan output. * buildSubPlanHash: load hash table by scanning subplan output.
*/ */
static void static void
buildSubPlanHash(SubPlanState *node) buildSubPlanHash(SubPlanState *node, ExprContext *econtext)
{ {
SubPlan *subplan = (SubPlan *) node->xprstate.expr; SubPlan *subplan = (SubPlan *) node->xprstate.expr;
PlanState *planstate = node->planstate; PlanState *planstate = node->planstate;
...@@ -485,9 +482,9 @@ buildSubPlanHash(SubPlanState *node) ...@@ -485,9 +482,9 @@ buildSubPlanHash(SubPlanState *node)
/* /*
* We are probably in a short-lived expression-evaluation context. Switch * We are probably in a short-lived expression-evaluation context. Switch
* to the child plan's per-query context for calling ExecProcNode. * to the per-query context for manipulating the child plan.
*/ */
oldcontext = MemoryContextSwitchTo(node->sub_estate->es_query_cxt); oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
/* /*
* Reset subplan to start. * Reset subplan to start.
...@@ -628,72 +625,45 @@ slotNoNulls(TupleTableSlot *slot) ...@@ -628,72 +625,45 @@ slotNoNulls(TupleTableSlot *slot)
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* ExecInitSubPlan * ExecInitSubPlan
* *
* Note: the eflags are those passed to the parent plan node of this * Create a SubPlanState for a SubPlan; this is the SubPlan-specific part
* subplan; they don't directly describe the execution conditions the * of ExecInitExpr(). We split it out so that it can be used for InitPlans
* subplan will face. * as well as regular SubPlans. Note that we don't link the SubPlan into
* the parent's subPlan list, because that shouldn't happen for InitPlans.
* Instead, ExecInitExpr() does that one part.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
void SubPlanState *
ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) ExecInitSubPlan(SubPlan *subplan, PlanState *parent)
{ {
SubPlan *subplan = (SubPlan *) node->xprstate.expr; SubPlanState *sstate = makeNode(SubPlanState);
Plan *plan = exec_subplan_get_plan(estate->es_plannedstmt, subplan); EState *estate = parent->state;
EState *sp_estate;
/* sstate->xprstate.evalfunc = (ExprStateEvalFunc) ExecSubPlan;
* initialize my state sstate->xprstate.expr = (Expr *) subplan;
*/
node->needShutdown = false;
node->curTuple = NULL;
node->projLeft = NULL;
node->projRight = NULL;
node->hashtable = NULL;
node->hashnulls = NULL;
node->tablecxt = NULL;
node->innerecontext = NULL;
node->keyColIdx = NULL;
node->tab_hash_funcs = NULL;
node->tab_eq_funcs = NULL;
node->lhs_hash_funcs = NULL;
node->cur_eq_funcs = NULL;
/* /* Link the SubPlanState to already-initialized subplan */
* create an EState for the subplan sstate->planstate = (PlanState *) list_nth(estate->es_subplanstates,
* subplan->plan_id - 1);
* The subquery needs its own EState because it has its own rangetable. It
* shares our Param ID space and es_query_cxt, however. XXX if rangetable /* Initialize subexpressions */
* access were done differently, the subquery could share our EState, sstate->testexpr = ExecInitExpr((Expr *) subplan->testexpr, parent);
* which would eliminate some thrashing about in this module... sstate->args = (List *) ExecInitExpr((Expr *) subplan->args, parent);
*
* XXX make that happen!
*/
sp_estate = CreateSubExecutorState(estate);
node->sub_estate = sp_estate;
sp_estate->es_range_table = estate->es_range_table;
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(plan) + 10);
sp_estate->es_snapshot = estate->es_snapshot;
sp_estate->es_crosscheck_snapshot = estate->es_crosscheck_snapshot;
sp_estate->es_instrument = estate->es_instrument;
sp_estate->es_plannedstmt = estate->es_plannedstmt;
/* /*
* Start up the subplan (this is a very cut-down form of InitPlan()) * initialize my state
*
* The subplan will never need to do BACKWARD scan or MARK/RESTORE. If it
* is a parameterless subplan (not initplan), we suggest that it be
* prepared to handle REWIND efficiently; otherwise there is no need.
*/ */
eflags &= EXEC_FLAG_EXPLAIN_ONLY; sstate->curTuple = NULL;
if (subplan->parParam == NIL && subplan->setParam == NIL) sstate->projLeft = NULL;
eflags |= EXEC_FLAG_REWIND; sstate->projRight = NULL;
sstate->hashtable = NULL;
node->planstate = ExecInitNode(plan, sp_estate, eflags); sstate->hashnulls = NULL;
sstate->tablecxt = NULL;
node->needShutdown = true; /* now we need to shutdown the subplan */ sstate->innerecontext = NULL;
sstate->keyColIdx = NULL;
sstate->tab_hash_funcs = NULL;
sstate->tab_eq_funcs = NULL;
sstate->lhs_hash_funcs = NULL;
sstate->cur_eq_funcs = NULL;
/* /*
* If this plan is un-correlated or undirect correlated one and want to * If this plan is un-correlated or undirect correlated one and want to
...@@ -712,7 +682,7 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) ...@@ -712,7 +682,7 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags)
int paramid = lfirst_int(lst); int paramid = lfirst_int(lst);
ParamExecData *prm = &(estate->es_param_exec_vals[paramid]); ParamExecData *prm = &(estate->es_param_exec_vals[paramid]);
prm->execPlan = node; prm->execPlan = sstate;
} }
} }
...@@ -735,19 +705,19 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) ...@@ -735,19 +705,19 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags)
ListCell *l; ListCell *l;
/* We need a memory context to hold the hash table(s) */ /* We need a memory context to hold the hash table(s) */
node->tablecxt = sstate->tablecxt =
AllocSetContextCreate(CurrentMemoryContext, AllocSetContextCreate(CurrentMemoryContext,
"Subplan HashTable Context", "Subplan HashTable Context",
ALLOCSET_DEFAULT_MINSIZE, ALLOCSET_DEFAULT_MINSIZE,
ALLOCSET_DEFAULT_INITSIZE, ALLOCSET_DEFAULT_INITSIZE,
ALLOCSET_DEFAULT_MAXSIZE); ALLOCSET_DEFAULT_MAXSIZE);
/* and a short-lived exprcontext for function evaluation */ /* and a short-lived exprcontext for function evaluation */
node->innerecontext = CreateExprContext(estate); sstate->innerecontext = CreateExprContext(estate);
/* Silly little array of column numbers 1..n */ /* Silly little array of column numbers 1..n */
ncols = list_length(subplan->paramIds); ncols = list_length(subplan->paramIds);
node->keyColIdx = (AttrNumber *) palloc(ncols * sizeof(AttrNumber)); sstate->keyColIdx = (AttrNumber *) palloc(ncols * sizeof(AttrNumber));
for (i = 0; i < ncols; i++) for (i = 0; i < ncols; i++)
node->keyColIdx[i] = i + 1; sstate->keyColIdx[i] = i + 1;
/* /*
* We use ExecProject to evaluate the lefthand and righthand * We use ExecProject to evaluate the lefthand and righthand
...@@ -763,32 +733,32 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) ...@@ -763,32 +733,32 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags)
* We also extract the combining operators themselves to initialize * We also extract the combining operators themselves to initialize
* the equality and hashing functions for the hash tables. * the equality and hashing functions for the hash tables.
*/ */
if (IsA(node->testexpr->expr, OpExpr)) if (IsA(sstate->testexpr->expr, OpExpr))
{ {
/* single combining operator */ /* single combining operator */
oplist = list_make1(node->testexpr); oplist = list_make1(sstate->testexpr);
} }
else if (and_clause((Node *) node->testexpr->expr)) else if (and_clause((Node *) sstate->testexpr->expr))
{ {
/* multiple combining operators */ /* multiple combining operators */
Assert(IsA(node->testexpr, BoolExprState)); Assert(IsA(sstate->testexpr, BoolExprState));
oplist = ((BoolExprState *) node->testexpr)->args; oplist = ((BoolExprState *) sstate->testexpr)->args;
} }
else else
{ {
/* shouldn't see anything else in a hashable subplan */ /* shouldn't see anything else in a hashable subplan */
elog(ERROR, "unrecognized testexpr type: %d", elog(ERROR, "unrecognized testexpr type: %d",
(int) nodeTag(node->testexpr->expr)); (int) nodeTag(sstate->testexpr->expr));
oplist = NIL; /* keep compiler quiet */ oplist = NIL; /* keep compiler quiet */
} }
Assert(list_length(oplist) == ncols); Assert(list_length(oplist) == ncols);
lefttlist = righttlist = NIL; lefttlist = righttlist = NIL;
leftptlist = rightptlist = NIL; leftptlist = rightptlist = NIL;
node->tab_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo)); sstate->tab_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo));
node->tab_eq_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo)); sstate->tab_eq_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo));
node->lhs_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo)); sstate->lhs_hash_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo));
node->cur_eq_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo)); sstate->cur_eq_funcs = (FmgrInfo *) palloc(ncols * sizeof(FmgrInfo));
i = 1; i = 1;
foreach(l, oplist) foreach(l, oplist)
{ {
...@@ -835,23 +805,23 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) ...@@ -835,23 +805,23 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags)
rightptlist = lappend(rightptlist, tle); rightptlist = lappend(rightptlist, tle);
/* Lookup the equality function (potentially cross-type) */ /* Lookup the equality function (potentially cross-type) */
fmgr_info(opexpr->opfuncid, &node->cur_eq_funcs[i - 1]); fmgr_info(opexpr->opfuncid, &sstate->cur_eq_funcs[i - 1]);
node->cur_eq_funcs[i - 1].fn_expr = (Node *) opexpr; sstate->cur_eq_funcs[i - 1].fn_expr = (Node *) opexpr;
/* Look up the equality function for the RHS type */ /* Look up the equality function for the RHS type */
if (!get_compatible_hash_operators(opexpr->opno, if (!get_compatible_hash_operators(opexpr->opno,
NULL, &rhs_eq_oper)) NULL, &rhs_eq_oper))
elog(ERROR, "could not find compatible hash operator for operator %u", elog(ERROR, "could not find compatible hash operator for operator %u",
opexpr->opno); opexpr->opno);
fmgr_info(get_opcode(rhs_eq_oper), &node->tab_eq_funcs[i - 1]); fmgr_info(get_opcode(rhs_eq_oper), &sstate->tab_eq_funcs[i - 1]);
/* Lookup the associated hash functions */ /* Lookup the associated hash functions */
if (!get_op_hash_functions(opexpr->opno, if (!get_op_hash_functions(opexpr->opno,
&left_hashfn, &right_hashfn)) &left_hashfn, &right_hashfn))
elog(ERROR, "could not find hash function for hash operator %u", elog(ERROR, "could not find hash function for hash operator %u",
opexpr->opno); opexpr->opno);
fmgr_info(left_hashfn, &node->lhs_hash_funcs[i - 1]); fmgr_info(left_hashfn, &sstate->lhs_hash_funcs[i - 1]);
fmgr_info(right_hashfn, &node->tab_hash_funcs[i - 1]); fmgr_info(right_hashfn, &sstate->tab_hash_funcs[i - 1]);
i++; i++;
} }
...@@ -876,7 +846,7 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) ...@@ -876,7 +846,7 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags)
tupDesc = ExecTypeFromTL(leftptlist, false); tupDesc = ExecTypeFromTL(leftptlist, false);
slot = ExecAllocTableSlot(tupTable); slot = ExecAllocTableSlot(tupTable);
ExecSetSlotDescriptor(slot, tupDesc); ExecSetSlotDescriptor(slot, tupDesc);
node->projLeft = ExecBuildProjectionInfo(lefttlist, sstate->projLeft = ExecBuildProjectionInfo(lefttlist,
NULL, NULL,
slot, slot,
NULL); NULL);
...@@ -884,11 +854,13 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags) ...@@ -884,11 +854,13 @@ ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags)
tupDesc = ExecTypeFromTL(rightptlist, false); tupDesc = ExecTypeFromTL(rightptlist, false);
slot = ExecAllocTableSlot(tupTable); slot = ExecAllocTableSlot(tupTable);
ExecSetSlotDescriptor(slot, tupDesc); ExecSetSlotDescriptor(slot, tupDesc);
node->projRight = ExecBuildProjectionInfo(righttlist, sstate->projRight = ExecBuildProjectionInfo(righttlist,
node->innerecontext, sstate->innerecontext,
slot, slot,
NULL); NULL);
} }
return sstate;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
...@@ -917,9 +889,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) ...@@ -917,9 +889,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
ArrayBuildState *astate = NULL; ArrayBuildState *astate = NULL;
/* /*
* Must switch to child query's per-query memory context. * Must switch to per-query memory context.
*/ */
oldcontext = MemoryContextSwitchTo(node->sub_estate->es_query_cxt); oldcontext = MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
if (subLinkType == ANY_SUBLINK || if (subLinkType == ANY_SUBLINK ||
subLinkType == ALL_SUBLINK) subLinkType == ALL_SUBLINK)
...@@ -978,11 +950,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) ...@@ -978,11 +950,9 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
* the param structs will point at this copied tuple! node->curTuple * the param structs will point at this copied tuple! node->curTuple
* keeps track of the copied tuple for eventual freeing. * keeps track of the copied tuple for eventual freeing.
*/ */
MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
if (node->curTuple) if (node->curTuple)
heap_freetuple(node->curTuple); heap_freetuple(node->curTuple);
node->curTuple = ExecCopySlotTuple(slot); node->curTuple = ExecCopySlotTuple(slot);
MemoryContextSwitchTo(node->sub_estate->es_query_cxt);
/* /*
* Now set all the setParam params from the columns of the tuple * Now set all the setParam params from the columns of the tuple
...@@ -1040,23 +1010,6 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext) ...@@ -1040,23 +1010,6 @@ ExecSetParamPlan(SubPlanState *node, ExprContext *econtext)
MemoryContextSwitchTo(oldcontext); MemoryContextSwitchTo(oldcontext);
} }
/* ----------------------------------------------------------------
* ExecEndSubPlan
* ----------------------------------------------------------------
*/
void
ExecEndSubPlan(SubPlanState *node)
{
if (node->needShutdown)
{
ExecEndPlan(node->planstate, node->sub_estate);
FreeExecutorState(node->sub_estate);
node->sub_estate = NULL;
node->planstate = NULL;
node->needShutdown = false;
}
}
/* /*
* Mark an initplan as needing recalculation * Mark an initplan as needing recalculation
*/ */
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.36 2007/02/22 22:00:23 tgl Exp $ * $PostgreSQL: pgsql/src/backend/executor/nodeSubqueryscan.c,v 1.37 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -45,16 +45,8 @@ static TupleTableSlot *SubqueryNext(SubqueryScanState *node); ...@@ -45,16 +45,8 @@ static TupleTableSlot *SubqueryNext(SubqueryScanState *node);
static TupleTableSlot * static TupleTableSlot *
SubqueryNext(SubqueryScanState *node) SubqueryNext(SubqueryScanState *node)
{ {
EState *estate;
ScanDirection direction;
TupleTableSlot *slot; TupleTableSlot *slot;
/*
* get information from the estate and scan state
*/
estate = node->ss.ps.state;
direction = estate->es_direction;
/* /*
* We need not support EvalPlanQual here, since we are not scanning a real * We need not support EvalPlanQual here, since we are not scanning a real
* relation. * relation.
...@@ -63,8 +55,6 @@ SubqueryNext(SubqueryScanState *node) ...@@ -63,8 +55,6 @@ SubqueryNext(SubqueryScanState *node)
/* /*
* Get the next tuple from the sub-query. * Get the next tuple from the sub-query.
*/ */
node->sss_SubEState->es_direction = direction;
slot = ExecProcNode(node->subplan); slot = ExecProcNode(node->subplan);
/* /*
...@@ -103,7 +93,6 @@ SubqueryScanState * ...@@ -103,7 +93,6 @@ SubqueryScanState *
ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags) ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags)
{ {
SubqueryScanState *subquerystate; SubqueryScanState *subquerystate;
EState *sp_estate;
/* check for unsupported flags */ /* check for unsupported flags */
Assert(!(eflags & EXEC_FLAG_MARK)); Assert(!(eflags & EXEC_FLAG_MARK));
...@@ -150,44 +139,16 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags) ...@@ -150,44 +139,16 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags)
/* /*
* initialize subquery * initialize subquery
*
* This should agree with ExecInitSubPlan
*
* The subquery needs its own EState because it has its own rangetable. It
* shares our Param ID space and es_query_cxt, however. XXX if rangetable
* access were done differently, the subquery could share our EState,
* which would eliminate some thrashing about in this module...
*
* XXX make that happen!
*/ */
sp_estate = CreateSubExecutorState(estate); subquerystate->subplan = ExecInitNode(node->subplan, estate, eflags);
subquerystate->sss_SubEState = sp_estate;
sp_estate->es_range_table = estate->es_range_table;
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(node->subplan) + 10);
sp_estate->es_snapshot = estate->es_snapshot;
sp_estate->es_crosscheck_snapshot = estate->es_crosscheck_snapshot;
sp_estate->es_instrument = estate->es_instrument;
sp_estate->es_plannedstmt = estate->es_plannedstmt;
/*
* Start up the subplan (this is a very cut-down form of InitPlan())
*/
subquerystate->subplan = ExecInitNode(node->subplan, sp_estate, eflags);
subquerystate->ss.ps.ps_TupFromTlist = false; subquerystate->ss.ps.ps_TupFromTlist = false;
/* /*
* Initialize scan tuple type (needed by ExecAssignScanProjectionInfo). * Initialize scan tuple type (needed by ExecAssignScanProjectionInfo)
* Because the subplan is in its own memory context, we need to copy its
* result tuple type not just link to it; else the tupdesc will disappear
* too soon during shutdown.
*/ */
ExecAssignScanType(&subquerystate->ss, ExecAssignScanType(&subquerystate->ss,
CreateTupleDescCopy(ExecGetResultType(subquerystate->subplan))); ExecGetResultType(subquerystate->subplan));
/* /*
* Initialize result tuple type and projection info. * Initialize result tuple type and projection info.
...@@ -201,11 +162,9 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags) ...@@ -201,11 +162,9 @@ ExecInitSubqueryScan(SubqueryScan *node, EState *estate, int eflags)
int int
ExecCountSlotsSubqueryScan(SubqueryScan *node) ExecCountSlotsSubqueryScan(SubqueryScan *node)
{ {
/* Assert(outerPlan(node) == NULL);
* The subplan has its own tuple table and must not be counted here! Assert(innerPlan(node) == NULL);
*/ return ExecCountSlotsNode(node->subplan) +
return ExecCountSlotsNode(outerPlan(node)) +
ExecCountSlotsNode(innerPlan(node)) +
SUBQUERYSCAN_NSLOTS; SUBQUERYSCAN_NSLOTS;
} }
...@@ -232,9 +191,7 @@ ExecEndSubqueryScan(SubqueryScanState *node) ...@@ -232,9 +191,7 @@ ExecEndSubqueryScan(SubqueryScanState *node)
/* /*
* close down subquery * close down subquery
*/ */
ExecEndPlan(node->subplan, node->sss_SubEState); ExecEndNode(node->subplan);
FreeExecutorState(node->sss_SubEState);
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.368 2007/02/22 22:00:23 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.369 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -79,6 +79,7 @@ _copyPlannedStmt(PlannedStmt *from) ...@@ -79,6 +79,7 @@ _copyPlannedStmt(PlannedStmt *from)
COPY_NODE_FIELD(resultRelations); COPY_NODE_FIELD(resultRelations);
COPY_NODE_FIELD(into); COPY_NODE_FIELD(into);
COPY_NODE_FIELD(subplans); COPY_NODE_FIELD(subplans);
COPY_BITMAPSET_FIELD(rewindPlanIDs);
COPY_NODE_FIELD(returningLists); COPY_NODE_FIELD(returningLists);
COPY_NODE_FIELD(rowMarks); COPY_NODE_FIELD(rowMarks);
COPY_SCALAR_FIELD(nParamExec); COPY_SCALAR_FIELD(nParamExec);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.301 2007/02/22 22:00:23 tgl Exp $ * $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.302 2007/02/27 01:11:25 tgl Exp $
* *
* NOTES * NOTES
* Every node type that can appear in stored rules' parsetrees *must* * Every node type that can appear in stored rules' parsetrees *must*
...@@ -246,6 +246,7 @@ _outPlannedStmt(StringInfo str, PlannedStmt *node) ...@@ -246,6 +246,7 @@ _outPlannedStmt(StringInfo str, PlannedStmt *node)
WRITE_NODE_FIELD(resultRelations); WRITE_NODE_FIELD(resultRelations);
WRITE_NODE_FIELD(into); WRITE_NODE_FIELD(into);
WRITE_NODE_FIELD(subplans); WRITE_NODE_FIELD(subplans);
WRITE_BITMAPSET_FIELD(rewindPlanIDs);
WRITE_NODE_FIELD(returningLists); WRITE_NODE_FIELD(returningLists);
WRITE_NODE_FIELD(rowMarks); WRITE_NODE_FIELD(rowMarks);
WRITE_INT_FIELD(nParamExec); WRITE_INT_FIELD(nParamExec);
...@@ -1262,6 +1263,7 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node) ...@@ -1262,6 +1263,7 @@ _outPlannerGlobal(StringInfo str, PlannerGlobal *node)
WRITE_NODE_FIELD(paramlist); WRITE_NODE_FIELD(paramlist);
WRITE_NODE_FIELD(subplans); WRITE_NODE_FIELD(subplans);
WRITE_NODE_FIELD(subrtables); WRITE_NODE_FIELD(subrtables);
WRITE_BITMAPSET_FIELD(rewindPlanIDs);
WRITE_NODE_FIELD(finalrtable); WRITE_NODE_FIELD(finalrtable);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.215 2007/02/22 22:00:24 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.216 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -103,6 +103,7 @@ planner(Query *parse, bool isCursor, int cursorOptions, ...@@ -103,6 +103,7 @@ planner(Query *parse, bool isCursor, int cursorOptions,
glob->paramlist = NIL; glob->paramlist = NIL;
glob->subplans = NIL; glob->subplans = NIL;
glob->subrtables = NIL; glob->subrtables = NIL;
glob->rewindPlanIDs = NULL;
glob->finalrtable = NIL; glob->finalrtable = NIL;
/* Determine what fraction of the plan is likely to be scanned */ /* Determine what fraction of the plan is likely to be scanned */
...@@ -158,6 +159,7 @@ planner(Query *parse, bool isCursor, int cursorOptions, ...@@ -158,6 +159,7 @@ planner(Query *parse, bool isCursor, int cursorOptions,
result->resultRelations = root->resultRelations; result->resultRelations = root->resultRelations;
result->into = parse->into; result->into = parse->into;
result->subplans = glob->subplans; result->subplans = glob->subplans;
result->rewindPlanIDs = glob->rewindPlanIDs;
result->returningLists = root->returningLists; result->returningLists = root->returningLists;
result->rowMarks = parse->rowMarks; result->rowMarks = parse->rowMarks;
result->nParamExec = list_length(glob->paramlist); result->nParamExec = list_length(glob->paramlist);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.121 2007/02/22 22:00:24 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.122 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -241,9 +241,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -241,9 +241,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
{ {
Query *subquery = (Query *) (slink->subselect); Query *subquery = (Query *) (slink->subselect);
double tuple_fraction; double tuple_fraction;
SubPlan *node; SubPlan *splan;
Plan *plan; Plan *plan;
PlannerInfo *subroot; PlannerInfo *subroot;
bool isInitPlan;
Bitmapset *tmpset; Bitmapset *tmpset;
int paramid; int paramid;
Node *result; Node *result;
...@@ -295,17 +296,17 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -295,17 +296,17 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
/* /*
* Initialize the SubPlan node. Note plan_id isn't set yet. * Initialize the SubPlan node. Note plan_id isn't set yet.
*/ */
node = makeNode(SubPlan); splan = makeNode(SubPlan);
node->subLinkType = slink->subLinkType; splan->subLinkType = slink->subLinkType;
node->testexpr = NULL; splan->testexpr = NULL;
node->paramIds = NIL; splan->paramIds = NIL;
node->firstColType = get_first_col_type(plan); splan->firstColType = get_first_col_type(plan);
node->useHashTable = false; splan->useHashTable = false;
/* At top level of a qual, can treat UNKNOWN the same as FALSE */ /* At top level of a qual, can treat UNKNOWN the same as FALSE */
node->unknownEqFalse = isTopQual; splan->unknownEqFalse = isTopQual;
node->setParam = NIL; splan->setParam = NIL;
node->parParam = NIL; splan->parParam = NIL;
node->args = NIL; splan->args = NIL;
/* /*
* Make parParam list of params that current query level will pass to this * Make parParam list of params that current query level will pass to this
...@@ -317,7 +318,7 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -317,7 +318,7 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
PlannerParamItem *pitem = list_nth(root->glob->paramlist, paramid); PlannerParamItem *pitem = list_nth(root->glob->paramlist, paramid);
if (pitem->abslevel == root->query_level) if (pitem->abslevel == root->query_level)
node->parParam = lappend_int(node->parParam, paramid); splan->parParam = lappend_int(splan->parParam, paramid);
} }
bms_free(tmpset); bms_free(tmpset);
...@@ -329,16 +330,16 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -329,16 +330,16 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
* PARAM_EXEC Params instead of the PARAM_SUBLINK Params emitted by the * PARAM_EXEC Params instead of the PARAM_SUBLINK Params emitted by the
* parser. * parser.
*/ */
if (node->parParam == NIL && slink->subLinkType == EXISTS_SUBLINK) if (splan->parParam == NIL && slink->subLinkType == EXISTS_SUBLINK)
{ {
Param *prm; Param *prm;
prm = generate_new_param(root, BOOLOID, -1); prm = generate_new_param(root, BOOLOID, -1);
node->setParam = list_make1_int(prm->paramid); splan->setParam = list_make1_int(prm->paramid);
root->init_plans = lappend(root->init_plans, node); isInitPlan = true;
result = (Node *) prm; result = (Node *) prm;
} }
else if (node->parParam == NIL && slink->subLinkType == EXPR_SUBLINK) else if (splan->parParam == NIL && slink->subLinkType == EXPR_SUBLINK)
{ {
TargetEntry *te = linitial(plan->targetlist); TargetEntry *te = linitial(plan->targetlist);
Param *prm; Param *prm;
...@@ -347,11 +348,11 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -347,11 +348,11 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
prm = generate_new_param(root, prm = generate_new_param(root,
exprType((Node *) te->expr), exprType((Node *) te->expr),
exprTypmod((Node *) te->expr)); exprTypmod((Node *) te->expr));
node->setParam = list_make1_int(prm->paramid); splan->setParam = list_make1_int(prm->paramid);
root->init_plans = lappend(root->init_plans, node); isInitPlan = true;
result = (Node *) prm; result = (Node *) prm;
} }
else if (node->parParam == NIL && slink->subLinkType == ARRAY_SUBLINK) else if (splan->parParam == NIL && slink->subLinkType == ARRAY_SUBLINK)
{ {
TargetEntry *te = linitial(plan->targetlist); TargetEntry *te = linitial(plan->targetlist);
Oid arraytype; Oid arraytype;
...@@ -365,19 +366,19 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -365,19 +366,19 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
prm = generate_new_param(root, prm = generate_new_param(root,
arraytype, arraytype,
exprTypmod((Node *) te->expr)); exprTypmod((Node *) te->expr));
node->setParam = list_make1_int(prm->paramid); splan->setParam = list_make1_int(prm->paramid);
root->init_plans = lappend(root->init_plans, node); isInitPlan = true;
result = (Node *) prm; result = (Node *) prm;
} }
else if (node->parParam == NIL && slink->subLinkType == ROWCOMPARE_SUBLINK) else if (splan->parParam == NIL && slink->subLinkType == ROWCOMPARE_SUBLINK)
{ {
/* Adjust the Params */ /* Adjust the Params */
result = convert_testexpr(root, result = convert_testexpr(root,
testexpr, testexpr,
0, 0,
&node->paramIds); &splan->paramIds);
node->setParam = list_copy(node->paramIds); splan->setParam = list_copy(splan->paramIds);
root->init_plans = lappend(root->init_plans, node); isInitPlan = true;
/* /*
* The executable expression is returned to become part of the outer * The executable expression is returned to become part of the outer
...@@ -390,10 +391,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -390,10 +391,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
ListCell *l; ListCell *l;
/* Adjust the Params */ /* Adjust the Params */
node->testexpr = convert_testexpr(root, splan->testexpr = convert_testexpr(root,
testexpr, testexpr,
0, 0,
&node->paramIds); &splan->paramIds);
/* /*
* We can't convert subplans of ALL_SUBLINK or ANY_SUBLINK types to * We can't convert subplans of ALL_SUBLINK or ANY_SUBLINK types to
...@@ -402,8 +403,8 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -402,8 +403,8 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
* tuple. But if it's an IN (= ANY) test, we might be able to use a * tuple. But if it's an IN (= ANY) test, we might be able to use a
* hashtable to avoid comparing all the tuples. * hashtable to avoid comparing all the tuples.
*/ */
if (subplan_is_hashable(slink, node, plan)) if (subplan_is_hashable(slink, splan, plan))
node->useHashTable = true; splan->useHashTable = true;
/* /*
* Otherwise, we have the option to tack a MATERIAL node onto the top * Otherwise, we have the option to tack a MATERIAL node onto the top
...@@ -413,7 +414,7 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -413,7 +414,7 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
* correlated subplans, we add MATERIAL unless the subplan's top plan * correlated subplans, we add MATERIAL unless the subplan's top plan
* node would materialize its output anyway. * node would materialize its output anyway.
*/ */
else if (node->parParam == NIL) else if (splan->parParam == NIL)
{ {
bool use_material; bool use_material;
...@@ -433,10 +434,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -433,10 +434,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
} }
/* /*
* Make node->args from parParam. * Make splan->args from parParam.
*/ */
args = NIL; args = NIL;
foreach(l, node->parParam) foreach(l, splan->parParam)
{ {
PlannerParamItem *pitem = list_nth(root->glob->paramlist, PlannerParamItem *pitem = list_nth(root->glob->paramlist,
lfirst_int(l)); lfirst_int(l));
...@@ -448,9 +449,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -448,9 +449,10 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
*/ */
args = lappend(args, copyObject(pitem->item)); args = lappend(args, copyObject(pitem->item));
} }
node->args = args; splan->args = args;
result = (Node *) node; result = (Node *) splan;
isInitPlan = false;
} }
/* /*
...@@ -460,7 +462,22 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual) ...@@ -460,7 +462,22 @@ make_subplan(PlannerInfo *root, SubLink *slink, Node *testexpr, bool isTopQual)
plan); plan);
root->glob->subrtables = lappend(root->glob->subrtables, root->glob->subrtables = lappend(root->glob->subrtables,
subroot->parse->rtable); subroot->parse->rtable);
node->plan_id = list_length(root->glob->subplans); splan->plan_id = list_length(root->glob->subplans);
if (isInitPlan)
root->init_plans = lappend(root->init_plans, splan);
/*
* A parameterless subplan (not initplan) should be prepared to handle
* REWIND efficiently. If it has direct parameters then there's no point
* since it'll be reset on each scan anyway; and if it's an initplan
* then there's no point since it won't get re-run without parameter
* changes anyway. The input of a hashed subplan doesn't need REWIND
* either.
*/
if (splan->parParam == NIL && !isInitPlan && !splan->useHashTable)
root->glob->rewindPlanIDs = bms_add_member(root->glob->rewindPlanIDs,
splan->plan_id);
return result; return result;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.138 2007/02/22 22:00:25 tgl Exp $ * $PostgreSQL: pgsql/src/include/executor/executor.h,v 1.139 2007/02/27 01:11:25 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -130,7 +130,6 @@ extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, ...@@ -130,7 +130,6 @@ extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc,
ScanDirection direction, long count); ScanDirection direction, long count);
extern void ExecutorEnd(QueryDesc *queryDesc); extern void ExecutorEnd(QueryDesc *queryDesc);
extern void ExecutorRewind(QueryDesc *queryDesc); extern void ExecutorRewind(QueryDesc *queryDesc);
extern void ExecEndPlan(PlanState *planstate, EState *estate);
extern bool ExecContextForcesOids(PlanState *planstate, bool *hasoids); extern bool ExecContextForcesOids(PlanState *planstate, bool *hasoids);
extern void ExecConstraints(ResultRelInfo *resultRelInfo, extern void ExecConstraints(ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate); TupleTableSlot *slot, EState *estate);
...@@ -167,7 +166,6 @@ extern Tuplestorestate *ExecMakeTableFunctionResult(ExprState *funcexpr, ...@@ -167,7 +166,6 @@ extern Tuplestorestate *ExecMakeTableFunctionResult(ExprState *funcexpr,
extern Datum ExecEvalExprSwitchContext(ExprState *expression, ExprContext *econtext, extern Datum ExecEvalExprSwitchContext(ExprState *expression, ExprContext *econtext,
bool *isNull, ExprDoneCond *isDone); bool *isNull, ExprDoneCond *isDone);
extern ExprState *ExecInitExpr(Expr *node, PlanState *parent); extern ExprState *ExecInitExpr(Expr *node, PlanState *parent);
extern SubPlanState *ExecInitExprInitPlan(SubPlan *node, PlanState *parent);
extern ExprState *ExecPrepareExpr(Expr *node, EState *estate); extern ExprState *ExecPrepareExpr(Expr *node, EState *estate);
extern bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull); extern bool ExecQual(List *qual, ExprContext *econtext, bool resultForNull);
extern int ExecTargetListLength(List *targetlist); extern int ExecTargetListLength(List *targetlist);
...@@ -227,7 +225,6 @@ extern void end_tup_output(TupOutputState *tstate); ...@@ -227,7 +225,6 @@ extern void end_tup_output(TupOutputState *tstate);
* prototypes from functions in execUtils.c * prototypes from functions in execUtils.c
*/ */
extern EState *CreateExecutorState(void); extern EState *CreateExecutorState(void);
extern EState *CreateSubExecutorState(EState *parent_estate);
extern void FreeExecutorState(EState *estate); extern void FreeExecutorState(EState *estate);
extern ExprContext *CreateExprContext(EState *estate); extern ExprContext *CreateExprContext(EState *estate);
extern ExprContext *CreateStandaloneExprContext(void); extern ExprContext *CreateStandaloneExprContext(void);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/executor/nodeSubplan.h,v 1.25 2007/01/05 22:19:54 momjian Exp $ * $PostgreSQL: pgsql/src/include/executor/nodeSubplan.h,v 1.26 2007/02/27 01:11:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#include "nodes/execnodes.h" #include "nodes/execnodes.h"
extern void ExecInitSubPlan(SubPlanState *node, EState *estate, int eflags); extern SubPlanState *ExecInitSubPlan(SubPlan *subplan, PlanState *parent);
extern Datum ExecSubPlan(SubPlanState *node, extern Datum ExecSubPlan(SubPlanState *node,
ExprContext *econtext, ExprContext *econtext,
bool *isNull, bool *isNull,
ExprDoneCond *isDone); ExprDoneCond *isDone);
extern void ExecEndSubPlan(SubPlanState *node);
extern void ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent); extern void ExecReScanSetParamPlan(SubPlanState *node, PlanState *parent);
extern void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext); extern void ExecSetParamPlan(SubPlanState *node, ExprContext *econtext);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.169 2007/02/22 22:00:25 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/execnodes.h,v 1.170 2007/02/27 01:11:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -328,14 +328,14 @@ typedef struct EState ...@@ -328,14 +328,14 @@ typedef struct EState
Oid es_lastoid; /* last oid processed (by INSERT) */ Oid es_lastoid; /* last oid processed (by INSERT) */
List *es_rowMarks; /* not good place, but there is no other */ List *es_rowMarks; /* not good place, but there is no other */
bool es_is_subquery; /* true if subquery (es_query_cxt not mine) */
bool es_instrument; /* true requests runtime instrumentation */ bool es_instrument; /* true requests runtime instrumentation */
bool es_select_into; /* true if doing SELECT INTO */ bool es_select_into; /* true if doing SELECT INTO */
bool es_into_oids; /* true to generate OIDs in SELECT INTO */ bool es_into_oids; /* true to generate OIDs in SELECT INTO */
List *es_exprcontexts; /* List of ExprContexts within EState */ List *es_exprcontexts; /* List of ExprContexts within EState */
List *es_subplanstates; /* List of PlanState for SubPlans */
/* /*
* this ExprContext is for per-output-tuple operations, such as constraint * this ExprContext is for per-output-tuple operations, such as constraint
* checks and index-value computations. It will be reset for each output * checks and index-value computations. It will be reset for each output
...@@ -582,11 +582,9 @@ typedef struct BoolExprState ...@@ -582,11 +582,9 @@ typedef struct BoolExprState
typedef struct SubPlanState typedef struct SubPlanState
{ {
ExprState xprstate; ExprState xprstate;
EState *sub_estate; /* subselect plan has its own EState */
struct PlanState *planstate; /* subselect plan's state tree */ struct PlanState *planstate; /* subselect plan's state tree */
ExprState *testexpr; /* state of combining expression */ ExprState *testexpr; /* state of combining expression */
List *args; /* states of argument expression(s) */ List *args; /* states of argument expression(s) */
bool needShutdown; /* TRUE = need to shutdown subplan */
HeapTuple curTuple; /* copy of most recent tuple from subplan */ HeapTuple curTuple; /* copy of most recent tuple from subplan */
/* these are used when hashing the subselect's output: */ /* these are used when hashing the subselect's output: */
ProjectionInfo *projLeft; /* for projecting lefthand exprs */ ProjectionInfo *projLeft; /* for projecting lefthand exprs */
...@@ -1060,17 +1058,13 @@ typedef struct TidScanState ...@@ -1060,17 +1058,13 @@ typedef struct TidScanState
* SubqueryScanState information * SubqueryScanState information
* *
* SubqueryScanState is used for scanning a sub-query in the range table. * SubqueryScanState is used for scanning a sub-query in the range table.
* The sub-query will have its own EState, which we save here.
* ScanTupleSlot references the current output tuple of the sub-query. * ScanTupleSlot references the current output tuple of the sub-query.
*
* SubEState exec state for sub-query
* ---------------- * ----------------
*/ */
typedef struct SubqueryScanState typedef struct SubqueryScanState
{ {
ScanState ss; /* its first field is NodeTag */ ScanState ss; /* its first field is NodeTag */
PlanState *subplan; PlanState *subplan;
EState *sss_SubEState;
} SubqueryScanState; } SubqueryScanState;
/* ---------------- /* ----------------
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.92 2007/02/22 22:00:25 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.93 2007/02/27 01:11:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -50,6 +50,8 @@ typedef struct PlannedStmt ...@@ -50,6 +50,8 @@ typedef struct PlannedStmt
List *subplans; /* Plan trees for SubPlan expressions */ List *subplans; /* Plan trees for SubPlan expressions */
Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
/* /*
* If the query has a returningList then the planner will store a list of * If the query has a returningList then the planner will store a list of
* processed targetlists (one per result relation) here. We must have a * processed targetlists (one per result relation) here. We must have a
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.138 2007/02/22 22:00:26 tgl Exp $ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.139 2007/02/27 01:11:26 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -68,6 +68,8 @@ typedef struct PlannerGlobal ...@@ -68,6 +68,8 @@ typedef struct PlannerGlobal
List *subrtables; /* Rangetables for SubPlan nodes */ List *subrtables; /* Rangetables for SubPlan nodes */
Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
List *finalrtable; /* "flat" rangetable for executor */ List *finalrtable; /* "flat" rangetable for executor */
} PlannerGlobal; } PlannerGlobal;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment