]> granicus.if.org Git - postgresql/blob - src/include/nodes/plannodes.h
Implement feature of new FE/BE protocol whereby RowDescription identifies
[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.65 2003/05/06 00:20:33 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                     numCols;                /* number of sort-key columns */
282         AttrNumber *sortColIdx;         /* their indexes in the target list */
283         Oid                *sortOperators;      /* OIDs of operators to sort them by */
284 } Sort;
285
286 /* ---------------
287  *       group node -
288  *              Used for queries with GROUP BY (but no aggregates) specified.
289  *              The input must be presorted according to the grouping columns.
290  * ---------------
291  */
292 typedef struct Group
293 {
294         Plan            plan;
295         int                     numCols;                /* number of grouping columns */
296         AttrNumber *grpColIdx;          /* their indexes in the target list */
297 } Group;
298
299 /* ---------------
300  *              aggregate node
301  *
302  * An Agg node implements plain or grouped aggregation.  For grouped
303  * aggregation, we can work with presorted input or unsorted input;
304  * the latter strategy uses an internal hashtable.
305  *
306  * Notice the lack of any direct info about the aggregate functions to be
307  * computed.  They are found by scanning the node's tlist and quals during
308  * executor startup.  (It is possible that there are no aggregate functions;
309  * this could happen if they get optimized away by constant-folding, or if
310  * we are using the Agg node to implement hash-based grouping.)
311  * ---------------
312  */
313 typedef enum AggStrategy
314 {
315         AGG_PLAIN,                                      /* simple agg across all input rows */
316         AGG_SORTED,                                     /* grouped agg, input must be sorted */
317         AGG_HASHED                                      /* grouped agg, use internal hashtable */
318 } AggStrategy;
319
320 typedef struct Agg
321 {
322         Plan            plan;
323         AggStrategy     aggstrategy;
324         int                     numCols;                /* number of grouping columns */
325         AttrNumber *grpColIdx;          /* their indexes in the target list */
326         long            numGroups;              /* estimated number of groups in input */
327 } Agg;
328
329 /* ----------------
330  *              unique node
331  * ----------------
332  */
333 typedef struct Unique
334 {
335         Plan            plan;
336         int                     numCols;                /* number of columns to check for
337                                                                  * uniqueness */
338         AttrNumber *uniqColIdx;         /* indexes into the target list */
339 } Unique;
340
341 /* ----------------
342  *              hash build node
343  * ----------------
344  */
345 typedef struct Hash
346 {
347         Plan            plan;
348         List       *hashkeys;
349 } Hash;
350
351 /* ----------------
352  *              setop node
353  * ----------------
354  */
355 typedef enum SetOpCmd
356 {
357         SETOPCMD_INTERSECT,
358         SETOPCMD_INTERSECT_ALL,
359         SETOPCMD_EXCEPT,
360         SETOPCMD_EXCEPT_ALL
361 } SetOpCmd;
362
363 typedef struct SetOp
364 {
365         Plan            plan;
366         SetOpCmd        cmd;                    /* what to do */
367         int                     numCols;                /* number of columns to check for
368                                                                  * duplicate-ness */
369         AttrNumber *dupColIdx;          /* indexes into the target list */
370         AttrNumber      flagColIdx;
371 } SetOp;
372
373 /* ----------------
374  *              limit node
375  * ----------------
376  */
377 typedef struct Limit
378 {
379         Plan            plan;
380         Node       *limitOffset;        /* OFFSET parameter, or NULL if none */
381         Node       *limitCount;         /* COUNT parameter, or NULL if none */
382 } Limit;
383
384 #endif   /* PLANNODES_H */