diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2003-05-06 00:20:33 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2003-05-06 00:20:33 +0000 |
commit | 2cf57c8f8d060711c1ad7e1dd6cc1115a2839b47 (patch) | |
tree | b3b2a9616d425072d26cfc57efcbe676c56b399e /src/backend/executor | |
parent | 94a3c60324465f98850b60f548c1ea481ab4e52f (diff) |
Implement feature of new FE/BE protocol whereby RowDescription identifies
the column by table OID and column number, if it's a simple column
reference. Along the way, get rid of reskey/reskeyop fields in Resdoms.
Turns out that representation was not convenient for either the planner
or the executor; we can make the planner deliver exactly what the
executor wants with no more effort.
initdb forced due to change in stored rule representation.
Diffstat (limited to 'src/backend/executor')
-rw-r--r-- | src/backend/executor/execMain.c | 38 | ||||
-rw-r--r-- | src/backend/executor/execTuples.c | 4 | ||||
-rw-r--r-- | src/backend/executor/functions.c | 4 | ||||
-rw-r--r-- | src/backend/executor/nodeSort.c | 68 | ||||
-rw-r--r-- | src/backend/executor/spi.c | 6 | ||||
-rw-r--r-- | src/backend/executor/tstoreReceiver.c | 5 |
6 files changed, 37 insertions, 88 deletions
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index d70b3379217..719c9456562 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.206 2003/05/05 17:57:47 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.207 2003/05/06 00:20:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -63,7 +63,7 @@ typedef struct evalPlanQual } evalPlanQual; /* decls for local routines only used within this module */ -static void InitPlan(QueryDesc *queryDesc); +static void InitPlan(QueryDesc *queryDesc, bool explainOnly); static void initResultRelInfo(ResultRelInfo *resultRelInfo, Index resultRelationIndex, List *rangeTable, @@ -104,12 +104,15 @@ static void EvalPlanQualStop(evalPlanQual *epq); * field of the QueryDesc is filled in to describe the tuples that will be * returned, and the internal fields (estate and planstate) are set up. * + * If explainOnly is true, we are not actually intending to run the plan, + * only to set up for EXPLAIN; so skip unwanted side-effects. + * * NB: the CurrentMemoryContext when this is called will become the parent * of the per-query context used for this Executor invocation. * ---------------------------------------------------------------- */ void -ExecutorStart(QueryDesc *queryDesc) +ExecutorStart(QueryDesc *queryDesc, bool explainOnly) { EState *estate; MemoryContext oldcontext; @@ -119,6 +122,13 @@ ExecutorStart(QueryDesc *queryDesc) Assert(queryDesc->estate == NULL); /* + * If the transaction is read-only, we need to check if any writes + * are planned to non-temporary tables. + */ + if (!explainOnly) + ExecCheckXactReadOnly(queryDesc->parsetree, queryDesc->operation); + + /* * Build EState, switch into per-query memory context for startup. */ estate = CreateExecutorState(); @@ -149,7 +159,7 @@ ExecutorStart(QueryDesc *queryDesc) /* * Initialize the plan state tree */ - InitPlan(queryDesc); + InitPlan(queryDesc, explainOnly); MemoryContextSwitchTo(oldcontext); } @@ -203,22 +213,16 @@ ExecutorRun(QueryDesc *queryDesc, dest = queryDesc->dest; /* - * If the transaction is read-only, we need to check if any writes - * are planned to non-temporary tables. This is done here at this - * rather late stage so that we can handle EXPLAIN vs. EXPLAIN - * ANALYZE easily. - */ - ExecCheckXactReadOnly(queryDesc->parsetree, operation); - - /* * startup tuple receiver */ estate->es_processed = 0; estate->es_lastoid = InvalidOid; destfunc = DestToFunction(dest); - (*destfunc->setup) (destfunc, operation, queryDesc->portalName, - queryDesc->tupDesc); + (*destfunc->setup) (destfunc, operation, + queryDesc->portalName, + queryDesc->tupDesc, + queryDesc->planstate->plan->targetlist); /* * run plan @@ -468,7 +472,7 @@ fail: * ---------------------------------------------------------------- */ static void -InitPlan(QueryDesc *queryDesc) +InitPlan(QueryDesc *queryDesc, bool explainOnly) { CmdType operation = queryDesc->operation; Query *parseTree = queryDesc->parsetree; @@ -751,10 +755,12 @@ InitPlan(QueryDesc *queryDesc) * If doing SELECT INTO, initialize the "into" relation. We must wait * till now so we have the "clean" result tuple type to create the * new table from. + * + * If EXPLAIN, skip creating the "into" relation. */ intoRelationDesc = (Relation) NULL; - if (do_select_into) + if (do_select_into && !explainOnly) { char *intoName; Oid namespaceId; diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c index 2e7291a006d..c81dd33d36a 100644 --- a/src/backend/executor/execTuples.c +++ b/src/backend/executor/execTuples.c @@ -15,7 +15,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.63 2002/12/13 19:45:52 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/execTuples.c,v 1.64 2003/05/06 00:20:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -723,7 +723,7 @@ begin_tup_output_tupdesc(CommandDest dest, TupleDesc tupdesc) tstate->destfunc = DestToFunction(dest); (*tstate->destfunc->setup) (tstate->destfunc, (int) CMD_SELECT, - NULL, tupdesc); + NULL, tupdesc, NIL); return tstate; } diff --git a/src/backend/executor/functions.c b/src/backend/executor/functions.c index d3ccf0dd905..ba41828be34 100644 --- a/src/backend/executor/functions.c +++ b/src/backend/executor/functions.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.62 2002/12/15 16:17:46 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.63 2003/05/06 00:20:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -250,7 +250,7 @@ postquel_start(execution_state *es, SQLFunctionCachePtr fcache) /* Utility commands don't need Executor. */ if (es->qd->operation != CMD_UTILITY) - ExecutorStart(es->qd); + ExecutorStart(es->qd, false); es->status = F_EXEC_RUN; } diff --git a/src/backend/executor/nodeSort.c b/src/backend/executor/nodeSort.c index 2be31ce09e8..468b91af9bb 100644 --- a/src/backend/executor/nodeSort.c +++ b/src/backend/executor/nodeSort.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.43 2003/05/05 17:57:47 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/nodeSort.c,v 1.44 2003/05/06 00:20:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -19,59 +19,6 @@ #include "executor/nodeSort.h" #include "utils/tuplesort.h" -/* ---------------------------------------------------------------- - * ExtractSortKeys - * - * Extract the sorting key information from the plan node. - * - * Returns two palloc'd arrays, one of sort operator OIDs and - * one of attribute numbers. - * ---------------------------------------------------------------- - */ -static void -ExtractSortKeys(Sort *sortnode, - Oid **sortOperators, - AttrNumber **attNums) -{ - List *targetList; - int keycount; - Oid *sortOps; - AttrNumber *attNos; - List *tl; - - /* - * get information from the node - */ - targetList = sortnode->plan.targetlist; - keycount = sortnode->keycount; - - /* - * first allocate space for results - */ - if (keycount <= 0) - elog(ERROR, "ExtractSortKeys: keycount <= 0"); - sortOps = (Oid *) palloc0(keycount * sizeof(Oid)); - *sortOperators = sortOps; - attNos = (AttrNumber *) palloc0(keycount * sizeof(AttrNumber)); - *attNums = attNos; - - /* - * extract info from the resdom nodes in the target list - */ - foreach(tl, targetList) - { - TargetEntry *target = (TargetEntry *) lfirst(tl); - Resdom *resdom = target->resdom; - Index reskey = resdom->reskey; - - if (reskey > 0) /* ignore TLEs that are not sort keys */ - { - Assert(reskey <= keycount); - sortOps[reskey - 1] = resdom->reskeyop; - attNos[reskey - 1] = resdom->resno; - } - } -} /* ---------------------------------------------------------------- * ExecSort @@ -118,8 +65,6 @@ ExecSort(SortState *node) Sort *plannode = (Sort *) node->ss.ps.plan; PlanState *outerNode; TupleDesc tupDesc; - Oid *sortOperators; - AttrNumber *attNums; SO1_printf("ExecSort: %s\n", "sorting subplan"); @@ -139,16 +84,13 @@ ExecSort(SortState *node) outerNode = outerPlanState(node); tupDesc = ExecGetResultType(outerNode); - ExtractSortKeys(plannode, &sortOperators, &attNums); - - tuplesortstate = tuplesort_begin_heap(tupDesc, plannode->keycount, - sortOperators, attNums, + tuplesortstate = tuplesort_begin_heap(tupDesc, + plannode->numCols, + plannode->sortOperators, + plannode->sortColIdx, true /* randomAccess */ ); node->tuplesortstate = (void *) tuplesortstate; - pfree(sortOperators); - pfree(attNums); - /* * Scan the subplan and feed all the tuples to tuplesort. */ diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 3b1e6c4bb3f..74299ddf3ea 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.94 2003/05/02 20:54:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.95 2003/05/06 00:20:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -880,7 +880,7 @@ SPI_cursor_close(Portal portal) */ void spi_dest_setup(DestReceiver *self, int operation, - const char *portalName, TupleDesc typeinfo) + const char *portalName, TupleDesc typeinfo, List *targetlist) { SPITupleTable *tuptable; MemoryContext oldcxt; @@ -1209,7 +1209,7 @@ _SPI_pquery(QueryDesc *queryDesc, bool runit, int tcount) ResetUsage(); #endif - ExecutorStart(queryDesc); + ExecutorStart(queryDesc, false); ExecutorRun(queryDesc, ForwardScanDirection, (long) tcount); diff --git a/src/backend/executor/tstoreReceiver.c b/src/backend/executor/tstoreReceiver.c index c4d16ef5e98..05b0c1f2397 100644 --- a/src/backend/executor/tstoreReceiver.c +++ b/src/backend/executor/tstoreReceiver.c @@ -9,7 +9,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/executor/tstoreReceiver.c,v 1.3 2003/05/02 20:54:34 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/executor/tstoreReceiver.c,v 1.4 2003/05/06 00:20:31 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -40,7 +40,8 @@ typedef struct */ static void tstoreSetupReceiver(DestReceiver *self, int operation, - const char *portalname, TupleDesc typeinfo) + const char *portalname, + TupleDesc typeinfo, List *targetlist) { TStoreState *myState = (TStoreState *) self; |