OSDN Git Service

Executor no longer cares about mergejoinop, mergerightorder, mergeleftorder,
[pg-rex/syncrep.git] / 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.23 1999/03/01 00:10:36 tgl 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         MergeJoinState *mergestate;
212 } MergeJoin;
213
214 /* ----------------
215  *              hash join (probe) node
216  * ----------------
217  */
218 typedef struct HashJoin
219 {
220         Join            join;
221         List       *hashclauses;
222         Oid                     hashjoinop;
223         HashJoinState *hashjoinstate;
224         HashJoinTable hashjointable;
225         IpcMemoryKey hashjointablekey;
226         int                     hashjointablesize;
227         bool            hashdone;
228 } HashJoin;
229
230 /* ---------------
231  *              aggregate node
232  * ---------------
233  */
234 typedef struct Agg
235 {
236         Plan            plan;
237         List       *aggs;
238         AggState   *aggstate;
239 } Agg;
240
241 /* ---------------
242  *       group node -
243  *              use for queries with GROUP BY specified.
244  *
245  *              If tuplePerGroup is true, one tuple (with group columns only) is
246  *              returned for each group and NULL is returned when there are no more
247  *              groups. Otherwise, all the tuples of a group are returned with a
248  *              NULL returned at the end of each group. (see nodeGroup.c for details)
249  * ---------------
250  */
251 typedef struct Group
252 {
253         Plan            plan;
254         bool            tuplePerGroup;  /* what tuples to return (see above) */
255         int                     numCols;                /* number of group columns */
256         AttrNumber *grpColIdx;          /* index into the target list */
257         GroupState *grpstate;
258 } Group;
259
260 /*
261  * ==========
262  * Noname nodes
263  * ==========
264  */
265 typedef struct Noname
266 {
267         Plan            plan;
268         Oid                     nonameid;
269         int                     keycount;
270 } Noname;
271
272 /* ----------------
273  *              materialization node
274  * ----------------
275  */
276 typedef struct Material
277 {
278         Plan            plan;                   /* noname node flattened out */
279         Oid                     nonameid;
280         int                     keycount;
281         MaterialState *matstate;
282 } Material;
283
284 /* ----------------
285  *              sort node
286  * ----------------
287  */
288 typedef struct Sort
289 {
290         Plan            plan;                   /* noname node flattened out */
291         Oid                     nonameid;
292         int                     keycount;
293         SortState  *sortstate;
294         void       *psortstate;
295         bool            cleaned;
296 } Sort;
297
298 /* ----------------
299  *              unique node
300  * ----------------
301  */
302 typedef struct Unique
303 {
304         Plan            plan;                   /* noname node flattened out */
305         Oid                     nonameid;
306         int                     keycount;
307         char       *uniqueAttr;         /* NULL if all attrs, or unique attribute
308                                                                  * name */
309         AttrNumber      uniqueAttrNum;  /* attribute number of attribute to select
310                                                                  * distinct on */
311         UniqueState *uniquestate;
312 } Unique;
313
314 /* ----------------
315  *              hash build node
316  * ----------------
317  */
318 typedef struct Hash
319 {
320         Plan            plan;
321         Var                *hashkey;
322         HashState  *hashstate;
323         HashJoinTable hashtable;
324         IpcMemoryKey hashtablekey;
325         int                     hashtablesize;
326 } Hash;
327
328 /* -------------------
329  *              Tee node information
330  *
331  *        leftParent :                          the left parent of this node
332  *        rightParent:                          the right parent of this node
333  * -------------------
334 */
335 typedef struct Tee
336 {
337         Plan            plan;
338         Plan       *leftParent;
339         Plan       *rightParent;
340         TeeState   *teestate;
341         char       *teeTableName;       /* the name of the table to materialize
342                                                                  * the tee into */
343         List       *rtentries;          /* the range table for the plan below the
344                                                                  * Tee may be different than the parent
345                                                                  * plans */
346 } Tee;
347
348 /* ---------------------
349  *              SubPlan node
350  * ---------------------
351  */
352 typedef struct SubPlan
353 {
354         NodeTag         type;
355         Plan       *plan;                       /* subselect plan itself */
356         int                     plan_id;                /* dummy thing because of we haven't equal
357                                                                  * funcs for plan nodes... actually, we
358                                                                  * could put *plan itself somewhere else
359                                                                  * (TopPlan node ?)... */
360         List       *rtable;                     /* range table */
361         List       *setParam;           /* non-correlated EXPR & EXISTS subqueries
362                                                                  * have to set some Params for paren Plan */
363         List       *parParam;           /* indices of corr. Vars from parent plan */
364         SubLink    *sublink;            /* SubLink node for subselects in WHERE
365                                                                  * and HAVING */
366         bool            shutdown;               /* shutdown plan if TRUE */
367 } SubPlan;
368
369 #endif   /* PLANNODES_H */