1 /*-------------------------------------------------------------------------
4 * definitions for query plan nodes
7 * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL: pgsql/src/include/nodes/plannodes.h,v 1.83 2006/03/05 15:58:57 momjian 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 tuples */
47 Cost total_cost; /* total cost (assuming all tuples fetched) */
50 * planner's estimate of result size of this plan step
52 double plan_rows; /* number of rows plan is expected to emit */
53 int plan_width; /* average row width in bytes */
56 * Common structural data for all Plan types.
58 List *targetlist; /* target list to be computed at this node */
59 List *qual; /* implicitly-ANDed qual conditions */
60 struct Plan *lefttree; /* input plan tree(s) */
61 struct Plan *righttree;
62 List *initPlan; /* Init Plan nodes (un-correlated expr
66 * Information for management of parameter-change-driven rescanning
68 * extParam includes the paramIDs of all external PARAM_EXEC params
69 * affecting this plan node or its children. setParam params from the
70 * node's initPlans are not included, but their extParams are.
72 * allParam includes all the extParam paramIDs, plus the IDs of local
73 * params that affect the node (i.e., the setParams of its initplans).
74 * These are _all_ the PARAM_EXEC params that affect this node.
80 * We really need in some TopPlan node to store range table and
81 * resultRelation from Query there and get rid of Query itself from
82 * Executor. Some other stuff like below could be put there, too.
84 int nParamExec; /* Number of them in entire query. This is to
85 * get Executor know about how many PARAM_EXEC
86 * there are in query plan. */
90 * these are are defined to avoid confusion problems with "left"
91 * and "right" and "inner" and "outer". The convention is that
92 * the "left" plan is the "outer" plan and the "right" plan is
93 * the inner plan, but these make the code more readable.
96 #define innerPlan(node) (((Plan *)(node))->righttree)
97 #define outerPlan(node) (((Plan *)(node))->lefttree)
102 * If no outer plan, evaluate a variable-free targetlist.
103 * If outer plan, return tuples from outer plan (after a level of
104 * projection as shown by targetlist).
106 * If resconstantqual isn't NULL, it represents a one-time qualification
107 * test (i.e., one that doesn't depend on any variables from the outer plan,
108 * so needs to be evaluated only once).
111 typedef struct Result
114 Node *resconstantqual;
119 * Generate the concatenation of the results of sub-plans.
121 * Append nodes are sometimes used to switch between several result relations
122 * (when the target of an UPDATE or DELETE is an inheritance set). Such a
123 * node will have isTarget true. The Append executor is then responsible
124 * for updating the executor state to point at the correct target relation
125 * whenever it switches subplans.
128 typedef struct Append
137 * Generate the intersection of the results of sub-plans.
139 * The subplans must be of types that yield tuple bitmaps. The targetlist
140 * and qual fields of the plan are unused and are always NIL.
143 typedef struct BitmapAnd
151 * Generate the union of the results of sub-plans.
153 * The subplans must be of types that yield tuple bitmaps. The targetlist
154 * and qual fields of the plan are unused and are always NIL.
157 typedef struct BitmapOr
171 Index scanrelid; /* relid is index into the range table */
175 * sequential scan node
178 typedef Scan SeqScan;
183 * indexqualorig is an implicitly-ANDed list of index qual expressions, each
184 * in the same form it appeared in the query WHERE condition. Each should
185 * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
186 * The indexkey is a Var or expression referencing column(s) of the index's
187 * base table. The comparisonval might be any expression, but it won't use
188 * any columns of the base table.
190 * indexqual has the same form, but the expressions have been commuted if
191 * necessary to put the indexkeys on the left, and the indexkeys are replaced
192 * by Var nodes identifying the index columns (varattno is the index column
193 * position, not the base table's column, even though varno is for the base
194 * table). This is a bit hokey ... would be cleaner to use a special-purpose
195 * node type that could not be mistaken for a regular Var. But it will do
198 * indexstrategy and indexsubtype are lists corresponding one-to-one with
199 * indexqual; they give information about the indexable operators that appear
200 * at the top of each indexqual.
203 typedef struct IndexScan
206 Oid indexid; /* OID of index to scan */
207 List *indexqual; /* list of index quals (OpExprs) */
208 List *indexqualorig; /* the same in original form */
209 List *indexstrategy; /* integer list of strategy numbers */
210 List *indexsubtype; /* OID list of strategy subtypes */
211 ScanDirection indexorderdir; /* forward or backward or don't care */
215 * bitmap index scan node
217 * BitmapIndexScan delivers a bitmap of potential tuple locations;
218 * it does not access the heap itself. The bitmap is used by an
219 * ancestor BitmapHeapScan node, possibly after passing through
220 * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
221 * the results of other BitmapIndexScans.
223 * The fields have the same meanings as for IndexScan, except we don't
224 * store a direction flag because direction is uninteresting.
226 * In a BitmapIndexScan plan node, the targetlist and qual fields are
227 * not used and are always NIL. The indexqualorig field is unused at
228 * run time too, but is saved for the benefit of EXPLAIN.
231 typedef struct BitmapIndexScan
234 Oid indexid; /* OID of index to scan */
235 List *indexqual; /* list of index quals (OpExprs) */
236 List *indexqualorig; /* the same in original form */
237 List *indexstrategy; /* integer list of strategy numbers */
238 List *indexsubtype; /* OID list of strategy subtypes */
242 * bitmap sequential scan node
244 * This needs a copy of the qual conditions being used by the input index
245 * scans because there are various cases where we need to recheck the quals;
246 * for example, when the bitmap is lossy about the specific rows on a page
247 * that meet the index condition.
250 typedef struct BitmapHeapScan
253 List *bitmapqualorig; /* index quals, in standard expr form */
259 * tidquals is an implicitly OR'ed list of qual expressions of the form
260 * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)".
263 typedef struct TidScan
266 List *tidquals; /* qual(s) involving CTID = something */
272 * SubqueryScan is for scanning the output of a sub-query in the range table.
273 * We need a special plan node above the sub-query's plan as a place to switch
274 * execution contexts. Although we are not scanning a physical relation,
275 * we make this a descendant of Scan anyway for code-sharing purposes.
277 * Note: we store the sub-plan in the type-specific subplan field, not in
278 * the generic lefttree field as you might expect. This is because we do
279 * not want plan-tree-traversal routines to recurse into the subplan without
280 * knowing that they are changing Query contexts.
283 typedef struct SubqueryScan
293 typedef struct FunctionScan
296 /* no other fields needed at present */
308 * jointype: rule for joining tuples from left and right subtrees
309 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
310 * (plan.qual contains conditions that came from WHERE)
312 * When jointype is INNER, joinqual and plan.qual are semantically
313 * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
314 * only joinqual is used to determine whether a match has been found for
315 * the purpose of deciding whether to generate null-extended tuples.
316 * (But plan.qual is still applied before actually returning a tuple.)
317 * For an outer join, only joinquals are allowed to be used as the merge
318 * or hash condition of a merge or hash join.
325 List *joinqual; /* JOIN quals (in addition to plan.qual) */
329 * nest loop join node
332 typedef struct NestLoop
341 typedef struct MergeJoin
348 * hash join (probe) node
351 typedef struct HashJoin
358 * materialization node
361 typedef struct Material
373 int numCols; /* number of sort-key columns */
374 AttrNumber *sortColIdx; /* their indexes in the target list */
375 Oid *sortOperators; /* OIDs of operators to sort them by */
380 * Used for queries with GROUP BY (but no aggregates) specified.
381 * The input must be presorted according to the grouping columns.
387 int numCols; /* number of grouping columns */
388 AttrNumber *grpColIdx; /* their indexes in the target list */
394 * An Agg node implements plain or grouped aggregation. For grouped
395 * aggregation, we can work with presorted input or unsorted input;
396 * the latter strategy uses an internal hashtable.
398 * Notice the lack of any direct info about the aggregate functions to be
399 * computed. They are found by scanning the node's tlist and quals during
400 * executor startup. (It is possible that there are no aggregate functions;
401 * this could happen if they get optimized away by constant-folding, or if
402 * we are using the Agg node to implement hash-based grouping.)
405 typedef enum AggStrategy
407 AGG_PLAIN, /* simple agg across all input rows */
408 AGG_SORTED, /* grouped agg, input must be sorted */
409 AGG_HASHED /* grouped agg, use internal hashtable */
415 AggStrategy aggstrategy;
416 int numCols; /* number of grouping columns */
417 AttrNumber *grpColIdx; /* their indexes in the target list */
418 long numGroups; /* estimated number of groups in input */
425 typedef struct Unique
428 int numCols; /* number of columns to check for uniqueness */
429 AttrNumber *uniqColIdx; /* indexes into the target list */
439 /* all other info is in the parent HashJoin node */
446 typedef enum SetOpCmd
449 SETOPCMD_INTERSECT_ALL,
457 SetOpCmd cmd; /* what to do */
458 int numCols; /* number of columns to check for
460 AttrNumber *dupColIdx; /* indexes into the target list */
461 AttrNumber flagColIdx;
471 Node *limitOffset; /* OFFSET parameter, or NULL if none */
472 Node *limitCount; /* COUNT parameter, or NULL if none */
475 #endif /* PLANNODES_H */