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