1 /*-------------------------------------------------------------------------
4 * definitions for query plan nodes
7 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: plannodes.h,v 1.64 2003/02/09 00:30:40 tgl Exp $
12 *-------------------------------------------------------------------------
17 #include "access/sdir.h"
18 #include "nodes/bitmapset.h"
19 #include "nodes/primnodes.h"
22 /* ----------------------------------------------------------------
24 * ----------------------------------------------------------------
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)
35 * We never actually instantiate any Plan nodes; this is just the common
36 * abstract superclass for all Plan-type nodes.
44 * estimated execution costs for plan (see costsize.c for more info)
46 Cost startup_cost; /* cost expended before fetching any
48 Cost total_cost; /* total cost (assuming all tuples
52 * planner's estimate of result size of this plan step
54 double plan_rows; /* number of rows plan is expected to emit */
55 int plan_width; /* average row width in bytes */
58 * Common structural data for all Plan types.
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
68 * Information for management of parameter-change-driven rescanning
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.
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.
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.
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. */
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.
98 #define innerPlan(node) (((Plan *)(node))->righttree)
99 #define outerPlan(node) (((Plan *)(node))->lefttree)
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).
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).
113 typedef struct Result
116 Node *resconstantqual;
121 * Generate the concatenation of the results of sub-plans.
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.
130 typedef struct Append
145 Index scanrelid; /* relid is index into the range table */
149 * sequential scan node
152 typedef Scan SeqScan;
158 typedef struct IndexScan
164 ScanDirection indxorderdir;
171 typedef struct TidScan
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.
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.
191 typedef struct SubqueryScan
201 typedef struct FunctionScan
204 /* no other fields needed at present */
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)
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.
233 List *joinqual; /* JOIN quals (in addition to plan.qual) */
237 * nest loop join node
240 typedef struct NestLoop
249 typedef struct MergeJoin
256 * hash join (probe) node
259 typedef struct HashJoin
266 * materialization node
269 typedef struct Material
286 * Used for queries with GROUP BY (but no aggregates) specified.
287 * The input must be presorted according to the grouping columns.
293 int numCols; /* number of grouping columns */
294 AttrNumber *grpColIdx; /* their indexes in the target list */
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.
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.)
311 typedef enum AggStrategy
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 */
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 */
331 typedef struct Unique
334 int numCols; /* number of columns to check for
336 AttrNumber *uniqColIdx; /* indexes into the target list */
353 typedef enum SetOpCmd
356 SETOPCMD_INTERSECT_ALL,
364 SetOpCmd cmd; /* what to do */
365 int numCols; /* number of columns to check for
367 AttrNumber *dupColIdx; /* indexes into the target list */
368 AttrNumber flagColIdx;
378 Node *limitOffset; /* OFFSET parameter, or NULL if none */
379 Node *limitCount; /* COUNT parameter, or NULL if none */
382 #endif /* PLANNODES_H */