postgresql/src/backend/executor/tstoreReceiver.c

104 lines
2.2 KiB
C
Raw Normal View History

2003-03-27 17:53:15 +01:00
/*-------------------------------------------------------------------------
*
* tstoreReceiver.c
2003-03-27 17:53:15 +01:00
* an implementation of DestReceiver that stores the result tuples in
* a Tuplestore
*
*
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
2003-03-27 17:53:15 +01:00
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/tstoreReceiver.c,v 1.20 2008/11/30 20:51:25 tgl Exp $
2003-03-27 17:53:15 +01:00
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "executor/tstoreReceiver.h"
2003-03-27 17:53:15 +01:00
typedef struct
{
2003-08-04 02:43:34 +02:00
DestReceiver pub;
Tuplestorestate *tstore;
MemoryContext cxt;
} TStoreState;
2003-03-27 17:53:15 +01:00
2003-03-27 17:53:15 +01:00
/*
* Prepare to receive tuples from executor.
2003-03-27 17:53:15 +01:00
*/
static void
tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
2003-03-27 17:53:15 +01:00
{
/* do nothing */
2003-03-27 17:53:15 +01:00
}
/*
* Receive a tuple from the executor and store it in the tuplestore.
*/
2003-03-27 17:53:15 +01:00
static void
tstoreReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
2003-03-27 17:53:15 +01:00
{
TStoreState *myState = (TStoreState *) self;
MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
tuplestore_puttupleslot(myState->tstore, slot);
2003-03-27 17:53:15 +01:00
MemoryContextSwitchTo(oldcxt);
}
/*
* Clean up at end of an executor run
*/
2003-03-27 17:53:15 +01:00
static void
tstoreShutdownReceiver(DestReceiver *self)
2003-03-27 17:53:15 +01:00
{
/* do nothing */
2003-03-27 17:53:15 +01:00
}
/*
* Destroy receiver when done with it
*/
static void
tstoreDestroyReceiver(DestReceiver *self)
{
pfree(self);
}
/*
* Initially create a DestReceiver object.
*/
2003-03-27 17:53:15 +01:00
DestReceiver *
CreateTuplestoreDestReceiver(void)
2003-03-27 17:53:15 +01:00
{
TStoreState *self = (TStoreState *) palloc0(sizeof(TStoreState));
2003-03-27 17:53:15 +01:00
self->pub.receiveSlot = tstoreReceiveSlot;
self->pub.rStartup = tstoreStartupReceiver;
self->pub.rShutdown = tstoreShutdownReceiver;
self->pub.rDestroy = tstoreDestroyReceiver;
self->pub.mydest = DestTuplestore;
2003-03-27 17:53:15 +01:00
/* private fields will be set by SetTuplestoreDestReceiverParams */
2003-03-27 17:53:15 +01:00
return (DestReceiver *) self;
}
/*
* Set parameters for a TuplestoreDestReceiver
*/
void
SetTuplestoreDestReceiverParams(DestReceiver *self,
Tuplestorestate *tStore,
MemoryContext tContext)
{
TStoreState *myState = (TStoreState *) self;
Assert(myState->pub.mydest == DestTuplestore);
myState->tstore = tStore;
myState->cxt = tContext;
}