]> granicus.if.org Git - postgresql/blob - src/include/utils/tuplestore.h
62279344144aaa6799f85e6ac35ed7d86fc08ff9
[postgresql] / src / include / utils / tuplestore.h
1 /*-------------------------------------------------------------------------
2  *
3  * tuplestore.h
4  *        Generalized routines for temporary tuple storage.
5  *
6  * This module handles temporary storage of tuples for purposes such
7  * as Materialize nodes, hashjoin batch files, etc.  It is essentially
8  * a dumbed-down version of tuplesort.c; it does no sorting of tuples
9  * but can only store and regurgitate a sequence of tuples.  However,
10  * because no sort is required, it is allowed to start reading the sequence
11  * before it has all been written.      This is particularly useful for cursors,
12  * because it allows random access within the already-scanned portion of
13  * a query without having to process the underlying scan to completion.
14  * A temporary file is used to handle the data if it exceeds the
15  * space limit specified by the caller.
16  *
17  * Beginning in Postgres 8.2, what is stored is just MinimalTuples;
18  * callers cannot expect valid system columns in regurgitated tuples.
19  * Also, we have changed the API to return tuples in TupleTableSlots,
20  * so that there is a check to prevent attempted access to system columns.
21  *
22  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
23  * Portions Copyright (c) 1994, Regents of the University of California
24  *
25  * $PostgreSQL: pgsql/src/include/utils/tuplestore.h,v 1.18 2006/06/27 02:51:40 tgl Exp $
26  *
27  *-------------------------------------------------------------------------
28  */
29 #ifndef TUPLESTORE_H
30 #define TUPLESTORE_H
31
32 #include "executor/tuptable.h"
33
34
35 /* Tuplestorestate is an opaque type whose details are not known outside
36  * tuplestore.c.
37  */
38 typedef struct Tuplestorestate Tuplestorestate;
39
40 /*
41  * Currently we only need to store MinimalTuples, but it would be easy
42  * to support the same behavior for IndexTuples and/or bare Datums.
43  */
44
45 extern Tuplestorestate *tuplestore_begin_heap(bool randomAccess,
46                                           bool interXact,
47                                           int maxKBytes);
48
49 extern void tuplestore_puttupleslot(Tuplestorestate *state,
50                                                                         TupleTableSlot *slot);
51 extern void tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple);
52
53 /* tuplestore_donestoring() used to be required, but is no longer used */
54 #define tuplestore_donestoring(state)   ((void) 0)
55
56 /* backwards scan is only allowed if randomAccess was specified 'true' */
57 extern bool tuplestore_gettupleslot(Tuplestorestate *state, bool forward,
58                                                                         TupleTableSlot *slot);
59 extern bool tuplestore_advance(Tuplestorestate *state, bool forward);
60
61 extern void tuplestore_end(Tuplestorestate *state);
62
63 extern bool tuplestore_ateof(Tuplestorestate *state);
64
65 extern void tuplestore_rescan(Tuplestorestate *state);
66 extern void tuplestore_markpos(Tuplestorestate *state);
67 extern void tuplestore_restorepos(Tuplestorestate *state);
68
69 #endif   /* TUPLESTORE_H */