postgresql/src/backend/executor/tstoreReceiver.c

91 lines
1.9 KiB
C
Raw Normal View History

2003-03-27 11:53:15 -05:00
/*-------------------------------------------------------------------------
*
* tstoreReceiver.c
2003-03-27 11:53:15 -05: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 11:53:15 -05:00
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/tstoreReceiver.c,v 1.19 2008/01/01 19:45:49 momjian Exp $
2003-03-27 11:53:15 -05:00
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "executor/tstoreReceiver.h"
2003-03-27 11:53:15 -05:00
typedef struct
{
2003-08-03 20:43:34 -04:00
DestReceiver pub;
Tuplestorestate *tstore;
MemoryContext cxt;
} TStoreState;
2003-03-27 11:53:15 -05:00
2003-03-27 11:53:15 -05:00
/*
* Prepare to receive tuples from executor.
2003-03-27 11:53:15 -05:00
*/
static void
tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
2003-03-27 11:53:15 -05:00
{
/* do nothing */
2003-03-27 11:53:15 -05:00
}
/*
* Receive a tuple from the executor and store it in the tuplestore.
*/
2003-03-27 11:53:15 -05:00
static void
tstoreReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
2003-03-27 11:53:15 -05:00
{
TStoreState *myState = (TStoreState *) self;
MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
tuplestore_puttupleslot(myState->tstore, slot);
2003-03-27 11:53:15 -05:00
MemoryContextSwitchTo(oldcxt);
}
/*
* Clean up at end of an executor run
*/
2003-03-27 11:53:15 -05:00
static void
tstoreShutdownReceiver(DestReceiver *self)
2003-03-27 11:53:15 -05:00
{
/* do nothing */
2003-03-27 11:53:15 -05:00
}
/*
* Destroy receiver when done with it
*/
static void
tstoreDestroyReceiver(DestReceiver *self)
{
pfree(self);
}
/*
* Initially create a DestReceiver object.
*/
2003-03-27 11:53:15 -05:00
DestReceiver *
CreateTuplestoreDestReceiver(Tuplestorestate *tStore,
MemoryContext tContext)
2003-03-27 11:53:15 -05:00
{
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 = DestTuplestore;
2003-03-27 11:53:15 -05:00
self->tstore = tStore;
self->cxt = tContext;
2003-03-27 11:53:15 -05:00
return (DestReceiver *) self;
}