PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plannodes.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * plannodes.h
4  * definitions for query plan nodes
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/nodes/plannodes.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef PLANNODES_H
15 #define PLANNODES_H
16 
17 #include "access/sdir.h"
18 #include "lib/stringinfo.h"
19 #include "nodes/bitmapset.h"
20 #include "nodes/lockoptions.h"
21 #include "nodes/primnodes.h"
22 
23 
24 /* ----------------------------------------------------------------
25  * node definitions
26  * ----------------------------------------------------------------
27  */
28 
29 /* ----------------
30  * PlannedStmt node
31  *
32  * The output of the planner is a Plan tree headed by a PlannedStmt node.
33  * PlannedStmt holds the "one time" information needed by the executor.
34  *
35  * For simplicity in APIs, we also wrap utility statements in PlannedStmt
36  * nodes; in such cases, commandType == CMD_UTILITY, the statement itself
37  * is in the utilityStmt field, and the rest of the struct is mostly dummy.
38  * (We do use canSetTag, stmt_location, stmt_len, and possibly queryId.)
39  * ----------------
40  */
41 typedef struct PlannedStmt
42 {
44 
45  CmdType commandType; /* select|insert|update|delete|utility */
46 
47  uint32 queryId; /* query identifier (copied from Query) */
48 
49  bool hasReturning; /* is it insert|update|delete RETURNING? */
50 
51  bool hasModifyingCTE; /* has insert|update|delete in WITH? */
52 
53  bool canSetTag; /* do I set the command result tag? */
54 
55  bool transientPlan; /* redo plan when TransactionXmin changes? */
56 
57  bool dependsOnRole; /* is plan specific to current role? */
58 
59  bool parallelModeNeeded; /* parallel mode required to execute? */
60 
61  struct Plan *planTree; /* tree of Plan nodes */
62 
63  List *rtable; /* list of RangeTblEntry nodes */
64 
65  /* rtable indexes of target relations for INSERT/UPDATE/DELETE */
66  List *resultRelations; /* integer list of RT indexes, or NIL */
67 
68  List *subplans; /* Plan trees for SubPlan expressions */
69 
70  Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
71 
72  List *rowMarks; /* a list of PlanRowMark's */
73 
74  List *relationOids; /* OIDs of relations the plan depends on */
75 
76  List *invalItems; /* other dependencies, as PlanInvalItems */
77 
78  int nParamExec; /* number of PARAM_EXEC Params used */
79 
80  Node *utilityStmt; /* non-null if this is utility stmt */
81 
82  /* statement location in source string (copied from Query) */
83  int stmt_location; /* start location, or -1 if unknown */
84  int stmt_len; /* length in bytes; 0 means "rest of string" */
85 } PlannedStmt;
86 
87 /* macro for fetching the Plan associated with a SubPlan node */
88 #define exec_subplan_get_plan(plannedstmt, subplan) \
89  ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
90 
91 
92 /* ----------------
93  * Plan node
94  *
95  * All plan nodes "derive" from the Plan structure by having the
96  * Plan structure as the first field. This ensures that everything works
97  * when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
98  * when passed around generically in the executor)
99  *
100  * We never actually instantiate any Plan nodes; this is just the common
101  * abstract superclass for all Plan-type nodes.
102  * ----------------
103  */
104 typedef struct Plan
105 {
107 
108  /*
109  * estimated execution costs for plan (see costsize.c for more info)
110  */
111  Cost startup_cost; /* cost expended before fetching any tuples */
112  Cost total_cost; /* total cost (assuming all tuples fetched) */
113 
114  /*
115  * planner's estimate of result size of this plan step
116  */
117  double plan_rows; /* number of rows plan is expected to emit */
118  int plan_width; /* average row width in bytes */
119 
120  /*
121  * information needed for parallel query
122  */
123  bool parallel_aware; /* engage parallel-aware logic? */
124 
125  /*
126  * Common structural data for all Plan types.
127  */
128  int plan_node_id; /* unique across entire final plan tree */
129  List *targetlist; /* target list to be computed at this node */
130  List *qual; /* implicitly-ANDed qual conditions */
131  struct Plan *lefttree; /* input plan tree(s) */
132  struct Plan *righttree;
133  List *initPlan; /* Init Plan nodes (un-correlated expr
134  * subselects) */
135 
136  /*
137  * Information for management of parameter-change-driven rescanning
138  *
139  * extParam includes the paramIDs of all external PARAM_EXEC params
140  * affecting this plan node or its children. setParam params from the
141  * node's initPlans are not included, but their extParams are.
142  *
143  * allParam includes all the extParam paramIDs, plus the IDs of local
144  * params that affect the node (i.e., the setParams of its initplans).
145  * These are _all_ the PARAM_EXEC params that affect this node.
146  */
149 } Plan;
150 
151 /* ----------------
152  * these are defined to avoid confusion problems with "left"
153  * and "right" and "inner" and "outer". The convention is that
154  * the "left" plan is the "outer" plan and the "right" plan is
155  * the inner plan, but these make the code more readable.
156  * ----------------
157  */
158 #define innerPlan(node) (((Plan *)(node))->righttree)
159 #define outerPlan(node) (((Plan *)(node))->lefttree)
160 
161 
162 /* ----------------
163  * Result node -
164  * If no outer plan, evaluate a variable-free targetlist.
165  * If outer plan, return tuples from outer plan (after a level of
166  * projection as shown by targetlist).
167  *
168  * If resconstantqual isn't NULL, it represents a one-time qualification
169  * test (i.e., one that doesn't depend on any variables from the outer plan,
170  * so needs to be evaluated only once).
171  * ----------------
172  */
173 typedef struct Result
174 {
177 } Result;
178 
179 /* ----------------
180  * ProjectSet node -
181  * Apply a projection that includes set-returning functions to the
182  * output tuples of the outer plan.
183  * ----------------
184  */
185 typedef struct ProjectSet
186 {
188 } ProjectSet;
189 
190 /* ----------------
191  * ModifyTable node -
192  * Apply rows produced by subplan(s) to result table(s),
193  * by inserting, updating, or deleting.
194  *
195  * Note that rowMarks and epqParam are presumed to be valid for all the
196  * subplan(s); they can't contain any info that varies across subplans.
197  * ----------------
198  */
199 typedef struct ModifyTable
200 {
202  CmdType operation; /* INSERT, UPDATE, or DELETE */
203  bool canSetTag; /* do we set the command tag/es_processed? */
204  Index nominalRelation; /* Parent RT index for use of EXPLAIN */
205  List *resultRelations; /* integer list of RT indexes */
206  int resultRelIndex; /* index of first resultRel in plan's list */
207  List *plans; /* plan(s) producing source data */
208  List *withCheckOptionLists; /* per-target-table WCO lists */
209  List *returningLists; /* per-target-table RETURNING tlists */
210  List *fdwPrivLists; /* per-target-table FDW private data lists */
211  Bitmapset *fdwDirectModifyPlans; /* indices of FDW DM plans */
212  List *rowMarks; /* PlanRowMarks (non-locking only) */
213  int epqParam; /* ID of Param for EvalPlanQual re-eval */
214  OnConflictAction onConflictAction; /* ON CONFLICT action */
215  List *arbiterIndexes; /* List of ON CONFLICT arbiter index OIDs */
216  List *onConflictSet; /* SET for INSERT ON CONFLICT DO UPDATE */
217  Node *onConflictWhere; /* WHERE for ON CONFLICT UPDATE */
218  Index exclRelRTI; /* RTI of the EXCLUDED pseudo relation */
219  List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
220 } ModifyTable;
221 
222 /* ----------------
223  * Append node -
224  * Generate the concatenation of the results of sub-plans.
225  * ----------------
226  */
227 typedef struct Append
228 {
231 } Append;
232 
233 /* ----------------
234  * MergeAppend node -
235  * Merge the results of pre-sorted sub-plans to preserve the ordering.
236  * ----------------
237  */
238 typedef struct MergeAppend
239 {
242  /* remaining fields are just like the sort-key info in struct Sort */
243  int numCols; /* number of sort-key columns */
244  AttrNumber *sortColIdx; /* their indexes in the target list */
245  Oid *sortOperators; /* OIDs of operators to sort them by */
246  Oid *collations; /* OIDs of collations */
247  bool *nullsFirst; /* NULLS FIRST/LAST directions */
248 } MergeAppend;
249 
250 /* ----------------
251  * RecursiveUnion node -
252  * Generate a recursive union of two subplans.
253  *
254  * The "outer" subplan is always the non-recursive term, and the "inner"
255  * subplan is the recursive term.
256  * ----------------
257  */
258 typedef struct RecursiveUnion
259 {
261  int wtParam; /* ID of Param representing work table */
262  /* Remaining fields are zero/null in UNION ALL case */
263  int numCols; /* number of columns to check for
264  * duplicate-ness */
265  AttrNumber *dupColIdx; /* their indexes in the target list */
266  Oid *dupOperators; /* equality operators to compare with */
267  long numGroups; /* estimated number of groups in input */
269 
270 /* ----------------
271  * BitmapAnd node -
272  * Generate the intersection of the results of sub-plans.
273  *
274  * The subplans must be of types that yield tuple bitmaps. The targetlist
275  * and qual fields of the plan are unused and are always NIL.
276  * ----------------
277  */
278 typedef struct BitmapAnd
279 {
282 } BitmapAnd;
283 
284 /* ----------------
285  * BitmapOr node -
286  * Generate the union of the results of sub-plans.
287  *
288  * The subplans must be of types that yield tuple bitmaps. The targetlist
289  * and qual fields of the plan are unused and are always NIL.
290  * ----------------
291  */
292 typedef struct BitmapOr
293 {
296 } BitmapOr;
297 
298 /*
299  * ==========
300  * Scan nodes
301  * ==========
302  */
303 typedef struct Scan
304 {
306  Index scanrelid; /* relid is index into the range table */
307 } Scan;
308 
309 /* ----------------
310  * sequential scan node
311  * ----------------
312  */
313 typedef Scan SeqScan;
314 
315 /* ----------------
316  * table sample scan node
317  * ----------------
318  */
319 typedef struct SampleScan
320 {
322  /* use struct pointer to avoid including parsenodes.h here */
324 } SampleScan;
325 
326 /* ----------------
327  * index scan node
328  *
329  * indexqualorig is an implicitly-ANDed list of index qual expressions, each
330  * in the same form it appeared in the query WHERE condition. Each should
331  * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
332  * The indexkey is a Var or expression referencing column(s) of the index's
333  * base table. The comparisonval might be any expression, but it won't use
334  * any columns of the base table. The expressions are ordered by index
335  * column position (but items referencing the same index column can appear
336  * in any order). indexqualorig is used at runtime only if we have to recheck
337  * a lossy indexqual.
338  *
339  * indexqual has the same form, but the expressions have been commuted if
340  * necessary to put the indexkeys on the left, and the indexkeys are replaced
341  * by Var nodes identifying the index columns (their varno is INDEX_VAR and
342  * their varattno is the index column number).
343  *
344  * indexorderbyorig is similarly the original form of any ORDER BY expressions
345  * that are being implemented by the index, while indexorderby is modified to
346  * have index column Vars on the left-hand side. Here, multiple expressions
347  * must appear in exactly the ORDER BY order, and this is not necessarily the
348  * index column order. Only the expressions are provided, not the auxiliary
349  * sort-order information from the ORDER BY SortGroupClauses; it's assumed
350  * that the sort ordering is fully determinable from the top-level operators.
351  * indexorderbyorig is used at runtime to recheck the ordering, if the index
352  * cannot calculate an accurate ordering. It is also needed for EXPLAIN.
353  *
354  * indexorderbyops is a list of the OIDs of the operators used to sort the
355  * ORDER BY expressions. This is used together with indexorderbyorig to
356  * recheck ordering at run time. (Note that indexorderby, indexorderbyorig,
357  * and indexorderbyops are used for amcanorderbyop cases, not amcanorder.)
358  *
359  * indexorderdir specifies the scan ordering, for indexscans on amcanorder
360  * indexes (for other indexes it should be "don't care").
361  * ----------------
362  */
363 typedef struct IndexScan
364 {
366  Oid indexid; /* OID of index to scan */
367  List *indexqual; /* list of index quals (usually OpExprs) */
368  List *indexqualorig; /* the same in original form */
369  List *indexorderby; /* list of index ORDER BY exprs */
370  List *indexorderbyorig; /* the same in original form */
371  List *indexorderbyops; /* OIDs of sort ops for ORDER BY exprs */
372  ScanDirection indexorderdir; /* forward or backward or don't care */
373 } IndexScan;
374 
375 /* ----------------
376  * index-only scan node
377  *
378  * IndexOnlyScan is very similar to IndexScan, but it specifies an
379  * index-only scan, in which the data comes from the index not the heap.
380  * Because of this, *all* Vars in the plan node's targetlist, qual, and
381  * index expressions reference index columns and have varno = INDEX_VAR.
382  * Hence we do not need separate indexqualorig and indexorderbyorig lists,
383  * since their contents would be equivalent to indexqual and indexorderby.
384  *
385  * To help EXPLAIN interpret the index Vars for display, we provide
386  * indextlist, which represents the contents of the index as a targetlist
387  * with one TLE per index column. Vars appearing in this list reference
388  * the base table, and this is the only field in the plan node that may
389  * contain such Vars.
390  * ----------------
391  */
392 typedef struct IndexOnlyScan
393 {
395  Oid indexid; /* OID of index to scan */
396  List *indexqual; /* list of index quals (usually OpExprs) */
397  List *indexorderby; /* list of index ORDER BY exprs */
398  List *indextlist; /* TargetEntry list describing index's cols */
399  ScanDirection indexorderdir; /* forward or backward or don't care */
400 } IndexOnlyScan;
401 
402 /* ----------------
403  * bitmap index scan node
404  *
405  * BitmapIndexScan delivers a bitmap of potential tuple locations;
406  * it does not access the heap itself. The bitmap is used by an
407  * ancestor BitmapHeapScan node, possibly after passing through
408  * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
409  * the results of other BitmapIndexScans.
410  *
411  * The fields have the same meanings as for IndexScan, except we don't
412  * store a direction flag because direction is uninteresting.
413  *
414  * In a BitmapIndexScan plan node, the targetlist and qual fields are
415  * not used and are always NIL. The indexqualorig field is unused at
416  * run time too, but is saved for the benefit of EXPLAIN.
417  * ----------------
418  */
419 typedef struct BitmapIndexScan
420 {
422  Oid indexid; /* OID of index to scan */
423  List *indexqual; /* list of index quals (OpExprs) */
424  List *indexqualorig; /* the same in original form */
426 
427 /* ----------------
428  * bitmap sequential scan node
429  *
430  * This needs a copy of the qual conditions being used by the input index
431  * scans because there are various cases where we need to recheck the quals;
432  * for example, when the bitmap is lossy about the specific rows on a page
433  * that meet the index condition.
434  * ----------------
435  */
436 typedef struct BitmapHeapScan
437 {
439  List *bitmapqualorig; /* index quals, in standard expr form */
441 
442 /* ----------------
443  * tid scan node
444  *
445  * tidquals is an implicitly OR'ed list of qual expressions of the form
446  * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)".
447  * ----------------
448  */
449 typedef struct TidScan
450 {
452  List *tidquals; /* qual(s) involving CTID = something */
453 } TidScan;
454 
455 /* ----------------
456  * subquery scan node
457  *
458  * SubqueryScan is for scanning the output of a sub-query in the range table.
459  * We often need an extra plan node above the sub-query's plan to perform
460  * expression evaluations (which we can't push into the sub-query without
461  * risking changing its semantics). Although we are not scanning a physical
462  * relation, we make this a descendant of Scan anyway for code-sharing
463  * purposes.
464  *
465  * Note: we store the sub-plan in the type-specific subplan field, not in
466  * the generic lefttree field as you might expect. This is because we do
467  * not want plan-tree-traversal routines to recurse into the subplan without
468  * knowing that they are changing Query contexts.
469  * ----------------
470  */
471 typedef struct SubqueryScan
472 {
475 } SubqueryScan;
476 
477 /* ----------------
478  * FunctionScan node
479  * ----------------
480  */
481 typedef struct FunctionScan
482 {
484  List *functions; /* list of RangeTblFunction nodes */
485  bool funcordinality; /* WITH ORDINALITY */
486 } FunctionScan;
487 
488 /* ----------------
489  * ValuesScan node
490  * ----------------
491  */
492 typedef struct ValuesScan
493 {
495  List *values_lists; /* list of expression lists */
496 } ValuesScan;
497 
498 /* ----------------
499  * CteScan node
500  * ----------------
501  */
502 typedef struct CteScan
503 {
505  int ctePlanId; /* ID of init SubPlan for CTE */
506  int cteParam; /* ID of Param representing CTE output */
507 } CteScan;
508 
509 /* ----------------
510  * WorkTableScan node
511  * ----------------
512  */
513 typedef struct WorkTableScan
514 {
516  int wtParam; /* ID of Param representing work table */
517 } WorkTableScan;
518 
519 /* ----------------
520  * ForeignScan node
521  *
522  * fdw_exprs and fdw_private are both under the control of the foreign-data
523  * wrapper, but fdw_exprs is presumed to contain expression trees and will
524  * be post-processed accordingly by the planner; fdw_private won't be.
525  * Note that everything in both lists must be copiable by copyObject().
526  * One way to store an arbitrary blob of bytes is to represent it as a bytea
527  * Const. Usually, though, you'll be better off choosing a representation
528  * that can be dumped usefully by nodeToString().
529  *
530  * fdw_scan_tlist is a targetlist describing the contents of the scan tuple
531  * returned by the FDW; it can be NIL if the scan tuple matches the declared
532  * rowtype of the foreign table, which is the normal case for a simple foreign
533  * table scan. (If the plan node represents a foreign join, fdw_scan_tlist
534  * is required since there is no rowtype available from the system catalogs.)
535  * When fdw_scan_tlist is provided, Vars in the node's tlist and quals must
536  * have varno INDEX_VAR, and their varattnos correspond to resnos in the
537  * fdw_scan_tlist (which are also column numbers in the actual scan tuple).
538  * fdw_scan_tlist is never actually executed; it just holds expression trees
539  * describing what is in the scan tuple's columns.
540  *
541  * fdw_recheck_quals should contain any quals which the core system passed to
542  * the FDW but which were not added to scan.plan.qual; that is, it should
543  * contain the quals being checked remotely. This is needed for correct
544  * behavior during EvalPlanQual rechecks.
545  *
546  * When the plan node represents a foreign join, scan.scanrelid is zero and
547  * fs_relids must be consulted to identify the join relation. (fs_relids
548  * is valid for simple scans as well, but will always match scan.scanrelid.)
549  * ----------------
550  */
551 typedef struct ForeignScan
552 {
554  CmdType operation; /* SELECT/INSERT/UPDATE/DELETE */
555  Oid fs_server; /* OID of foreign server */
556  List *fdw_exprs; /* expressions that FDW may evaluate */
557  List *fdw_private; /* private data for FDW */
558  List *fdw_scan_tlist; /* optional tlist describing scan tuple */
559  List *fdw_recheck_quals; /* original quals not in
560  * scan.plan.qual */
561  Bitmapset *fs_relids; /* RTIs generated by this scan */
562  bool fsSystemCol; /* true if any "system column" is needed */
563 } ForeignScan;
564 
565 /* ----------------
566  * CustomScan node
567  *
568  * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist,
569  * and fs_relids fields apply equally to CustomScan's custom_exprs,
570  * custom_private, custom_scan_tlist, and custom_relids fields. The
571  * convention of setting scan.scanrelid to zero for joins applies as well.
572  *
573  * Note that since Plan trees can be copied, custom scan providers *must*
574  * fit all plan data they need into those fields; embedding CustomScan in
575  * a larger struct will not work.
576  * ----------------
577  */
578 struct CustomScanMethods;
579 
580 typedef struct CustomScan
581 {
583  uint32 flags; /* mask of CUSTOMPATH_* flags, see
584  * nodes/extensible.h */
585  List *custom_plans; /* list of Plan nodes, if any */
586  List *custom_exprs; /* expressions that custom code may evaluate */
587  List *custom_private; /* private data for custom code */
588  List *custom_scan_tlist; /* optional tlist describing scan
589  * tuple */
590  Bitmapset *custom_relids; /* RTIs generated by this scan */
591  const struct CustomScanMethods *methods;
592 } CustomScan;
593 
594 /*
595  * ==========
596  * Join nodes
597  * ==========
598  */
599 
600 /* ----------------
601  * Join node
602  *
603  * jointype: rule for joining tuples from left and right subtrees
604  * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
605  * (plan.qual contains conditions that came from WHERE)
606  *
607  * When jointype is INNER, joinqual and plan.qual are semantically
608  * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
609  * only joinqual is used to determine whether a match has been found for
610  * the purpose of deciding whether to generate null-extended tuples.
611  * (But plan.qual is still applied before actually returning a tuple.)
612  * For an outer join, only joinquals are allowed to be used as the merge
613  * or hash condition of a merge or hash join.
614  * ----------------
615  */
616 typedef struct Join
617 {
620  List *joinqual; /* JOIN quals (in addition to plan.qual) */
621 } Join;
622 
623 /* ----------------
624  * nest loop join node
625  *
626  * The nestParams list identifies any executor Params that must be passed
627  * into execution of the inner subplan carrying values from the current row
628  * of the outer subplan. Currently we restrict these values to be simple
629  * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
630  * creation, the paramval can actually be a PlaceHolderVar expression; but it
631  * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
632  * ----------------
633  */
634 typedef struct NestLoop
635 {
637  List *nestParams; /* list of NestLoopParam nodes */
638 } NestLoop;
639 
640 typedef struct NestLoopParam
641 {
643  int paramno; /* number of the PARAM_EXEC Param to set */
644  Var *paramval; /* outer-relation Var to assign to Param */
645 } NestLoopParam;
646 
647 /* ----------------
648  * merge join node
649  *
650  * The expected ordering of each mergeable column is described by a btree
651  * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
652  * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
653  * of each mergeclause may be of different datatypes, but they are ordered the
654  * same way according to the common opfamily and collation. The operator in
655  * each mergeclause must be an equality operator of the indicated opfamily.
656  * ----------------
657  */
658 typedef struct MergeJoin
659 {
661  List *mergeclauses; /* mergeclauses as expression trees */
662  /* these are arrays, but have the same length as the mergeclauses list: */
663  Oid *mergeFamilies; /* per-clause OIDs of btree opfamilies */
664  Oid *mergeCollations; /* per-clause OIDs of collations */
665  int *mergeStrategies; /* per-clause ordering (ASC or DESC) */
666  bool *mergeNullsFirst; /* per-clause nulls ordering */
667 } MergeJoin;
668 
669 /* ----------------
670  * hash join node
671  * ----------------
672  */
673 typedef struct HashJoin
674 {
677 } HashJoin;
678 
679 /* ----------------
680  * materialization node
681  * ----------------
682  */
683 typedef struct Material
684 {
686 } Material;
687 
688 /* ----------------
689  * sort node
690  * ----------------
691  */
692 typedef struct Sort
693 {
695  int numCols; /* number of sort-key columns */
696  AttrNumber *sortColIdx; /* their indexes in the target list */
697  Oid *sortOperators; /* OIDs of operators to sort them by */
698  Oid *collations; /* OIDs of collations */
699  bool *nullsFirst; /* NULLS FIRST/LAST directions */
700 } Sort;
701 
702 /* ---------------
703  * group node -
704  * Used for queries with GROUP BY (but no aggregates) specified.
705  * The input must be presorted according to the grouping columns.
706  * ---------------
707  */
708 typedef struct Group
709 {
711  int numCols; /* number of grouping columns */
712  AttrNumber *grpColIdx; /* their indexes in the target list */
713  Oid *grpOperators; /* equality operators to compare with */
714 } Group;
715 
716 /* ---------------
717  * aggregate node
718  *
719  * An Agg node implements plain or grouped aggregation. For grouped
720  * aggregation, we can work with presorted input or unsorted input;
721  * the latter strategy uses an internal hashtable.
722  *
723  * Notice the lack of any direct info about the aggregate functions to be
724  * computed. They are found by scanning the node's tlist and quals during
725  * executor startup. (It is possible that there are no aggregate functions;
726  * this could happen if they get optimized away by constant-folding, or if
727  * we are using the Agg node to implement hash-based grouping.)
728  * ---------------
729  */
730 typedef struct Agg
731 {
733  AggStrategy aggstrategy; /* basic strategy, see nodes.h */
734  AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
735  int numCols; /* number of grouping columns */
736  AttrNumber *grpColIdx; /* their indexes in the target list */
737  Oid *grpOperators; /* equality operators to compare with */
738  long numGroups; /* estimated number of groups in input */
739  Bitmapset *aggParams; /* IDs of Params used in Aggref inputs */
740  /* Note: planner provides numGroups & aggParams only in AGG_HASHED case */
741  List *groupingSets; /* grouping sets to use */
742  List *chain; /* chained Agg/Sort nodes */
743 } Agg;
744 
745 /* ----------------
746  * window aggregate node
747  * ----------------
748  */
749 typedef struct WindowAgg
750 {
752  Index winref; /* ID referenced by window functions */
753  int partNumCols; /* number of columns in partition clause */
754  AttrNumber *partColIdx; /* their indexes in the target list */
755  Oid *partOperators; /* equality operators for partition columns */
756  int ordNumCols; /* number of columns in ordering clause */
757  AttrNumber *ordColIdx; /* their indexes in the target list */
758  Oid *ordOperators; /* equality operators for ordering columns */
759  int frameOptions; /* frame_clause options, see WindowDef */
760  Node *startOffset; /* expression for starting bound, if any */
761  Node *endOffset; /* expression for ending bound, if any */
762 } WindowAgg;
763 
764 /* ----------------
765  * unique node
766  * ----------------
767  */
768 typedef struct Unique
769 {
771  int numCols; /* number of columns to check for uniqueness */
772  AttrNumber *uniqColIdx; /* their indexes in the target list */
773  Oid *uniqOperators; /* equality operators to compare with */
774 } Unique;
775 
776 /* ------------
777  * gather node
778  * ------------
779  */
780 typedef struct Gather
781 {
785  bool invisible; /* suppress EXPLAIN display (for testing)? */
786 } Gather;
787 
788 /* ----------------
789  * hash build node
790  *
791  * If the executor is supposed to try to apply skew join optimization, then
792  * skewTable/skewColumn/skewInherit identify the outer relation's join key
793  * column, from which the relevant MCV statistics can be fetched. Also, its
794  * type information is provided to save a lookup.
795  * ----------------
796  */
797 typedef struct Hash
798 {
800  Oid skewTable; /* outer join key's table OID, or InvalidOid */
801  AttrNumber skewColumn; /* outer join key's column #, or zero */
802  bool skewInherit; /* is outer join rel an inheritance tree? */
803  Oid skewColType; /* datatype of the outer key column */
804  int32 skewColTypmod; /* typmod of the outer key column */
805  /* all other info is in the parent HashJoin node */
806 } Hash;
807 
808 /* ----------------
809  * setop node
810  * ----------------
811  */
812 typedef struct SetOp
813 {
815  SetOpCmd cmd; /* what to do, see nodes.h */
816  SetOpStrategy strategy; /* how to do it, see nodes.h */
817  int numCols; /* number of columns to check for
818  * duplicate-ness */
819  AttrNumber *dupColIdx; /* their indexes in the target list */
820  Oid *dupOperators; /* equality operators to compare with */
821  AttrNumber flagColIdx; /* where is the flag column, if any */
822  int firstFlag; /* flag value for first input relation */
823  long numGroups; /* estimated number of groups in input */
824 } SetOp;
825 
826 /* ----------------
827  * lock-rows node
828  *
829  * rowMarks identifies the rels to be locked by this node; it should be
830  * a subset of the rowMarks listed in the top-level PlannedStmt.
831  * epqParam is a Param that all scan nodes below this one must depend on.
832  * It is used to force re-evaluation of the plan during EvalPlanQual.
833  * ----------------
834  */
835 typedef struct LockRows
836 {
838  List *rowMarks; /* a list of PlanRowMark's */
839  int epqParam; /* ID of Param for EvalPlanQual re-eval */
840 } LockRows;
841 
842 /* ----------------
843  * limit node
844  *
845  * Note: as of Postgres 8.2, the offset and count expressions are expected
846  * to yield int8, rather than int4 as before.
847  * ----------------
848  */
849 typedef struct Limit
850 {
852  Node *limitOffset; /* OFFSET parameter, or NULL if none */
853  Node *limitCount; /* COUNT parameter, or NULL if none */
854 } Limit;
855 
856 
857 /*
858  * RowMarkType -
859  * enums for types of row-marking operations
860  *
861  * The first four of these values represent different lock strengths that
862  * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
863  * We support these on regular tables, as well as on foreign tables whose FDWs
864  * report support for late locking. For other foreign tables, any locking
865  * that might be done for such requests must happen during the initial row
866  * fetch; their FDWs provide no mechanism for going back to lock a row later.
867  * This means that the semantics will be a bit different than for a local
868  * table; in particular we are likely to lock more rows than would be locked
869  * locally, since remote rows will be locked even if they then fail
870  * locally-checked restriction or join quals. However, the prospect of
871  * doing a separate remote query to lock each selected row is usually pretty
872  * unappealing, so early locking remains a credible design choice for FDWs.
873  *
874  * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely
875  * identify all the source rows, not only those from the target relations, so
876  * that we can perform EvalPlanQual rechecking at need. For plain tables we
877  * can just fetch the TID, much as for a target relation; this case is
878  * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
879  * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
880  * pretty inefficient, since most of the time we'll never need the data; but
881  * fortunately the overhead is usually not performance-critical in practice.
882  * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
883  * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
884  * (Again, this probably doesn't make sense if a physical remote fetch is
885  * needed, but for FDWs that map to local storage it might be credible.)
886  */
887 typedef enum RowMarkType
888 {
889  ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
890  ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
891  ROW_MARK_SHARE, /* obtain shared tuple lock */
892  ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
893  ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
894  ROW_MARK_COPY /* physically copy the row value */
895 } RowMarkType;
896 
897 #define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
898 
899 /*
900  * PlanRowMark -
901  * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
902  *
903  * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate
904  * PlanRowMark node for each non-target relation in the query. Relations that
905  * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
906  * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
907  *
908  * Initially all PlanRowMarks have rti == prti and isParent == false.
909  * When the planner discovers that a relation is the root of an inheritance
910  * tree, it sets isParent true, and adds an additional PlanRowMark to the
911  * list for each child relation (including the target rel itself in its role
912  * as a child). The child entries have rti == child rel's RT index and
913  * prti == parent's RT index, and can therefore be recognized as children by
914  * the fact that prti != rti. The parent's allMarkTypes field gets the OR
915  * of (1<<markType) across all its children (this definition allows children
916  * to use different markTypes).
917  *
918  * The planner also adds resjunk output columns to the plan that carry
919  * information sufficient to identify the locked or fetched rows. When
920  * markType != ROW_MARK_COPY, these columns are named
921  * tableoid%u OID of table
922  * ctid%u TID of row
923  * The tableoid column is only present for an inheritance hierarchy.
924  * When markType == ROW_MARK_COPY, there is instead a single column named
925  * wholerow%u whole-row value of relation
926  * (An inheritance hierarchy could have all three resjunk output columns,
927  * if some children use a different markType than others.)
928  * In all three cases, %u represents the rowmark ID number (rowmarkId).
929  * This number is unique within a plan tree, except that child relation
930  * entries copy their parent's rowmarkId. (Assigning unique numbers
931  * means we needn't renumber rowmarkIds when flattening subqueries, which
932  * would require finding and renaming the resjunk columns as well.)
933  * Note this means that all tables in an inheritance hierarchy share the
934  * same resjunk column names. However, in an inherited UPDATE/DELETE the
935  * columns could have different physical column numbers in each subplan.
936  */
937 typedef struct PlanRowMark
938 {
940  Index rti; /* range table index of markable relation */
941  Index prti; /* range table index of parent relation */
942  Index rowmarkId; /* unique identifier for resjunk columns */
943  RowMarkType markType; /* see enum above */
944  int allMarkTypes; /* OR of (1<<markType) for all children */
945  LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */
946  LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED options */
947  bool isParent; /* true if this is a "dummy" parent entry */
948 } PlanRowMark;
949 
950 
951 /*
952  * Plan invalidation info
953  *
954  * We track the objects on which a PlannedStmt depends in two ways:
955  * relations are recorded as a simple list of OIDs, and everything else
956  * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
957  * to be used with the syscache invalidation mechanism, so it identifies a
958  * system catalog entry by cache ID and hash value.
959  */
960 typedef struct PlanInvalItem
961 {
963  int cacheId; /* a syscache ID, see utils/syscache.h */
964  uint32 hashValue; /* hash value of object's cache lookup key */
965 } PlanInvalItem;
966 
967 #endif /* PLANNODES_H */
int numCols
Definition: plannodes.h:771
struct BitmapAnd BitmapAnd
Oid skewTable
Definition: plannodes.h:800
bool dependsOnRole
Definition: plannodes.h:57
List * bitmapplans
Definition: plannodes.h:281
int ordNumCols
Definition: plannodes.h:756
struct NestLoopParam NestLoopParam
Plan plan
Definition: plannodes.h:175
int numCols
Definition: plannodes.h:735
List * qual
Definition: plannodes.h:130
List * arbiterIndexes
Definition: plannodes.h:215
double plan_rows
Definition: plannodes.h:117
ScanDirection indexorderdir
Definition: plannodes.h:372
SetOpStrategy strategy
Definition: plannodes.h:816
Plan plan
Definition: plannodes.h:305
bool skewInherit
Definition: plannodes.h:802
Bitmapset * fdwDirectModifyPlans
Definition: plannodes.h:211
uint32 queryId
Definition: plannodes.h:47
SetOpCmd cmd
Definition: plannodes.h:815
Plan plan
Definition: plannodes.h:851
Index nominalRelation
Definition: plannodes.h:204
RowMarkType markType
Definition: plannodes.h:943
struct Sort Sort
Index scanrelid
Definition: plannodes.h:306
AttrNumber * grpColIdx
Definition: plannodes.h:736
List * nestParams
Definition: plannodes.h:637
struct ModifyTable ModifyTable
Oid fs_server
Definition: plannodes.h:555
Plan plan
Definition: plannodes.h:837
struct SubqueryScan SubqueryScan
long numGroups
Definition: plannodes.h:823
Plan plan
Definition: plannodes.h:694
List * withCheckOptionLists
Definition: plannodes.h:208
Oid * collations
Definition: plannodes.h:246
List * functions
Definition: plannodes.h:484
int resultRelIndex
Definition: plannodes.h:206
struct BitmapHeapScan BitmapHeapScan
List * hashclauses
Definition: plannodes.h:676
List * relationOids
Definition: plannodes.h:74
List * indexqual
Definition: plannodes.h:423
List * fdw_exprs
Definition: plannodes.h:556
struct Hash Hash
AttrNumber * ordColIdx
Definition: plannodes.h:757
List * tidquals
Definition: plannodes.h:452
List * fdw_private
Definition: plannodes.h:557
struct FunctionScan FunctionScan
int plan_node_id
Definition: plannodes.h:128
List * indexqualorig
Definition: plannodes.h:368
NodeTag type
Definition: plannodes.h:642
struct TableSampleClause * tablesample
Definition: plannodes.h:323
NodeTag type
Definition: plannodes.h:939
struct Limit Limit
Definition: nodes.h:508
Oid skewColType
Definition: plannodes.h:803
List * custom_exprs
Definition: plannodes.h:586
struct HashJoin HashJoin
bool * nullsFirst
Definition: plannodes.h:699
Index prti
Definition: plannodes.h:941
int epqParam
Definition: plannodes.h:839
AttrNumber * dupColIdx
Definition: plannodes.h:819
bool canSetTag
Definition: plannodes.h:203
struct Scan Scan
List * values_lists
Definition: plannodes.h:495
List * fdw_scan_tlist
Definition: plannodes.h:558
struct Join Join
struct Append Append
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
struct Gather Gather
Definition: primnodes.h:141
Index rowmarkId
Definition: plannodes.h:942
LockWaitPolicy waitPolicy
Definition: plannodes.h:946
Scan scan
Definition: plannodes.h:494
List * custom_plans
Definition: plannodes.h:585
bool transientPlan
Definition: plannodes.h:55
Node * limitOffset
Definition: plannodes.h:852
struct IndexOnlyScan IndexOnlyScan
int numCols
Definition: plannodes.h:817
SetOpStrategy
Definition: nodes.h:778
int stmt_len
Definition: plannodes.h:84
Oid * ordOperators
Definition: plannodes.h:758
CmdType operation
Definition: plannodes.h:554
List * plans
Definition: plannodes.h:207
Join join
Definition: plannodes.h:675
Oid * sortOperators
Definition: plannodes.h:697
NodeTag type
Definition: plannodes.h:106
Oid indexid
Definition: plannodes.h:366
struct Agg Agg
struct CteScan CteScan
signed int int32
Definition: c.h:253
List * onConflictSet
Definition: plannodes.h:216
struct Plan * planTree
Definition: plannodes.h:61
JoinType
Definition: nodes.h:665
List * invalItems
Definition: plannodes.h:76
struct WindowAgg WindowAgg
struct WorkTableScan WorkTableScan
List * resultRelations
Definition: plannodes.h:205
List * mergeclauses
Definition: plannodes.h:661
struct BitmapIndexScan BitmapIndexScan
struct NestLoop NestLoop
Oid * uniqOperators
Definition: plannodes.h:773
List * appendplans
Definition: plannodes.h:230
struct IndexScan IndexScan
Node * startOffset
Definition: plannodes.h:760
JoinType jointype
Definition: plannodes.h:619
struct ForeignScan ForeignScan
Node * resconstantqual
Definition: plannodes.h:176
int nParamExec
Definition: plannodes.h:78
List * rowMarks
Definition: plannodes.h:212
struct Plan * righttree
Definition: plannodes.h:132
AggStrategy aggstrategy
Definition: plannodes.h:733
Var * paramval
Definition: plannodes.h:644
Join join
Definition: plannodes.h:636
int cteParam
Definition: plannodes.h:506
List * custom_private
Definition: plannodes.h:587
List * indexorderbyorig
Definition: plannodes.h:370
Plan plan
Definition: plannodes.h:782
AttrNumber flagColIdx
Definition: plannodes.h:821
bool single_copy
Definition: plannodes.h:784
Scan scan
Definition: plannodes.h:321
Scan scan
Definition: plannodes.h:504
Node * limitCount
Definition: plannodes.h:853
Scan scan
Definition: plannodes.h:365
Oid * dupOperators
Definition: plannodes.h:820
AttrNumber * dupColIdx
Definition: plannodes.h:265
struct PlanRowMark PlanRowMark
struct Result Result
int stmt_location
Definition: plannodes.h:83
Bitmapset * aggParams
Definition: plannodes.h:739
int ctePlanId
Definition: plannodes.h:505
Cost startup_cost
Definition: plannodes.h:111
struct Material Material
bool hasReturning
Definition: plannodes.h:49
AttrNumber skewColumn
Definition: plannodes.h:801
Node * endOffset
Definition: plannodes.h:761
struct MergeJoin MergeJoin
List * fdwPrivLists
Definition: plannodes.h:210
ScanDirection
Definition: sdir.h:22
const struct CustomScanMethods * methods
Definition: plannodes.h:591
Node * utilityStmt
Definition: plannodes.h:80
bool parallel_aware
Definition: plannodes.h:123
int allMarkTypes
Definition: plannodes.h:944
unsigned int uint32
Definition: c.h:265
ScanDirection indexorderdir
Definition: plannodes.h:399
int partNumCols
Definition: plannodes.h:753
struct ValuesScan ValuesScan
Bitmapset * allParam
Definition: plannodes.h:148
List * fdw_recheck_quals
Definition: plannodes.h:559
struct LockRows LockRows
int numCols
Definition: plannodes.h:711
struct ProjectSet ProjectSet
struct SetOp SetOp
List * indexqual
Definition: plannodes.h:367
List * bitmapqualorig
Definition: plannodes.h:439
NodeTag type
Definition: plannodes.h:43
Plan plan
Definition: plannodes.h:294
AttrNumber * uniqColIdx
Definition: plannodes.h:772
Plan plan
Definition: plannodes.h:814
int numCols
Definition: plannodes.h:695
Plan plan
Definition: plannodes.h:732
Scan scan
Definition: plannodes.h:582
List * bitmapplans
Definition: plannodes.h:295
Plan plan
Definition: plannodes.h:685
bool canSetTag
Definition: plannodes.h:53
LockClauseStrength
Definition: lockoptions.h:21
CmdType commandType
Definition: plannodes.h:45
Plan plan
Definition: plannodes.h:770
Scan SeqScan
Definition: plannodes.h:313
NodeTag type
Definition: plannodes.h:962
Oid * mergeFamilies
Definition: plannodes.h:663
Oid * mergeCollations
Definition: plannodes.h:664
List * groupingSets
Definition: plannodes.h:741
unsigned int Index
Definition: c.h:361
AttrNumber * partColIdx
Definition: plannodes.h:754
List * rowMarks
Definition: plannodes.h:72
uint32 hashValue
Definition: plannodes.h:964
int32 skewColTypmod
Definition: plannodes.h:804
int num_workers
Definition: plannodes.h:783
List * indextlist
Definition: plannodes.h:398
List * indexorderby
Definition: plannodes.h:397
Index rti
Definition: plannodes.h:940
int firstFlag
Definition: plannodes.h:822
Oid * partOperators
Definition: plannodes.h:755
bool * mergeNullsFirst
Definition: plannodes.h:666
List * indexorderby
Definition: plannodes.h:369
List * subplans
Definition: plannodes.h:68
int plan_width
Definition: plannodes.h:118
bool funcordinality
Definition: plannodes.h:485
int * mergeStrategies
Definition: plannodes.h:665
Index winref
Definition: plannodes.h:752
Bitmapset * rewindPlanIDs
Definition: plannodes.h:70
AggSplit aggsplit
Definition: plannodes.h:734
List * custom_scan_tlist
Definition: plannodes.h:588
struct PlannedStmt PlannedStmt
bool hasModifyingCTE
Definition: plannodes.h:51
Plan plan
Definition: plannodes.h:710
OnConflictAction onConflictAction
Definition: plannodes.h:214
List * rowMarks
Definition: plannodes.h:838
AttrNumber * sortColIdx
Definition: plannodes.h:244
Scan scan
Definition: plannodes.h:451
struct Unique Unique
struct CustomScan CustomScan
LockClauseStrength strength
Definition: plannodes.h:945
AggSplit
Definition: nodes.h:748
struct TidScan TidScan
long numGroups
Definition: plannodes.h:738
RowMarkType
Definition: plannodes.h:887
List * indexqual
Definition: plannodes.h:396
Oid * dupOperators
Definition: plannodes.h:266
struct BitmapOr BitmapOr
Bitmapset * extParam
Definition: plannodes.h:147
struct MergeAppend MergeAppend
List * rtable
Definition: plannodes.h:63
struct Plan * lefttree
Definition: plannodes.h:131
Bitmapset * custom_relids
Definition: plannodes.h:590
struct PlanInvalItem PlanInvalItem
List * indexorderbyops
Definition: plannodes.h:371
List * indexqualorig
Definition: plannodes.h:424
List * targetlist
Definition: plannodes.h:129
bool * nullsFirst
Definition: plannodes.h:247
struct RecursiveUnion RecursiveUnion
AttrNumber * sortColIdx
Definition: plannodes.h:696
bool invisible
Definition: plannodes.h:785
List * mergeplans
Definition: plannodes.h:241
AggStrategy
Definition: nodes.h:727
Plan plan
Definition: plannodes.h:799
Oid * grpOperators
Definition: plannodes.h:737
CmdType operation
Definition: plannodes.h:202
Join join
Definition: plannodes.h:660
List * chain
Definition: plannodes.h:742
SetOpCmd
Definition: nodes.h:770
List * resultRelations
Definition: plannodes.h:66
struct SampleScan SampleScan
bool parallelModeNeeded
Definition: plannodes.h:59
List * initPlan
Definition: plannodes.h:133
Plan plan
Definition: plannodes.h:751
AttrNumber * grpColIdx
Definition: plannodes.h:712
Cost total_cost
Definition: plannodes.h:112
struct Plan Plan
struct Group Group
List * returningLists
Definition: plannodes.h:209
bool isParent
Definition: plannodes.h:947
Oid * sortOperators
Definition: plannodes.h:245
Plan plan
Definition: plannodes.h:280
Definition: plannodes.h:730
int frameOptions
Definition: plannodes.h:759
Index exclRelRTI
Definition: plannodes.h:218
Oid * collations
Definition: plannodes.h:698
Definition: pg_list.h:45
OnConflictAction
Definition: nodes.h:790
int16 AttrNumber
Definition: attnum.h:21
Oid * grpOperators
Definition: plannodes.h:713
LockWaitPolicy
Definition: lockoptions.h:36
CmdType
Definition: nodes.h:641
List * joinqual
Definition: plannodes.h:620
List * exclRelTlist
Definition: plannodes.h:219
double Cost
Definition: nodes.h:632
Plan * subplan
Definition: plannodes.h:474
Plan plan
Definition: plannodes.h:229
int epqParam
Definition: plannodes.h:213
bool fsSystemCol
Definition: plannodes.h:562
Node * onConflictWhere
Definition: plannodes.h:217
Bitmapset * fs_relids
Definition: plannodes.h:561
Plan plan
Definition: plannodes.h:618
uint32 flags
Definition: plannodes.h:583
Plan plan
Definition: plannodes.h:187