]> granicus.if.org Git - postgresql/blob - src/include/nodes/plannodes.h
2ca16b63272e16030a518996abda1707798dba71
[postgresql] / src / include / nodes / plannodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * plannodes.h
4  *        definitions for query plan nodes
5  *
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: plannodes.h,v 1.64 2003/02/09 00:30:40 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PLANNODES_H
15 #define PLANNODES_H
16
17 #include "access/sdir.h"
18 #include "nodes/bitmapset.h"
19 #include "nodes/primnodes.h"
20
21
22 /* ----------------------------------------------------------------
23  *                                              node definitions
24  * ----------------------------------------------------------------
25  */
26
27 /* ----------------
28  *              Plan node
29  *
30  * All plan nodes "derive" from the Plan structure by having the
31  * Plan structure as the first field.  This ensures that everything works
32  * when nodes are cast to Plan's.  (node pointers are frequently cast to Plan*
33  * when passed around generically in the executor)
34  *
35  * We never actually instantiate any Plan nodes; this is just the common
36  * abstract superclass for all Plan-type nodes.
37  * ----------------
38  */
39 typedef struct Plan
40 {
41         NodeTag         type;
42
43         /*
44          * estimated execution costs for plan (see costsize.c for more info)
45          */
46         Cost            startup_cost;   /* cost expended before fetching any
47                                                                  * tuples */
48         Cost            total_cost;             /* total cost (assuming all tuples
49                                                                  * fetched) */
50
51         /*
52          * planner's estimate of result size of this plan step
53          */
54         double          plan_rows;              /* number of rows plan is expected to emit */
55         int                     plan_width;             /* average row width in bytes */
56
57         /*
58          * Common structural data for all Plan types.
59          */
60         List       *targetlist;         /* target list to be computed at this node */
61         List       *qual;                       /* implicitly-ANDed qual conditions */
62         struct Plan *lefttree;          /* input plan tree(s) */
63         struct Plan *righttree;
64         List       *initPlan;           /* Init Plan nodes (un-correlated expr
65                                                                  * subselects) */
66
67         /*
68          * Information for management of parameter-change-driven rescanning
69          *
70          * extParam includes the paramIDs of all external PARAM_EXEC params
71          * affecting this plan node or its children.  setParam params from
72          * the node's initPlans are not included, but their extParams are.
73          *
74          * allParam includes all the extParam paramIDs, plus the IDs of local
75          * params that affect the node (i.e., the setParams of its initplans).
76          * These are _all_ the PARAM_EXEC params that affect this node.
77          */
78         Bitmapset  *extParam;
79         Bitmapset  *allParam;
80
81         /*
82          * We really need in some TopPlan node to store range table and
83          * resultRelation from Query there and get rid of Query itself from
84          * Executor. Some other stuff like below could be put there, too.
85          */
86         int                     nParamExec;             /* Number of them in entire query. This is
87                                                                  * to get Executor know about how many
88                                                                  * param_exec there are in query plan. */
89 } Plan;
90
91 /* ----------------
92  *      these are are defined to avoid confusion problems with "left"
93  *      and "right" and "inner" and "outer".  The convention is that
94  *      the "left" plan is the "outer" plan and the "right" plan is
95  *      the inner plan, but these make the code more readable.
96  * ----------------
97  */
98 #define innerPlan(node)                 (((Plan *)(node))->righttree)
99 #define outerPlan(node)                 (((Plan *)(node))->lefttree)
100
101
102 /* ----------------
103  *       Result node -
104  *              If no outer plan, evaluate a variable-free targetlist.
105  *              If outer plan, return tuples from outer plan (after a level of
106  *              projection as shown by targetlist).
107  *
108  * If resconstantqual isn't NULL, it represents a one-time qualification
109  * test (i.e., one that doesn't depend on any variables from the outer plan,
110  * so needs to be evaluated only once).
111  * ----------------
112  */
113 typedef struct Result
114 {
115         Plan            plan;
116         Node       *resconstantqual;
117 } Result;
118
119 /* ----------------
120  *       Append node -
121  *              Generate the concatenation of the results of sub-plans.
122  *
123  * Append nodes are sometimes used to switch between several result relations
124  * (when the target of an UPDATE or DELETE is an inheritance set).      Such a
125  * node will have isTarget true.  The Append executor is then responsible
126  * for updating the executor state to point at the correct target relation
127  * whenever it switches subplans.
128  * ----------------
129  */
130 typedef struct Append
131 {
132         Plan            plan;
133         List       *appendplans;
134         bool            isTarget;
135 } Append;
136
137 /*
138  * ==========
139  * Scan nodes
140  * ==========
141  */
142 typedef struct Scan
143 {
144         Plan            plan;
145         Index           scanrelid;              /* relid is index into the range table */
146 } Scan;
147
148 /* ----------------
149  *              sequential scan node
150  * ----------------
151  */
152 typedef Scan SeqScan;
153
154 /* ----------------
155  *              index scan node
156  * ----------------
157  */
158 typedef struct IndexScan
159 {
160         Scan            scan;
161         List       *indxid;
162         List       *indxqual;
163         List       *indxqualorig;
164         ScanDirection indxorderdir;
165 } IndexScan;
166
167 /* ----------------
168  *                              tid scan node
169  * ----------------
170  */
171 typedef struct TidScan
172 {
173         Scan            scan;
174         List       *tideval;
175 } TidScan;
176
177 /* ----------------
178  *              subquery scan node
179  *
180  * SubqueryScan is for scanning the output of a sub-query in the range table.
181  * We need a special plan node above the sub-query's plan as a place to switch
182  * execution contexts.  Although we are not scanning a physical relation,
183  * we make this a descendant of Scan anyway for code-sharing purposes.
184  *
185  * Note: we store the sub-plan in the type-specific subplan field, not in
186  * the generic lefttree field as you might expect.      This is because we do
187  * not want plan-tree-traversal routines to recurse into the subplan without
188  * knowing that they are changing Query contexts.
189  * ----------------
190  */
191 typedef struct SubqueryScan
192 {
193         Scan            scan;
194         Plan       *subplan;
195 } SubqueryScan;
196
197 /* ----------------
198  *              FunctionScan node
199  * ----------------
200  */
201 typedef struct FunctionScan
202 {
203         Scan            scan;
204         /* no other fields needed at present */
205 } FunctionScan;
206
207 /*
208  * ==========
209  * Join nodes
210  * ==========
211  */
212
213 /* ----------------
214  *              Join node
215  *
216  * jointype:    rule for joining tuples from left and right subtrees
217  * joinqual:    qual conditions that came from JOIN/ON or JOIN/USING
218  *                              (plan.qual contains conditions that came from WHERE)
219  *
220  * When jointype is INNER, joinqual and plan.qual are semantically
221  * interchangeable.  For OUTER jointypes, the two are *not* interchangeable;
222  * only joinqual is used to determine whether a match has been found for
223  * the purpose of deciding whether to generate null-extended tuples.
224  * (But plan.qual is still applied before actually returning a tuple.)
225  * For an outer join, only joinquals are allowed to be used as the merge
226  * or hash condition of a merge or hash join.
227  * ----------------
228  */
229 typedef struct Join
230 {
231         Plan            plan;
232         JoinType        jointype;
233         List       *joinqual;           /* JOIN quals (in addition to plan.qual) */
234 } Join;
235
236 /* ----------------
237  *              nest loop join node
238  * ----------------
239  */
240 typedef struct NestLoop
241 {
242         Join            join;
243 } NestLoop;
244
245 /* ----------------
246  *              merge join node
247  * ----------------
248  */
249 typedef struct MergeJoin
250 {
251         Join            join;
252         List       *mergeclauses;
253 } MergeJoin;
254
255 /* ----------------
256  *              hash join (probe) node
257  * ----------------
258  */
259 typedef struct HashJoin
260 {
261         Join            join;
262         List       *hashclauses;
263 } HashJoin;
264
265 /* ----------------
266  *              materialization node
267  * ----------------
268  */
269 typedef struct Material
270 {
271         Plan            plan;
272 } Material;
273
274 /* ----------------
275  *              sort node
276  * ----------------
277  */
278 typedef struct Sort
279 {
280         Plan            plan;
281         int                     keycount;
282 } Sort;
283
284 /* ---------------
285  *       group node -
286  *              Used for queries with GROUP BY (but no aggregates) specified.
287  *              The input must be presorted according to the grouping columns.
288  * ---------------
289  */
290 typedef struct Group
291 {
292         Plan            plan;
293         int                     numCols;                /* number of grouping columns */
294         AttrNumber *grpColIdx;          /* their indexes in the target list */
295 } Group;
296
297 /* ---------------
298  *              aggregate node
299  *
300  * An Agg node implements plain or grouped aggregation.  For grouped
301  * aggregation, we can work with presorted input or unsorted input;
302  * the latter strategy uses an internal hashtable.
303  *
304  * Notice the lack of any direct info about the aggregate functions to be
305  * computed.  They are found by scanning the node's tlist and quals during
306  * executor startup.  (It is possible that there are no aggregate functions;
307  * this could happen if they get optimized away by constant-folding, or if
308  * we are using the Agg node to implement hash-based grouping.)
309  * ---------------
310  */
311 typedef enum AggStrategy
312 {
313         AGG_PLAIN,                                      /* simple agg across all input rows */
314         AGG_SORTED,                                     /* grouped agg, input must be sorted */
315         AGG_HASHED                                      /* grouped agg, use internal hashtable */
316 } AggStrategy;
317
318 typedef struct Agg
319 {
320         Plan            plan;
321         AggStrategy     aggstrategy;
322         int                     numCols;                /* number of grouping columns */
323         AttrNumber *grpColIdx;          /* their indexes in the target list */
324         long            numGroups;              /* estimated number of groups in input */
325 } Agg;
326
327 /* ----------------
328  *              unique node
329  * ----------------
330  */
331 typedef struct Unique
332 {
333         Plan            plan;
334         int                     numCols;                /* number of columns to check for
335                                                                  * uniqueness */
336         AttrNumber *uniqColIdx;         /* indexes into the target list */
337 } Unique;
338
339 /* ----------------
340  *              hash build node
341  * ----------------
342  */
343 typedef struct Hash
344 {
345         Plan            plan;
346         List       *hashkeys;
347 } Hash;
348
349 /* ----------------
350  *              setop node
351  * ----------------
352  */
353 typedef enum SetOpCmd
354 {
355         SETOPCMD_INTERSECT,
356         SETOPCMD_INTERSECT_ALL,
357         SETOPCMD_EXCEPT,
358         SETOPCMD_EXCEPT_ALL
359 } SetOpCmd;
360
361 typedef struct SetOp
362 {
363         Plan            plan;
364         SetOpCmd        cmd;                    /* what to do */
365         int                     numCols;                /* number of columns to check for
366                                                                  * duplicate-ness */
367         AttrNumber *dupColIdx;          /* indexes into the target list */
368         AttrNumber      flagColIdx;
369 } SetOp;
370
371 /* ----------------
372  *              limit node
373  * ----------------
374  */
375 typedef struct Limit
376 {
377         Plan            plan;
378         Node       *limitOffset;        /* OFFSET parameter, or NULL if none */
379         Node       *limitCount;         /* COUNT parameter, or NULL if none */
380 } Limit;
381
382 #endif   /* PLANNODES_H */