You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
postgres/src/backend/executor/tstoreReceiver.c

104 lines
2.2 KiB

23 years ago
/*-------------------------------------------------------------------------
*
* tstoreReceiver.c
23 years ago
* an implementation of DestReceiver that stores the result tuples in
* a Tuplestore
*
*
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
23 years ago
* 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 $
23 years ago
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "executor/tstoreReceiver.h"
23 years ago
typedef struct
{
23 years ago
DestReceiver pub;
Tuplestorestate *tstore;
MemoryContext cxt;
} TStoreState;
23 years ago
23 years ago
/*
* Prepare to receive tuples from executor.
23 years ago
*/
static void
tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
23 years ago
{
/* do nothing */
23 years ago
}
/*
* Receive a tuple from the executor and store it in the tuplestore.
*/
23 years ago
static void
tstoreReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
23 years ago
{
TStoreState *myState = (TStoreState *) self;
MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
tuplestore_puttupleslot(myState->tstore, slot);
23 years ago
MemoryContextSwitchTo(oldcxt);
}
/*
* Clean up at end of an executor run
*/
23 years ago
static void
tstoreShutdownReceiver(DestReceiver *self)
23 years ago
{
/* do nothing */
23 years ago
}
/*
* Destroy receiver when done with it
*/
static void
tstoreDestroyReceiver(DestReceiver *self)
{
pfree(self);
}
/*
* Initially create a DestReceiver object.
*/
23 years ago
DestReceiver *
CreateTuplestoreDestReceiver(void)
23 years ago
{
TStoreState *self = (TStoreState *) palloc0(sizeof(TStoreState));
23 years ago
self->pub.receiveSlot = tstoreReceiveSlot;
self->pub.rStartup = tstoreStartupReceiver;
self->pub.rShutdown = tstoreShutdownReceiver;
self->pub.rDestroy = tstoreDestroyReceiver;
self->pub.mydest = DestTuplestore;
23 years ago
/* private fields will be set by SetTuplestoreDestReceiverParams */
23 years ago
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;
}