]> granicus.if.org Git - postgresql/blob - src/include/nodes/plannodes.h
Redesign DISTINCT ON as discussed in pgsql-sql 1/25/00: syntax is now
[postgresql] / src / include / nodes / plannodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * plannodes.h
4  *        definitions for query plan nodes
5  *
6  *
7  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: plannodes.h,v 1.37 2000/01/27 18:11:44 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PLANNODES_H
15 #define PLANNODES_H
16
17 #include "nodes/execnodes.h"
18
19 /* ----------------------------------------------------------------
20  *      Executor State types are used in the plannode structures
21  *      so we have to include their definitions too.
22  *
23  *              Node Type                               node information used by executor
24  *
25  * control nodes
26  *
27  *              Result                                  ResultState                             resstate;
28  *              Append                                  AppendState                             appendstate;
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 {
66         NodeTag         type;
67
68         /* planner's estimates of cost and result size */
69         Cost            cost;
70         double          plan_rows;
71         int                     plan_width;
72
73         EState     *state;                      /* at execution time, state's of
74                                                                  * individual nodes point to one EState
75                                                                  * for the whole top-level plan */
76         List       *targetlist;
77         List       *qual;                       /* Node* or List* ?? */
78         struct Plan *lefttree;
79         struct Plan *righttree;
80         List       *extParam;           /* indices of _all_ _external_ PARAM_EXEC
81                                                                  * for this plan in global
82                                                                  * es_param_exec_vals. Params from
83                                                                  * setParam from initPlan-s are not
84                                                                  * included, but their execParam-s are
85                                                                  * here!!! */
86         List       *locParam;           /* someones from setParam-s */
87         List       *chgParam;           /* list of changed ones from the above */
88         List       *initPlan;           /* Init Plan nodes (un-correlated expr
89                                                                  * subselects) */
90         List       *subPlan;            /* Other SubPlan nodes */
91
92         /*
93          * We really need in some TopPlan node to store range table and
94          * resultRelation from Query there and get rid of Query itself from
95          * Executor. Some other stuff like below could be put there, too.
96          */
97         int                     nParamExec;             /* Number of them in entire query. This is
98                                                                  * to get Executor know about how many
99                                                                  * param_exec there are in query plan. */
100 } Plan;
101
102 /* ----------------
103  *      these are are defined to avoid confusion problems with "left"
104  *      and "right" and "inner" and "outer".  The convention is that
105  *      the "left" plan is the "outer" plan and the "right" plan is
106  *      the inner plan, but these make the code more readable.
107  * ----------------
108  */
109 #define innerPlan(node)                 (((Plan *)(node))->righttree)
110 #define outerPlan(node)                 (((Plan *)(node))->lefttree)
111
112
113 /*
114  * ===============
115  * Top-level nodes
116  * ===============
117  */
118
119 /* all plan nodes "derive" from the Plan structure by having the
120    Plan structure as the first field.  This ensures that everything works
121    when nodes are cast to Plan's.  (node pointers are frequently cast to Plan*
122    when passed around generically in the executor */
123
124
125 /* ----------------
126  *       result node -
127  *              returns tuples from outer plan that satisfy the qualifications
128  * ----------------
129  */
130 typedef struct Result
131 {
132         Plan            plan;
133         Node       *resconstantqual;
134         ResultState *resstate;
135 } Result;
136
137 /* ----------------
138  *              append node
139  * ----------------
140  */
141 typedef struct Append
142 {
143         Plan            plan;
144         List       *appendplans;
145         List       *unionrtables;       /* List of range tables, one for each
146                                                                  * union query. */
147         Index           inheritrelid;   /* The range table has to be changed for
148                                                                  * inheritance. */
149         List       *inheritrtable;
150         AppendState *appendstate;
151 } Append;
152
153 /*
154  * ==========
155  * Scan nodes
156  * ==========
157  */
158 typedef struct Scan
159 {
160         Plan            plan;
161         Index           scanrelid;              /* relid is index into the range table */
162         CommonScanState *scanstate;
163 } Scan;
164
165 /* ----------------
166  *              sequential scan node
167  * ----------------
168  */
169 typedef Scan SeqScan;
170
171 /* ----------------
172  *              index scan node
173  * ----------------
174  */
175 typedef struct IndexScan
176 {
177         Scan            scan;
178         List       *indxid;
179         List       *indxqual;
180         List       *indxqualorig;
181         ScanDirection   indxorderdir;
182         IndexScanState *indxstate;
183 } IndexScan;
184
185 /* ----------------
186  *              tid scan node
187  * ----------------
188  */
189 typedef struct TidScan
190 {
191         Scan            scan;
192         bool            needRescan;
193         List       *tideval;
194         TidScanState *tidstate;
195 } TidScan;
196
197 /* 
198  * ==========
199  * Join nodes
200  * ==========
201  */
202
203 /* ----------------
204  *              Join node
205  * ----------------
206  */
207 typedef Plan Join;
208
209 /* ----------------
210  *              nest loop join node
211  * ----------------
212  */
213 typedef struct NestLoop
214 {
215         Join            join;
216         NestLoopState *nlstate;
217 } NestLoop;
218
219 /* ----------------
220  *              merge join node
221  * ----------------
222  */
223 typedef struct MergeJoin
224 {
225         Join            join;
226         List       *mergeclauses;
227         MergeJoinState *mergestate;
228 } MergeJoin;
229
230 /* ----------------
231  *              hash join (probe) node
232  * ----------------
233  */
234 typedef struct HashJoin
235 {
236         Join            join;
237         List       *hashclauses;
238         Oid                     hashjoinop;
239         HashJoinState *hashjoinstate;
240         bool            hashdone;
241 } HashJoin;
242
243 /* ---------------
244  *              aggregate node
245  * ---------------
246  */
247 typedef struct Agg
248 {
249         Plan            plan;
250         AggState   *aggstate;
251 } Agg;
252
253 /* ---------------
254  *       group node -
255  *              use for queries with GROUP BY specified.
256  *
257  *              If tuplePerGroup is true, one tuple (with group columns only) is
258  *              returned for each group and NULL is returned when there are no more
259  *              groups. Otherwise, all the tuples of a group are returned with a
260  *              NULL returned at the end of each group. (see nodeGroup.c for details)
261  * ---------------
262  */
263 typedef struct Group
264 {
265         Plan            plan;
266         bool            tuplePerGroup;  /* what tuples to return (see above) */
267         int                     numCols;                /* number of group columns */
268         AttrNumber *grpColIdx;          /* indexes into the target list */
269         GroupState *grpstate;
270 } Group;
271
272 /*
273  * ==========
274  * Noname nodes
275  * ==========
276  */
277 typedef struct Noname
278 {
279         Plan            plan;
280         Oid                     nonameid;
281         int                     keycount;
282 } Noname;
283
284 /* ----------------
285  *              materialization node
286  * ----------------
287  */
288 typedef struct Material
289 {
290         Plan            plan;                   /* noname node flattened out */
291         Oid                     nonameid;
292         int                     keycount;
293         MaterialState *matstate;
294 } Material;
295
296 /* ----------------
297  *              sort node
298  * ----------------
299  */
300 typedef struct Sort
301 {
302         Plan            plan;                   /* noname node flattened out */
303         Oid                     nonameid;
304         int                     keycount;
305         SortState  *sortstate;
306 } Sort;
307
308 /* ----------------
309  *              unique node
310  * ----------------
311  */
312 typedef struct Unique
313 {
314         Plan            plan;                   /* noname node flattened out */
315         Oid                     nonameid;
316         int                     keycount;
317         int                     numCols;                /* number of columns to check for uniqueness */
318         AttrNumber *uniqColIdx;         /* indexes into the target list */
319         UniqueState *uniquestate;
320 } Unique;
321
322 /* ----------------
323  *              hash build node
324  * ----------------
325  */
326 typedef struct Hash
327 {
328         Plan            plan;
329         Var                *hashkey;
330         HashState  *hashstate;
331 } Hash;
332
333 #ifdef NOT_USED
334 /* -------------------
335  *              Tee node information
336  *
337  *        leftParent :                          the left parent of this node
338  *        rightParent:                          the right parent of this node
339  * -------------------
340 */
341 typedef struct Tee
342 {
343         Plan            plan;
344         Plan       *leftParent;
345         Plan       *rightParent;
346         TeeState   *teestate;
347         char       *teeTableName;       /* the name of the table to materialize
348                                                                  * the tee into */
349         List       *rtentries;          /* the range table for the plan below the
350                                                                  * Tee may be different than the parent
351                                                                  * plans */
352 }                       Tee;
353
354 #endif
355
356 /* ---------------------
357  *              SubPlan node
358  * ---------------------
359  */
360 typedef struct SubPlan
361 {
362         NodeTag         type;
363         Plan       *plan;                       /* subselect plan itself */
364         int                     plan_id;                /* dummy thing because of we haven't equal
365                                                                  * funcs for plan nodes... actually, we
366                                                                  * could put *plan itself somewhere else
367                                                                  * (TopPlan node ?)... */
368         List       *rtable;                     /* range table for subselect */
369         /* setParam and parParam are lists of integers (param IDs) */
370         List       *setParam;           /* non-correlated EXPR & EXISTS subqueries
371                                                                  * have to set some Params for paren Plan */
372         List       *parParam;           /* indices of corr. Vars from parent plan */
373         SubLink    *sublink;            /* SubLink node from parser; holds info about
374                                                                  * what to do with subselect's results */
375         /*
376          * Remaining fields are working state for executor; not used in planning
377          */
378         bool            shutdown;               /* TRUE = need to shutdown plan */
379         HeapTuple       curTuple;               /* copy of most recent tuple from subplan */
380 } SubPlan;
381
382 #endif   /* PLANNODES_H */