]> granicus.if.org Git - postgresql/blob - src/include/nodes/plannodes.h
Remove unused Choose node.
[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.20 1999/01/23 23:28:09 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  *              Result                                  ResultState                             resstate;
27  *              Append                                  AppendState                             appendstate;
28  *
29  * scan nodes
30  *
31  *              Scan ***                                CommonScanState                 scanstate;
32  *              IndexScan                               IndexScanState                  indxstate;
33  *
34  *                (*** nodes which inherit Scan also inherit scanstate)
35  *
36  * join nodes
37  *
38  *              NestLoop                                NestLoopState                   nlstate;
39  *              MergeJoin                               MergeJoinState                  mergestate;
40  *              HashJoin                                HashJoinState                   hashjoinstate;
41  *
42  * materialize nodes
43  *
44  *              Material                                MaterialState                   matstate;
45  *              Sort                                    SortState                               sortstate;
46  *              Unique                                  UniqueState                             uniquestate;
47  *              Hash                                    HashState                               hashstate;
48  *
49  * ----------------------------------------------------------------
50  */
51
52
53 /* ----------------------------------------------------------------
54  *                                              node definitions
55  * ----------------------------------------------------------------
56  */
57
58 /* ----------------
59  *              Plan node
60  * ----------------
61  */
62
63 typedef struct Plan
64 {
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
71                                                                  * individual nodes point to one EState
72                                                                  * for the whole top-level plan */
73         List       *targetlist;
74         List       *qual;                       /* Node* or List* ?? */
75         struct Plan *lefttree;
76         struct Plan *righttree;
77         List       *extParam;           /* indices of _all_ _external_ PARAM_EXEC
78                                                                  * for this plan in global
79                                                                  * es_param_exec_vals. Params from
80                                                                  * setParam from initPlan-s are not
81                                                                  * included, but their execParam-s are
82                                                                  * here!!! */
83         List       *locParam;           /* someones from setParam-s */
84         List       *chgParam;           /* list of changed ones from the above */
85         List       *initPlan;           /* Init Plan nodes (un-correlated expr
86                                                                  * subselects) */
87         List       *subPlan;            /* Other SubPlan nodes */
88
89         /*
90          * We really need in some TopPlan node to store range table and
91          * resultRelation from Query there and get rid of Query itself from
92          * Executor. Some other stuff like below could be put there, too.
93          */
94         int                     nParamExec;             /* Number of them in entire query. This is
95                                                                  * to get Executor know about how many
96                                                                  * param_exec there are in query plan. */
97 } Plan;
98
99 /* ----------------
100  *      these are are defined to avoid confusion problems with "left"
101  *      and "right" and "inner" and "outer".  The convention is that
102  *      the "left" plan is the "outer" plan and the "right" plan is
103  *      the inner plan, but these make the code more readable.
104  * ----------------
105  */
106 #define innerPlan(node)                 (((Plan *)(node))->righttree)
107 #define outerPlan(node)                 (((Plan *)(node))->lefttree)
108
109
110 /*
111  * ===============
112  * Top-level nodes
113  * ===============
114  */
115
116 /* all plan nodes "derive" from the Plan structure by having the
117    Plan structure as the first field.  This ensures that everything works
118    when nodes are cast to Plan's.  (node pointers are frequently cast to Plan*
119    when passed around generically in the executor */
120
121
122 /* ----------------
123  *       result node -
124  *              returns tuples from outer plan that satisfy the qualifications
125  * ----------------
126  */
127 typedef struct Result
128 {
129         Plan            plan;
130         Node       *resconstantqual;
131         ResultState *resstate;
132 } Result;
133
134 /* ----------------
135  *              append node
136  * ----------------
137  */
138 typedef struct Append
139 {
140         Plan            plan;
141         List       *appendplans;
142         List       *unionrtables;       /* List of range tables, one for each
143                                                                  * union query. */
144         Index           inheritrelid;   /* The range table has to be changed for
145                                                                  * inheritance. */
146         List       *inheritrtable;
147         AppendState *appendstate;
148 } Append;
149
150 /*
151  * ==========
152  * Scan nodes
153  * ==========
154  */
155 typedef struct Scan
156 {
157         Plan            plan;
158         Index           scanrelid;              /* relid is index into the range table */
159         CommonScanState *scanstate;
160 } Scan;
161
162 /* ----------------
163  *              sequential scan node
164  * ----------------
165  */
166 typedef Scan SeqScan;
167
168 /* ----------------
169  *              index scan node
170  * ----------------
171  */
172 typedef struct IndexScan
173 {
174         Scan            scan;
175         List       *indxid;
176         List       *indxqual;
177         List       *indxqualorig;
178         IndexScanState *indxstate;
179 } IndexScan;
180
181 /*
182  * ==========
183  * Join nodes
184  * ==========
185  */
186
187 /* ----------------
188  *              Join node
189  * ----------------
190  */
191 typedef Plan Join;
192
193 /* ----------------
194  *              nest loop join node
195  * ----------------
196  */
197 typedef struct NestLoop
198 {
199         Join            join;
200         NestLoopState *nlstate;
201 } NestLoop;
202
203 /* ----------------
204  *              merge join node
205  * ----------------
206  */
207 typedef struct MergeJoin
208 {
209         Join            join;
210         List       *mergeclauses;
211         Oid                     mergejoinop;
212         Oid                *mergerightorder;/* inner sort operator */
213         Oid                *mergeleftorder; /* outer sort operator */
214         MergeJoinState *mergestate;
215 } MergeJoin;
216
217 /* ----------------
218  *              hash join (probe) node
219  * ----------------
220  */
221 typedef struct HashJoin
222 {
223         Join            join;
224         List       *hashclauses;
225         Oid                     hashjoinop;
226         HashJoinState *hashjoinstate;
227         HashJoinTable hashjointable;
228         IpcMemoryKey hashjointablekey;
229         int                     hashjointablesize;
230         bool            hashdone;
231 } HashJoin;
232
233 /* ---------------
234  *              aggregate node
235  * ---------------
236  */
237 typedef struct Agg
238 {
239         Plan            plan;
240         List       *aggs;
241         AggState   *aggstate;
242 } Agg;
243
244 /* ---------------
245  *       group node -
246  *              use for queries with GROUP BY specified.
247  *
248  *              If tuplePerGroup is true, one tuple (with group columns only) is
249  *              returned for each group and NULL is returned when there are no more
250  *              groups. Otherwise, all the tuples of a group are returned with a
251  *              NULL returned at the end of each group. (see nodeGroup.c for details)
252  * ---------------
253  */
254 typedef struct Group
255 {
256         Plan            plan;
257         bool            tuplePerGroup;  /* what tuples to return (see above) */
258         int                     numCols;                /* number of group columns */
259         AttrNumber *grpColIdx;          /* index into the target list */
260         GroupState *grpstate;
261 } Group;
262
263 /*
264  * ==========
265  * Temp nodes
266  * ==========
267  */
268 typedef struct Temp
269 {
270         Plan            plan;
271         Oid                     tempid;
272         int                     keycount;
273 } Temp;
274
275 /* ----------------
276  *              materialization node
277  * ----------------
278  */
279 typedef struct Material
280 {
281         Plan            plan;                   /* temp node flattened out */
282         Oid                     tempid;
283         int                     keycount;
284         MaterialState *matstate;
285 } Material;
286
287 /* ----------------
288  *              sort node
289  * ----------------
290  */
291 typedef struct Sort
292 {
293         Plan            plan;                   /* temp node flattened out */
294         Oid                     tempid;
295         int                     keycount;
296         SortState  *sortstate;
297         void       *psortstate;
298         bool            cleaned;
299 } Sort;
300
301 /* ----------------
302  *              unique node
303  * ----------------
304  */
305 typedef struct Unique
306 {
307         Plan            plan;                   /* temp node flattened out */
308         Oid                     tempid;
309         int                     keycount;
310         char       *uniqueAttr;         /* NULL if all attrs, or unique attribute
311                                                                  * name */
312         AttrNumber      uniqueAttrNum;  /* attribute number of attribute to select
313                                                                  * distinct on */
314         UniqueState *uniquestate;
315 } Unique;
316
317 /* ----------------
318  *              hash build node
319  * ----------------
320  */
321 typedef struct Hash
322 {
323         Plan            plan;
324         Var                *hashkey;
325         HashState  *hashstate;
326         HashJoinTable hashtable;
327         IpcMemoryKey hashtablekey;
328         int                     hashtablesize;
329 } Hash;
330
331 /* -------------------
332  *              Tee node information
333  *
334  *        leftParent :                          the left parent of this node
335  *        rightParent:                          the right parent of this node
336  * -------------------
337 */
338 typedef struct Tee
339 {
340         Plan            plan;
341         Plan       *leftParent;
342         Plan       *rightParent;
343         TeeState   *teestate;
344         char       *teeTableName;       /* the name of the table to materialize
345                                                                  * the tee into */
346         List       *rtentries;          /* the range table for the plan below the
347                                                                  * Tee may be different than the parent
348                                                                  * plans */
349 } Tee;
350
351 /* ---------------------
352  *              SubPlan node
353  * ---------------------
354  */
355 typedef struct SubPlan
356 {
357         NodeTag         type;
358         Plan       *plan;                       /* subselect plan itself */
359         int                     plan_id;                /* dummy thing because of we haven't equal
360                                                                  * funcs for plan nodes... actually, we
361                                                                  * could put *plan itself somewhere else
362                                                                  * (TopPlan node ?)... */
363         List       *rtable;                     /* range table */
364         List       *setParam;           /* non-correlated EXPR & EXISTS subqueries
365                                                                  * have to set some Params for paren Plan */
366         List       *parParam;           /* indices of corr. Vars from parent plan */
367         SubLink    *sublink;            /* SubLink node for subselects in WHERE
368                                                                  * and HAVING */
369         bool            shutdown;               /* shutdown plan if TRUE */
370 } SubPlan;
371
372 #endif   /* PLANNODES_H */