1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +03:00

Restructure command destination handling so that we pass around

DestReceiver pointers instead of just CommandDest values.  The DestReceiver
is made at the point where the destination is selected, rather than
deep inside the executor.  This cleans up the original kluge implementation
of tstoreReceiver.c, and makes it easy to support retrieving results
from utility statements inside portals.  Thus, you can now do fun things
like Bind and Execute a FETCH or EXPLAIN command, and it'll all work
as expected (e.g., you can Describe the portal, or use Execute's count
parameter to suspend the output partway through).  Implementation involves
stuffing the utility command's output into a Tuplestore, which would be
kind of annoying for huge output sets, but should be quite acceptable
for typical uses of utility commands.
This commit is contained in:
Tom Lane
2003-05-06 20:26:28 +00:00
parent 299fbb4b37
commit 79913910d4
28 changed files with 698 additions and 349 deletions

View File

@ -26,7 +26,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.207 2003/05/06 00:20:31 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.208 2003/05/06 20:26:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -72,9 +72,9 @@ static TupleTableSlot *ExecutePlan(EState *estate, PlanState *planstate,
CmdType operation,
long numberTuples,
ScanDirection direction,
DestReceiver *destfunc);
DestReceiver *dest);
static void ExecSelect(TupleTableSlot *slot,
DestReceiver *destfunc,
DestReceiver *dest,
EState *estate);
static void ExecInsert(TupleTableSlot *slot, ItemPointer tupleid,
EState *estate);
@ -188,8 +188,7 @@ ExecutorRun(QueryDesc *queryDesc,
{
EState *estate;
CmdType operation;
CommandDest dest;
DestReceiver *destfunc;
DestReceiver *dest;
TupleTableSlot *result;
MemoryContext oldcontext;
@ -218,11 +217,10 @@ ExecutorRun(QueryDesc *queryDesc,
estate->es_processed = 0;
estate->es_lastoid = InvalidOid;
destfunc = DestToFunction(dest);
(*destfunc->setup) (destfunc, operation,
queryDesc->portalName,
queryDesc->tupDesc,
queryDesc->planstate->plan->targetlist);
(*dest->startup) (dest, operation,
queryDesc->portalName,
queryDesc->tupDesc,
queryDesc->planstate->plan->targetlist);
/*
* run plan
@ -235,12 +233,12 @@ ExecutorRun(QueryDesc *queryDesc,
operation,
count,
direction,
destfunc);
dest);
/*
* shutdown receiver
*/
(*destfunc->cleanup) (destfunc);
(*dest->shutdown) (dest);
MemoryContextSwitchTo(oldcontext);
@ -962,7 +960,7 @@ ExecutePlan(EState *estate,
CmdType operation,
long numberTuples,
ScanDirection direction,
DestReceiver *destfunc)
DestReceiver *dest)
{
JunkFilter *junkfilter;
TupleTableSlot *slot;
@ -1162,8 +1160,7 @@ lnext: ;
{
case CMD_SELECT:
ExecSelect(slot, /* slot containing tuple */
destfunc, /* destination's tuple-receiver
* obj */
dest, /* destination's tuple-receiver obj */
estate);
result = slot;
break;
@ -1237,7 +1234,7 @@ lnext: ;
*/
static void
ExecSelect(TupleTableSlot *slot,
DestReceiver *destfunc,
DestReceiver *dest,
EState *estate)
{
HeapTuple tuple;
@ -1251,6 +1248,8 @@ ExecSelect(TupleTableSlot *slot,
/*
* insert the tuple into the "into relation"
*
* XXX this probably ought to be replaced by a separate destination
*/
if (estate->es_into_relation_descriptor != NULL)
{
@ -1260,9 +1259,9 @@ ExecSelect(TupleTableSlot *slot,
}
/*
* send the tuple to the front end (or the screen)
* send the tuple to the destination
*/
(*destfunc->receiveTuple) (tuple, attrtype, destfunc);
(*dest->receiveTuple) (tuple, attrtype, dest);
IncrRetrieved();
(estate->es_processed)++;
}