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