1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

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.
This commit is contained in:
Tom Lane
2003-05-06 00:20:33 +00:00
parent 94a3c60324
commit 2cf57c8f8d
32 changed files with 454 additions and 336 deletions

View File

@ -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;
@ -118,6 +121,13 @@ ExecutorStart(QueryDesc *queryDesc)
Assert(queryDesc != NULL);
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.
*/
@ -149,7 +159,7 @@ ExecutorStart(QueryDesc *queryDesc)
/*
* Initialize the plan state tree
*/
InitPlan(queryDesc);
InitPlan(queryDesc, explainOnly);
MemoryContextSwitchTo(oldcontext);
}
@ -202,14 +212,6 @@ ExecutorRun(QueryDesc *queryDesc,
operation = queryDesc->operation;
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
*/
@ -217,8 +219,10 @@ ExecutorRun(QueryDesc *queryDesc,
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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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.
*/

View File

@ -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);

View File

@ -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;