2003-03-27 17:53:15 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
2003-05-06 22:26:28 +02:00
|
|
|
* tstoreReceiver.c
|
2003-03-27 17:53:15 +01:00
|
|
|
* an implementation of DestReceiver that stores the result tuples in
|
|
|
|
* a Tuplestore
|
|
|
|
*
|
|
|
|
*
|
2008-01-01 20:46:01 +01:00
|
|
|
* 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
|
2008-11-30 21:51:25 +01:00
|
|
|
* $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-05-06 22:26:28 +02:00
|
|
|
|
2003-03-27 17:53:15 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2003-08-04 02:43:34 +02:00
|
|
|
DestReceiver pub;
|
|
|
|
Tuplestorestate *tstore;
|
|
|
|
MemoryContext cxt;
|
2003-08-08 23:42:59 +02:00
|
|
|
} TStoreState;
|
2003-03-27 17:53:15 +01:00
|
|
|
|
2003-04-29 05:21:30 +02:00
|
|
|
|
2003-03-27 17:53:15 +01:00
|
|
|
/*
|
2003-04-29 05:21:30 +02:00
|
|
|
* Prepare to receive tuples from executor.
|
2003-03-27 17:53:15 +01:00
|
|
|
*/
|
|
|
|
static void
|
2003-05-08 20:16:37 +02:00
|
|
|
tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
|
2003-03-27 17:53:15 +01:00
|
|
|
{
|
2003-05-06 22:26:28 +02:00
|
|
|
/* do nothing */
|
2003-03-27 17:53:15 +01:00
|
|
|
}
|
|
|
|
|
2003-04-29 05:21:30 +02:00
|
|
|
/*
|
|
|
|
* Receive a tuple from the executor and store it in the tuplestore.
|
|
|
|
*/
|
2003-03-27 17:53:15 +01:00
|
|
|
static void
|
2005-03-16 22:38:10 +01:00
|
|
|
tstoreReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
|
2003-03-27 17:53:15 +01:00
|
|
|
{
|
|
|
|
TStoreState *myState = (TStoreState *) self;
|
|
|
|
MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
|
|
|
|
|
2006-06-27 04:51:40 +02:00
|
|
|
tuplestore_puttupleslot(myState->tstore, slot);
|
2003-03-27 17:53:15 +01:00
|
|
|
|
|
|
|
MemoryContextSwitchTo(oldcxt);
|
|
|
|
}
|
|
|
|
|
2003-04-29 05:21:30 +02:00
|
|
|
/*
|
2003-05-06 22:26:28 +02:00
|
|
|
* Clean up at end of an executor run
|
2003-04-29 05:21:30 +02:00
|
|
|
*/
|
2003-03-27 17:53:15 +01:00
|
|
|
static void
|
2003-05-06 22:26:28 +02:00
|
|
|
tstoreShutdownReceiver(DestReceiver *self)
|
2003-03-27 17:53:15 +01:00
|
|
|
{
|
2003-04-29 05:21:30 +02:00
|
|
|
/* do nothing */
|
2003-03-27 17:53:15 +01:00
|
|
|
}
|
|
|
|
|
2003-05-06 22:26:28 +02:00
|
|
|
/*
|
|
|
|
* Destroy receiver when done with it
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
tstoreDestroyReceiver(DestReceiver *self)
|
|
|
|
{
|
|
|
|
pfree(self);
|
|
|
|
}
|
|
|
|
|
2003-04-29 05:21:30 +02:00
|
|
|
/*
|
|
|
|
* Initially create a DestReceiver object.
|
|
|
|
*/
|
2003-03-27 17:53:15 +01:00
|
|
|
DestReceiver *
|
2008-11-30 21:51:25 +01:00
|
|
|
CreateTuplestoreDestReceiver(void)
|
2003-03-27 17:53:15 +01:00
|
|
|
{
|
2008-11-30 21:51:25 +01:00
|
|
|
TStoreState *self = (TStoreState *) palloc0(sizeof(TStoreState));
|
2003-03-27 17:53:15 +01:00
|
|
|
|
2005-03-16 22:38:10 +01:00
|
|
|
self->pub.receiveSlot = tstoreReceiveSlot;
|
2003-08-06 19:46:46 +02:00
|
|
|
self->pub.rStartup = tstoreStartupReceiver;
|
|
|
|
self->pub.rShutdown = tstoreShutdownReceiver;
|
|
|
|
self->pub.rDestroy = tstoreDestroyReceiver;
|
2005-11-03 18:11:40 +01:00
|
|
|
self->pub.mydest = DestTuplestore;
|
2003-03-27 17:53:15 +01:00
|
|
|
|
2008-11-30 21:51:25 +01:00
|
|
|
/* private fields will be set by SetTuplestoreDestReceiverParams */
|
2003-03-27 17:53:15 +01:00
|
|
|
|
|
|
|
return (DestReceiver *) self;
|
|
|
|
}
|
2008-11-30 21:51:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|