mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
of tuples when passing data up through multiple plan nodes. A slot can now hold either a normal "physical" HeapTuple, or a "virtual" tuple consisting of Datum/isnull arrays. Upper plan levels can usually just copy the Datum arrays, avoiding heap_formtuple() and possible subsequent nocachegetattr() calls to extract the data again. This work extends Atsushi Ogawa's earlier patch, which provided the key idea of adding Datum arrays to TupleTableSlots. (I believe however that something like this was foreseen way back in Berkeley days --- see the old comment on ExecProject.) A test case involving many levels of join of fairly wide tables (about 80 columns altogether) showed about 3x overall speedup, though simple queries will probably not be helped very much. I have also duplicated some code in heaptuple.c in order to provide versions of heap_formtuple and friends that use "bool" arrays to indicate null attributes, instead of the old convention of "char" arrays containing either 'n' or ' '. This provides a better match to the convention used by ExecEvalExpr. While I have not made a concerted effort to get rid of uses of the old routines, I think they should be deprecated and eventually removed.
91 lines
1.9 KiB
C
91 lines
1.9 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* tstoreReceiver.c
|
|
* an implementation of DestReceiver that stores the result tuples in
|
|
* a Tuplestore
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* IDENTIFICATION
|
|
* $PostgreSQL: pgsql/src/backend/executor/tstoreReceiver.c,v 1.14 2005/03/16 21:38:08 tgl Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
#include "executor/tstoreReceiver.h"
|
|
|
|
|
|
typedef struct
|
|
{
|
|
DestReceiver pub;
|
|
Tuplestorestate *tstore;
|
|
MemoryContext cxt;
|
|
} TStoreState;
|
|
|
|
|
|
/*
|
|
* Prepare to receive tuples from executor.
|
|
*/
|
|
static void
|
|
tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
|
|
{
|
|
/* do nothing */
|
|
}
|
|
|
|
/*
|
|
* Receive a tuple from the executor and store it in the tuplestore.
|
|
*/
|
|
static void
|
|
tstoreReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
|
|
{
|
|
TStoreState *myState = (TStoreState *) self;
|
|
MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
|
|
|
|
tuplestore_puttuple(myState->tstore, ExecFetchSlotTuple(slot));
|
|
|
|
MemoryContextSwitchTo(oldcxt);
|
|
}
|
|
|
|
/*
|
|
* Clean up at end of an executor run
|
|
*/
|
|
static void
|
|
tstoreShutdownReceiver(DestReceiver *self)
|
|
{
|
|
/* do nothing */
|
|
}
|
|
|
|
/*
|
|
* Destroy receiver when done with it
|
|
*/
|
|
static void
|
|
tstoreDestroyReceiver(DestReceiver *self)
|
|
{
|
|
pfree(self);
|
|
}
|
|
|
|
/*
|
|
* Initially create a DestReceiver object.
|
|
*/
|
|
DestReceiver *
|
|
CreateTuplestoreDestReceiver(Tuplestorestate *tStore,
|
|
MemoryContext tContext)
|
|
{
|
|
TStoreState *self = (TStoreState *) palloc(sizeof(TStoreState));
|
|
|
|
self->pub.receiveSlot = tstoreReceiveSlot;
|
|
self->pub.rStartup = tstoreStartupReceiver;
|
|
self->pub.rShutdown = tstoreShutdownReceiver;
|
|
self->pub.rDestroy = tstoreDestroyReceiver;
|
|
self->pub.mydest = Tuplestore;
|
|
|
|
self->tstore = tStore;
|
|
self->cxt = tContext;
|
|
|
|
return (DestReceiver *) self;
|
|
}
|