~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/executor/tstoreReceiver.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2005, 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.13 2004-12-31 21:59:45 pgsql 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
tstoreReceiveTuple(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
 
44
{
 
45
        TStoreState *myState = (TStoreState *) self;
 
46
        MemoryContext oldcxt = MemoryContextSwitchTo(myState->cxt);
 
47
 
 
48
        tuplestore_puttuple(myState->tstore, tuple);
 
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.receiveTuple = tstoreReceiveTuple;
 
81
        self->pub.rStartup = tstoreStartupReceiver;
 
82
        self->pub.rShutdown = tstoreShutdownReceiver;
 
83
        self->pub.rDestroy = tstoreDestroyReceiver;
 
84
        self->pub.mydest = Tuplestore;
 
85
 
 
86
        self->tstore = tStore;
 
87
        self->cxt = tContext;
 
88
 
 
89
        return (DestReceiver *) self;
 
90
}