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.52 2001/10/28 06:26:07 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 */
85 * execution state data. Having Plan point to this, rather than the
86 * other way round, is 100% bogus.
88 EState *state; /* at execution time, state's of
89 * individual nodes point to one EState
90 * for the whole top-level plan */
92 struct Instrumentation *instrument; /* Optional runtime stats for this
96 * Common structural data for all Plan types. XXX chgParam is runtime
97 * data and should be in the EState, not here.
100 List *qual; /* implicitly-ANDed qual conditions */
101 struct Plan *lefttree;
102 struct Plan *righttree;
103 List *extParam; /* indices of _all_ _external_ PARAM_EXEC
104 * for this plan in global
105 * es_param_exec_vals. Params from
106 * setParam from initPlan-s are not
107 * included, but their execParam-s are
109 List *locParam; /* someones from setParam-s */
110 List *chgParam; /* list of changed ones from the above */
111 List *initPlan; /* Init Plan nodes (un-correlated expr
113 List *subPlan; /* Other SubPlan nodes */
116 * We really need in some TopPlan node to store range table and
117 * resultRelation from Query there and get rid of Query itself from
118 * Executor. Some other stuff like below could be put there, too.
120 int nParamExec; /* Number of them in entire query. This is
121 * to get Executor know about how many
122 * param_exec there are in query plan. */
126 * these are are defined to avoid confusion problems with "left"
127 * and "right" and "inner" and "outer". The convention is that
128 * the "left" plan is the "outer" plan and the "right" plan is
129 * the inner plan, but these make the code more readable.
132 #define innerPlan(node) (((Plan *)(node))->righttree)
133 #define outerPlan(node) (((Plan *)(node))->lefttree)
142 /* all plan nodes "derive" from the Plan structure by having the
143 Plan structure as the first field. This ensures that everything works
144 when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
145 when passed around generically in the executor */
150 * If no outer plan, evaluate a variable-free targetlist.
151 * If outer plan, return tuples from outer plan that satisfy
152 * given quals (we can also do a level of projection)
155 typedef struct Result
158 Node *resconstantqual;
159 ResultState *resstate;
164 * Generate the concatenation of the results of sub-plans.
166 * Append nodes are sometimes used to switch between several result relations
167 * (when the target of an UPDATE or DELETE is an inheritance set). Such a
168 * node will have isTarget true. The Append executor is then responsible
169 * for updating the executor state to point at the correct target relation
170 * whenever it switches subplans.
173 typedef struct Append
178 AppendState *appendstate;
189 Index scanrelid; /* relid is index into the range table */
190 CommonScanState *scanstate;
194 * sequential scan node
197 typedef Scan SeqScan;
203 typedef struct IndexScan
209 ScanDirection indxorderdir;
210 IndexScanState *indxstate;
217 typedef struct TidScan
222 TidScanState *tidstate;
228 * SubqueryScan is for scanning the output of a sub-query in the range table.
229 * We need a special plan node above the sub-query's plan as a place to switch
230 * execution contexts. Although we are not scanning a physical relation,
231 * we make this a descendant of Scan anyway for code-sharing purposes.
233 * Note: we store the sub-plan in the type-specific subplan field, not in
234 * the generic lefttree field as you might expect. This is because we do
235 * not want plan-tree-traversal routines to recurse into the subplan without
236 * knowing that they are changing Query contexts.
239 typedef struct SubqueryScan
254 * jointype: rule for joining tuples from left and right subtrees
255 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
256 * (plan.qual contains conditions that came from WHERE)
258 * When jointype is INNER, joinqual and plan.qual are semantically
259 * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
260 * only joinqual is used to determine whether a match has been found for
261 * the purpose of deciding whether to generate null-extended tuples.
262 * (But plan.qual is still applied before actually returning a tuple.)
263 * For an outer join, only joinquals are allowed to be used as the merge
264 * or hash condition of a merge or hash join.
271 List *joinqual; /* JOIN quals (in addition to plan.qual) */
275 * nest loop join node
278 typedef struct NestLoop
281 NestLoopState *nlstate;
288 typedef struct MergeJoin
292 MergeJoinState *mergestate;
296 * hash join (probe) node
299 typedef struct HashJoin
304 HashJoinState *hashjoinstate;
319 * use for queries with GROUP BY specified.
321 * If tuplePerGroup is true, one tuple (with group columns only) is
322 * returned for each group and NULL is returned when there are no more
323 * groups. Otherwise, all the tuples of a group are returned with a
324 * NULL returned at the end of each group. (see nodeGroup.c for details)
330 bool tuplePerGroup; /* what tuples to return (see above) */
331 int numCols; /* number of group columns */
332 AttrNumber *grpColIdx; /* indexes into the target list */
333 GroupState *grpstate;
337 * materialization node
340 typedef struct Material
343 MaterialState *matstate;
354 SortState *sortstate;
361 typedef struct Unique
364 int numCols; /* number of columns to check for
366 AttrNumber *uniqColIdx; /* indexes into the target list */
367 UniqueState *uniquestate;
374 typedef enum SetOpCmd
377 SETOPCMD_INTERSECT_ALL,
385 SetOpCmd cmd; /* what to do */
386 int numCols; /* number of columns to check for
388 AttrNumber *dupColIdx; /* indexes into the target list */
389 AttrNumber flagColIdx;
390 SetOpState *setopstate;
400 Node *limitOffset; /* OFFSET parameter, or NULL if none */
401 Node *limitCount; /* COUNT parameter, or NULL if none */
402 LimitState *limitstate;
413 HashState *hashstate;
417 /* -------------------
418 * Tee node information
420 * leftParent : the left parent of this node
421 * rightParent: the right parent of this node
422 * -------------------
430 char *teeTableName; /* the name of the table to materialize
432 List *rtentries; /* the range table for the plan below the
433 * Tee may be different than the parent
438 /* ---------------------
440 * ---------------------
442 typedef struct SubPlan
445 Plan *plan; /* subselect plan itself */
446 int plan_id; /* dummy thing because of we haven't equal
447 * funcs for plan nodes... actually, we
448 * could put *plan itself somewhere else
449 * (TopPlan node ?)... */
450 List *rtable; /* range table for subselect */
451 /* setParam and parParam are lists of integers (param IDs) */
452 List *setParam; /* non-correlated EXPR & EXISTS subqueries
453 * have to set some Params for paren Plan */
454 List *parParam; /* indices of corr. Vars from parent plan */
455 SubLink *sublink; /* SubLink node from parser; holds info
456 * about what to do with subselect's
460 * Remaining fields are working state for executor; not used in
463 bool needShutdown; /* TRUE = need to shutdown subplan */
464 HeapTuple curTuple; /* copy of most recent tuple from subplan */
467 #endif /* PLANNODES_H */