OSDN Git Service

pgindent run for 8.3.
[pg-rex/syncrep.git] / src / backend / executor / tstoreReceiver.c
1 /*-------------------------------------------------------------------------
2  *
3  * tstoreReceiver.c
4  *        an implementation of DestReceiver that stores the result tuples in
5  *        a Tuplestore
6  *
7  *
8  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * IDENTIFICATION
12  *        $PostgreSQL: pgsql/src/backend/executor/tstoreReceiver.c,v 1.18 2007/01/05 22:19:29 momjian Exp $
13  *
14  *-------------------------------------------------------------------------
15  */
16
17 #include "postgres.h"
18
19 #include "executor/tstoreReceiver.h"
20
21
22 typedef struct
23 {
24         DestReceiver pub;
25         Tuplestorestate *tstore;
26         MemoryContext cxt;
27 } TStoreState;
28
29
30 /*
31  * Prepare to receive tuples from executor.
32  */
33 static void
34 tstoreStartupReceiver(DestReceiver *self, int operation, TupleDesc typeinfo)
35 {
36         /* do nothing */
37 }
38
39 /*
40  * Receive a tuple from the executor and store it in the tuplestore.
41  */
42 static void
43 tstoreReceiveSlot(TupleTableSlot *slot, DestReceiver *self)
44 {
45         TStoreState *myState = (TStoreState *) self;
46         MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
47
48         tuplestore_puttupleslot(myState->tstore, slot);
49
50         MemoryContextSwitchTo(oldcxt);
51 }
52
53 /*
54  * Clean up at end of an executor run
55  */
56 static void
57 tstoreShutdownReceiver(DestReceiver *self)
58 {
59         /* do nothing */
60 }
61
62 /*
63  * Destroy receiver when done with it
64  */
65 static void
66 tstoreDestroyReceiver(DestReceiver *self)
67 {
68         pfree(self);
69 }
70
71 /*
72  * Initially create a DestReceiver object.
73  */
74 DestReceiver *
75 CreateTuplestoreDestReceiver(Tuplestorestate *tStore,
76                                                          MemoryContext tContext)
77 {
78         TStoreState *self = (TStoreState *) palloc(sizeof(TStoreState));
79
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;
85
86         self->tstore = tStore;
87         self->cxt = tContext;
88
89         return (DestReceiver *) self;
90 }