1 /*-------------------------------------------------------------------------
4 * definitions for query plan nodes
7 * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: plannodes.h,v 1.47 2001/01/24 19:43:26 momjian Exp $
12 *-------------------------------------------------------------------------
17 #include "nodes/execnodes.h"
19 /* ----------------------------------------------------------------
20 * Executor State types are used in the plannode structures
21 * so we have to include their definitions too.
23 * Node Type node information used by executor
27 * Result ResultState resstate;
28 * Append AppendState appendstate;
32 * Scan *** CommonScanState scanstate;
33 * IndexScan IndexScanState indxstate;
34 * SubqueryScan SubqueryScanState subquerystate;
36 * (*** nodes which inherit Scan also inherit scanstate)
40 * NestLoop NestLoopState nlstate;
41 * MergeJoin MergeJoinState mergestate;
42 * HashJoin HashJoinState hashjoinstate;
46 * Material MaterialState matstate;
47 * Sort SortState sortstate;
48 * Unique UniqueState uniquestate;
49 * SetOp SetOpState setopstate;
50 * Limit LimitState limitstate;
51 * Hash HashState hashstate;
53 * ----------------------------------------------------------------
57 /* ----------------------------------------------------------------
59 * ----------------------------------------------------------------
71 /* estimated execution costs for plan (see costsize.c for more info) */
72 Cost startup_cost; /* cost expended before fetching any
74 Cost total_cost; /* total cost (assuming all tuples
78 * planner's estimate of result size (note: LIMIT, if any, is not
79 * considered in setting plan_rows)
81 double plan_rows; /* number of rows plan is expected to emit */
82 int plan_width; /* average row width in bytes */
84 EState *state; /* at execution time, state's of
85 * individual nodes point to one EState
86 * for the whole top-level plan */
88 List *qual; /* implicitly-ANDed qual conditions */
89 struct Plan *lefttree;
90 struct Plan *righttree;
91 List *extParam; /* indices of _all_ _external_ PARAM_EXEC
92 * for this plan in global
93 * es_param_exec_vals. Params from
94 * setParam from initPlan-s are not
95 * included, but their execParam-s are
97 List *locParam; /* someones from setParam-s */
98 List *chgParam; /* list of changed ones from the above */
99 List *initPlan; /* Init Plan nodes (un-correlated expr
101 List *subPlan; /* Other SubPlan nodes */
104 * We really need in some TopPlan node to store range table and
105 * resultRelation from Query there and get rid of Query itself from
106 * Executor. Some other stuff like below could be put there, too.
108 int nParamExec; /* Number of them in entire query. This is
109 * to get Executor know about how many
110 * param_exec there are in query plan. */
114 * these are are defined to avoid confusion problems with "left"
115 * and "right" and "inner" and "outer". The convention is that
116 * the "left" plan is the "outer" plan and the "right" plan is
117 * the inner plan, but these make the code more readable.
120 #define innerPlan(node) (((Plan *)(node))->righttree)
121 #define outerPlan(node) (((Plan *)(node))->lefttree)
130 /* all plan nodes "derive" from the Plan structure by having the
131 Plan structure as the first field. This ensures that everything works
132 when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
133 when passed around generically in the executor */
138 * If no outer plan, evaluate a variable-free targetlist.
139 * If outer plan, return tuples from outer plan that satisfy
140 * given quals (we can also do a level of projection)
143 typedef struct Result
146 Node *resconstantqual;
147 ResultState *resstate;
152 * Generate the concatenation of the results of sub-plans.
154 * Append nodes are sometimes used to switch between several result relations
155 * (when the target of an UPDATE or DELETE is an inheritance set). Such a
156 * node will have isTarget true. The Append executor is then responsible
157 * for updating the executor state to point at the correct target relation
158 * whenever it switches subplans.
161 typedef struct Append
166 AppendState *appendstate;
177 Index scanrelid; /* relid is index into the range table */
178 CommonScanState *scanstate;
182 * sequential scan node
185 typedef Scan SeqScan;
191 typedef struct IndexScan
197 ScanDirection indxorderdir;
198 IndexScanState *indxstate;
205 typedef struct TidScan
210 TidScanState *tidstate;
216 * SubqueryScan is for scanning the output of a sub-query in the range table.
217 * We need a special plan node above the sub-query's plan as a place to switch
218 * execution contexts. Although we are not scanning a physical relation,
219 * we make this a descendant of Scan anyway for code-sharing purposes.
221 * Note: we store the sub-plan in the type-specific subplan field, not in
222 * the generic lefttree field as you might expect. This is because we do
223 * not want plan-tree-traversal routines to recurse into the subplan without
224 * knowing that they are changing Query contexts.
227 typedef struct SubqueryScan
242 * jointype: rule for joining tuples from left and right subtrees
243 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
244 * (plan.qual contains conditions that came from WHERE)
246 * When jointype is INNER, joinqual and plan.qual are semantically
247 * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
248 * only joinqual is used to determine whether a match has been found for
249 * the purpose of deciding whether to generate null-extended tuples.
250 * (But plan.qual is still applied before actually returning a tuple.)
251 * For an outer join, only joinquals are allowed to be used as the merge
252 * or hash condition of a merge or hash join.
259 List *joinqual; /* JOIN quals (in addition to plan.qual) */
263 * nest loop join node
266 typedef struct NestLoop
269 NestLoopState *nlstate;
276 typedef struct MergeJoin
280 MergeJoinState *mergestate;
284 * hash join (probe) node
287 typedef struct HashJoin
292 HashJoinState *hashjoinstate;
307 * use for queries with GROUP BY specified.
309 * If tuplePerGroup is true, one tuple (with group columns only) is
310 * returned for each group and NULL is returned when there are no more
311 * groups. Otherwise, all the tuples of a group are returned with a
312 * NULL returned at the end of each group. (see nodeGroup.c for details)
318 bool tuplePerGroup; /* what tuples to return (see above) */
319 int numCols; /* number of group columns */
320 AttrNumber *grpColIdx; /* indexes into the target list */
321 GroupState *grpstate;
325 * materialization node
328 typedef struct Material
331 MaterialState *matstate;
342 SortState *sortstate;
349 typedef struct Unique
352 int numCols; /* number of columns to check for
354 AttrNumber *uniqColIdx; /* indexes into the target list */
355 UniqueState *uniquestate;
362 typedef enum SetOpCmd
365 SETOPCMD_INTERSECT_ALL,
373 SetOpCmd cmd; /* what to do */
374 int numCols; /* number of columns to check for
376 AttrNumber *dupColIdx; /* indexes into the target list */
377 AttrNumber flagColIdx;
378 SetOpState *setopstate;
388 Node *limitOffset; /* OFFSET parameter, or NULL if none */
389 Node *limitCount; /* COUNT parameter, or NULL if none */
390 LimitState *limitstate;
401 HashState *hashstate;
405 /* -------------------
406 * Tee node information
408 * leftParent : the left parent of this node
409 * rightParent: the right parent of this node
410 * -------------------
418 char *teeTableName; /* the name of the table to materialize
420 List *rtentries; /* the range table for the plan below the
421 * Tee may be different than the parent
427 /* ---------------------
429 * ---------------------
431 typedef struct SubPlan
434 Plan *plan; /* subselect plan itself */
435 int plan_id; /* dummy thing because of we haven't equal
436 * funcs for plan nodes... actually, we
437 * could put *plan itself somewhere else
438 * (TopPlan node ?)... */
439 List *rtable; /* range table for subselect */
440 /* setParam and parParam are lists of integers (param IDs) */
441 List *setParam; /* non-correlated EXPR & EXISTS subqueries
442 * have to set some Params for paren Plan */
443 List *parParam; /* indices of corr. Vars from parent plan */
444 SubLink *sublink; /* SubLink node from parser; holds info
445 * about what to do with subselect's
449 * Remaining fields are working state for executor; not used in
452 bool needShutdown; /* TRUE = need to shutdown subplan */
453 HeapTuple curTuple; /* copy of most recent tuple from subplan */
456 #endif /* PLANNODES_H */