]> granicus.if.org Git - postgresql/blob - src/include/nodes/plannodes.h
Allow internal sorts to be stored in memory rather than in files.
[postgresql] / src / include / nodes / plannodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * plannodes.h--
4  *    definitions for query plan nodes
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: plannodes.h,v 1.6 1997/08/06 03:42:04 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef PLANNODES_H
14 #define PLANNODES_H
15
16 #include <nodes/execnodes.h>
17
18 /* ----------------------------------------------------------------
19  *  Executor State types are used in the plannode structures
20  *  so we have to include their definitions too.
21  *
22  *      Node Type               node information used by executor
23  *
24  * control nodes
25  *
26  *      Existential             ExistentialState        exstate;
27  *      Result                  ResultState             resstate;
28  *      Append                  AppendState             unionstate;
29  *
30  * scan nodes
31  *
32  *      Scan ***                CommonScanState         scanstate;
33  *      IndexScan               IndexScanState          indxstate;
34  *
35  *        (*** nodes which inherit Scan also inherit scanstate)
36  *
37  * join nodes
38  *
39  *      NestLoop                NestLoopState           nlstate;
40  *      MergeJoin               MergeJoinState          mergestate;
41  *      HashJoin                HashJoinState           hashjoinstate;
42  *
43  * materialize nodes
44  *
45  *      Material                MaterialState           matstate;
46  *      Sort                    SortState               sortstate;
47  *      Unique                  UniqueState             uniquestate;
48  *      Hash                    HashState               hashstate;
49  *
50  * ----------------------------------------------------------------
51  */
52
53
54 /* ----------------------------------------------------------------
55  *                      node definitions
56  * ----------------------------------------------------------------
57  */
58
59 /* ----------------
60  *      Plan node
61  * ----------------
62  */
63
64 typedef struct Plan {
65     NodeTag             type;
66     Cost                cost;
67     int                 plan_size;
68     int                 plan_width;
69     int                 plan_tupperpage;
70     EState              *state;  /* at execution time, state's of individual
71                                     nodes point to one EState for the 
72                                     whole top-level plan */
73     List                *targetlist;
74     List                *qual;  /* Node* or List* ?? */
75     struct Plan         *lefttree;
76     struct Plan         *righttree;
77 } Plan;
78
79 /* ----------------
80  *  these are are defined to avoid confusion problems with "left"
81  *  and "right" and "inner" and "outer".  The convention is that
82  *  the "left" plan is the "outer" plan and the "right" plan is
83  *  the inner plan, but these make the code more readable. 
84  * ----------------
85  */
86 #define innerPlan(node)         (((Plan *)(node))->righttree)
87 #define outerPlan(node)         (((Plan *)(node))->lefttree)
88
89
90 /*
91  * ===============
92  * Top-level nodes
93  * ===============
94  */
95
96 /* all plan nodes "derive" from the Plan structure by having the
97    Plan structure as the first field.  This ensures that everything works
98    when nodes are cast to Plan's.  (node pointers are frequently cast to Plan*
99    when passed around generically in the executor */
100
101
102 /* ----------------
103  *      existential node
104  * ----------------
105  */
106 typedef Plan    Existential;
107
108 /* ----------------
109  *   result node -
110  *      returns tuples from outer plan that satisfy the qualifications
111  * ----------------
112  */
113 typedef struct Result {
114     Plan                plan;
115     Node                *resconstantqual;
116     ResultState         *resstate;
117 } Result;
118
119 /* ----------------
120  *      append node
121  * ----------------
122  */
123 typedef struct Append {
124     Plan                plan;
125     List                *unionplans;
126     Index               unionrelid;
127     List                *unionrtentries;
128     AppendState         *unionstate;
129 } Append;
130
131 /*
132  * ==========
133  * Scan nodes
134  * ==========
135  */
136 typedef struct Scan {
137     Plan                plan;
138     Index               scanrelid; /* relid is index into the range table */
139     CommonScanState     *scanstate;
140 } Scan;
141
142 /* ----------------
143  *      sequential scan node
144  * ----------------
145  */
146 typedef Scan    SeqScan;
147
148 /* ----------------
149  *      index scan node
150  * ----------------
151  */
152 typedef struct IndexScan {
153     Scan                scan;
154     List                *indxid;
155     List                *indxqual;
156     IndexScanState      *indxstate;
157 } IndexScan;
158
159 /*
160  * ==========
161  * Join nodes
162  * ==========
163  */
164
165 /* ----------------
166  *      Join node
167  * ----------------
168  */
169 typedef Plan    Join;
170
171 /* ----------------
172  *      nest loop join node
173  * ----------------
174  */
175 typedef struct NestLoop {
176     Join                join;
177     NestLoopState       *nlstate;
178 } NestLoop;
179
180 /* ----------------
181  *      merge join node
182  * ----------------
183  */
184 typedef struct MergeJoin {
185     Join                join;
186     List                *mergeclauses;
187     Oid                 mergesortop;
188     Oid                 *mergerightorder;       /* inner sort operator */
189     Oid                 *mergeleftorder;        /* outer sort operator */
190     MergeJoinState      *mergestate;
191 } MergeJoin;
192
193 /* ----------------
194  *      hash join (probe) node
195  * ----------------
196  */
197 typedef struct HashJoin {
198     Join                join;
199     List                *hashclauses;
200     Oid                 hashjoinop;
201     HashJoinState       *hashjoinstate;
202     HashJoinTable       hashjointable;
203     IpcMemoryKey        hashjointablekey;
204     int                 hashjointablesize;
205     bool                hashdone;
206 } HashJoin;
207
208 /* ---------------
209  *      aggregate node
210  * ---------------
211  */
212 typedef struct Agg {
213     Plan                plan;
214     int                 numAgg;
215     Aggreg              **aggs;
216     AggState            *aggstate;
217 } Agg;
218
219 /* ---------------
220  *   group node -
221  *      use for queries with GROUP BY specified.
222  *
223  *      If tuplePerGroup is true, one tuple (with group columns only) is
224  *      returned for each group and NULL is returned when there are no more
225  *      groups. Otherwise, all the tuples of a group are returned with a
226  *      NULL returned at the end of each group. (see nodeGroup.c for details)
227  * ---------------
228  */
229 typedef struct Group {
230     Plan                plan;
231     bool                tuplePerGroup;  /* what tuples to return (see above) */
232     int                 numCols;        /* number of group columns */
233     AttrNumber          *grpColIdx;     /* index into the target list */
234     GroupState          *grpstate;
235 } Group;
236
237 /*
238  * ==========
239  * Temp nodes
240  * ==========
241  */
242 typedef struct Temp {
243     Plan                plan;
244     Oid                 tempid;
245     int                 keycount;
246 } Temp;
247
248 /* ----------------
249  *      materialization node
250  * ----------------
251  */
252 typedef struct Material {
253     Plan                plan;           /* temp node flattened out */
254     Oid                 tempid;
255     int                 keycount;
256     MaterialState       *matstate;
257 } Material;
258
259 /* ----------------
260  *      sort node
261  * ----------------
262  */
263 typedef struct Sort {
264     Plan                plan;           /* temp node flattened out */
265     Oid                 tempid;
266     int                 keycount;
267     SortState           *sortstate;
268     void                *psortstate;
269     bool                cleaned;
270 } Sort;
271
272 /* ----------------
273  *      unique node
274  * ----------------
275  */
276 typedef struct Unique {
277     Plan                plan;           /* temp node flattened out */
278     Oid                 tempid;
279     int                 keycount;
280     char               *uniqueAttr; /* NULL if all attrs,
281                                        or unique attribute name */
282     AttrNumber          uniqueAttrNum; /* attribute number of attribute
283                                            to select distinct on */
284     UniqueState         *uniquestate;
285 } Unique;
286
287 /* ----------------
288  *      hash build node
289  * ----------------
290  */
291 typedef struct Hash {
292     Plan                plan;
293     Var                 *hashkey;
294     HashState           *hashstate;
295     HashJoinTable       hashtable;
296     IpcMemoryKey        hashtablekey;
297     int                 hashtablesize;
298 } Hash;
299
300 /* ---------------------
301  *      choose node
302  * ---------------------
303  */
304 typedef struct Choose {
305     Plan        plan;
306     List        *chooseplanlist;
307 } Choose;
308
309 /* -------------------
310  *      Tee node information
311  *
312  *    leftParent :              the left parent of this node
313  *    rightParent:              the right parent of this node  
314  * -------------------
315 */
316 typedef struct Tee {
317   Plan           plan;
318   Plan*          leftParent;
319   Plan*          rightParent;
320   TeeState       *teestate;
321   char           *teeTableName; /* the name of the table to materialize
322                                   the tee into */
323   List           *rtentries; /* the range table for the plan below the Tee
324                                 may be different than the parent plans */
325 } Tee;
326
327 #endif /* PLANNODES_H */