1 /*-------------------------------------------------------------------------
4 * an implementation of DestReceiver that stores the result tuples in
8 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
12 * $PostgreSQL: pgsql/src/backend/executor/tstoreReceiver.c,v 1.18 2007/01/05 22:19:29 momjian Exp $
14 *-------------------------------------------------------------------------
19 #include "executor/tstoreReceiver.h"
25 Tuplestorestate *tstore;
31 * Prepare to receive tuples from executor.
34 tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
40 * Receive a tuple from the executor and store it in the tuplestore.
43 tstoreReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
45 TStoreState *myState = (TStoreState *) self;
46 MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
48 tuplestore_puttupleslot(myState->tstore, slot);
50 MemoryContextSwitchTo(oldcxt);
54 * Clean up at end of an executor run
57 tstoreShutdownReceiver(DestReceiver *self)
63 * Destroy receiver when done with it
66 tstoreDestroyReceiver(DestReceiver *self)
72 * Initially create a DestReceiver object.
75 CreateTuplestoreDestReceiver(Tuplestorestate *tStore,
76 MemoryContext tContext)
78 TStoreState *self = (TStoreState *) palloc(sizeof(TStoreState));
80 self->pub.receiveSlot = tstoreReceiveSlot;
81 self->pub.rStartup = tstoreStartupReceiver;
82 self->pub.rShutdown = tstoreShutdownReceiver;
83 self->pub.rDestroy = tstoreDestroyReceiver;
84 self->pub.mydest = DestTuplestore;
86 self->tstore = tStore;
89 return (DestReceiver *) self;