PostgreSQL Source Code  git master
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-2023, 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 "access/stratnum.h"
19 #include "common/relpath.h"
20 #include "lib/stringinfo.h"
21 #include "nodes/bitmapset.h"
22 #include "nodes/lockoptions.h"
23 #include "nodes/parsenodes.h"
24 #include "nodes/primnodes.h"
25 
26 
27 /* ----------------------------------------------------------------
28  * node definitions
29  * ----------------------------------------------------------------
30  */
31 
32 /* ----------------
33  * PlannedStmt node
34  *
35  * The output of the planner is a Plan tree headed by a PlannedStmt node.
36  * PlannedStmt holds the "one time" information needed by the executor.
37  *
38  * For simplicity in APIs, we also wrap utility statements in PlannedStmt
39  * nodes; in such cases, commandType == CMD_UTILITY, the statement itself
40  * is in the utilityStmt field, and the rest of the struct is mostly dummy.
41  * (We do use canSetTag, stmt_location, stmt_len, and possibly queryId.)
42  *
43  * PlannedStmt, as well as all varieties of Plan, do not support equal(),
44  * not because it's not sensible but because we currently have no need.
45  * ----------------
46  */
47 typedef struct PlannedStmt
48 {
49  pg_node_attr(no_equal, no_query_jumble)
50 
51  NodeTag type;
52 
53  CmdType commandType; /* select|insert|update|delete|merge|utility */
54 
55  uint64 queryId; /* query identifier (copied from Query) */
56 
57  bool hasReturning; /* is it insert|update|delete RETURNING? */
58 
59  bool hasModifyingCTE; /* has insert|update|delete in WITH? */
60 
61  bool canSetTag; /* do I set the command result tag? */
62 
63  bool transientPlan; /* redo plan when TransactionXmin changes? */
64 
65  bool dependsOnRole; /* is plan specific to current role? */
66 
67  bool parallelModeNeeded; /* parallel mode required to execute? */
68 
69  int jitFlags; /* which forms of JIT should be performed */
70 
71  struct Plan *planTree; /* tree of Plan nodes */
72 
73  List *rtable; /* list of RangeTblEntry nodes */
74 
75  List *permInfos; /* list of RTEPermissionInfo nodes for rtable
76  * entries needing one */
77 
78  /* rtable indexes of target relations for INSERT/UPDATE/DELETE/MERGE */
79  List *resultRelations; /* integer list of RT indexes, or NIL */
80 
81  List *appendRelations; /* list of AppendRelInfo nodes */
82 
83  List *subplans; /* Plan trees for SubPlan expressions; note
84  * that some could be NULL */
85 
86  Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
87 
88  List *rowMarks; /* a list of PlanRowMark's */
89 
90  List *relationOids; /* OIDs of relations the plan depends on */
91 
92  List *invalItems; /* other dependencies, as PlanInvalItems */
93 
94  List *paramExecTypes; /* type OIDs for PARAM_EXEC Params */
95 
96  Node *utilityStmt; /* non-null if this is utility stmt */
97 
98  /* statement location in source string (copied from Query) */
99  int stmt_location; /* start location, or -1 if unknown */
100  int stmt_len; /* length in bytes; 0 means "rest of string" */
102 
103 /* macro for fetching the Plan associated with a SubPlan node */
104 #define exec_subplan_get_plan(plannedstmt, subplan) \
105  ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
106 
107 
108 /* ----------------
109  * Plan node
110  *
111  * All plan nodes "derive" from the Plan structure by having the
112  * Plan structure as the first field. This ensures that everything works
113  * when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
114  * when passed around generically in the executor)
115  *
116  * We never actually instantiate any Plan nodes; this is just the common
117  * abstract superclass for all Plan-type nodes.
118  * ----------------
119  */
120 typedef struct Plan
121 {
122  pg_node_attr(abstract, no_equal, no_query_jumble)
123 
124  NodeTag type;
125 
126  /*
127  * estimated execution costs for plan (see costsize.c for more info)
128  */
129  Cost startup_cost; /* cost expended before fetching any tuples */
130  Cost total_cost; /* total cost (assuming all tuples fetched) */
131 
132  /*
133  * planner's estimate of result size of this plan step
134  */
135  Cardinality plan_rows; /* number of rows plan is expected to emit */
136  int plan_width; /* average row width in bytes */
137 
138  /*
139  * information needed for parallel query
140  */
141  bool parallel_aware; /* engage parallel-aware logic? */
142  bool parallel_safe; /* OK to use as part of parallel plan? */
143 
144  /*
145  * information needed for asynchronous execution
146  */
147  bool async_capable; /* engage asynchronous-capable logic? */
148 
149  /*
150  * Common structural data for all Plan types.
151  */
152  int plan_node_id; /* unique across entire final plan tree */
153  List *targetlist; /* target list to be computed at this node */
154  List *qual; /* implicitly-ANDed qual conditions */
155  struct Plan *lefttree; /* input plan tree(s) */
156  struct Plan *righttree;
157  List *initPlan; /* Init Plan nodes (un-correlated expr
158  * subselects) */
159 
160  /*
161  * Information for management of parameter-change-driven rescanning
162  *
163  * extParam includes the paramIDs of all external PARAM_EXEC params
164  * affecting this plan node or its children. setParam params from the
165  * node's initPlans are not included, but their extParams are.
166  *
167  * allParam includes all the extParam paramIDs, plus the IDs of local
168  * params that affect the node (i.e., the setParams of its initplans).
169  * These are _all_ the PARAM_EXEC params that affect this node.
170  */
174 
175 /* ----------------
176  * these are defined to avoid confusion problems with "left"
177  * and "right" and "inner" and "outer". The convention is that
178  * the "left" plan is the "outer" plan and the "right" plan is
179  * the inner plan, but these make the code more readable.
180  * ----------------
181  */
182 #define innerPlan(node) (((Plan *)(node))->righttree)
183 #define outerPlan(node) (((Plan *)(node))->lefttree)
184 
185 
186 /* ----------------
187  * Result node -
188  * If no outer plan, evaluate a variable-free targetlist.
189  * If outer plan, return tuples from outer plan (after a level of
190  * projection as shown by targetlist).
191  *
192  * If resconstantqual isn't NULL, it represents a one-time qualification
193  * test (i.e., one that doesn't depend on any variables from the outer plan,
194  * so needs to be evaluated only once).
195  * ----------------
196  */
197 typedef struct Result
198 {
202 
203 /* ----------------
204  * ProjectSet node -
205  * Apply a projection that includes set-returning functions to the
206  * output tuples of the outer plan.
207  * ----------------
208  */
209 typedef struct ProjectSet
210 {
213 
214 /* ----------------
215  * ModifyTable node -
216  * Apply rows produced by outer plan to result table(s),
217  * by inserting, updating, or deleting.
218  *
219  * If the originally named target table is a partitioned table, both
220  * nominalRelation and rootRelation contain the RT index of the partition
221  * root, which is not otherwise mentioned in the plan. Otherwise rootRelation
222  * is zero. However, nominalRelation will always be set, as it's the rel that
223  * EXPLAIN should claim is the INSERT/UPDATE/DELETE/MERGE target.
224  *
225  * Note that rowMarks and epqParam are presumed to be valid for all the
226  * table(s); they can't contain any info that varies across tables.
227  * ----------------
228  */
229 typedef struct ModifyTable
230 {
232  CmdType operation; /* INSERT, UPDATE, DELETE, or MERGE */
233  bool canSetTag; /* do we set the command tag/es_processed? */
234  Index nominalRelation; /* Parent RT index for use of EXPLAIN */
235  Index rootRelation; /* Root RT index, if target is partitioned */
236  bool partColsUpdated; /* some part key in hierarchy updated? */
237  List *resultRelations; /* integer list of RT indexes */
238  List *updateColnosLists; /* per-target-table update_colnos lists */
239  List *withCheckOptionLists; /* per-target-table WCO lists */
240  List *returningLists; /* per-target-table RETURNING tlists */
241  List *fdwPrivLists; /* per-target-table FDW private data lists */
242  Bitmapset *fdwDirectModifyPlans; /* indices of FDW DM plans */
243  List *rowMarks; /* PlanRowMarks (non-locking only) */
244  int epqParam; /* ID of Param for EvalPlanQual re-eval */
245  OnConflictAction onConflictAction; /* ON CONFLICT action */
246  List *arbiterIndexes; /* List of ON CONFLICT arbiter index OIDs */
247  List *onConflictSet; /* INSERT ON CONFLICT DO UPDATE targetlist */
248  List *onConflictCols; /* target column numbers for onConflictSet */
249  Node *onConflictWhere; /* WHERE for ON CONFLICT UPDATE */
250  Index exclRelRTI; /* RTI of the EXCLUDED pseudo relation */
251  List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
252  List *mergeActionLists; /* per-target-table lists of actions for
253  * MERGE */
255 
256 struct PartitionPruneInfo; /* forward reference to struct below */
257 
258 /* ----------------
259  * Append node -
260  * Generate the concatenation of the results of sub-plans.
261  * ----------------
262  */
263 typedef struct Append
264 {
266  Bitmapset *apprelids; /* RTIs of appendrel(s) formed by this node */
268  int nasyncplans; /* # of asynchronous plans */
269 
270  /*
271  * All 'appendplans' preceding this index are non-partial plans. All
272  * 'appendplans' from this index onwards are partial plans.
273  */
275 
276  /* Info for run-time subplan pruning; NULL if we're not doing that */
279 
280 /* ----------------
281  * MergeAppend node -
282  * Merge the results of pre-sorted sub-plans to preserve the ordering.
283  * ----------------
284  */
285 typedef struct MergeAppend
286 {
288 
289  /* RTIs of appendrel(s) formed by this node */
291 
293 
294  /* these fields are just like the sort-key info in struct Sort: */
295 
296  /* number of sort-key columns */
297  int numCols;
298 
299  /* their indexes in the target list */
300  AttrNumber *sortColIdx pg_node_attr(array_size(numCols));
301 
302  /* OIDs of operators to sort them by */
303  Oid *sortOperators pg_node_attr(array_size(numCols));
304 
305  /* OIDs of collations */
306  Oid *collations pg_node_attr(array_size(numCols));
307 
308  /* NULLS FIRST/LAST directions */
309  bool *nullsFirst pg_node_attr(array_size(numCols));
310 
311  /* Info for run-time subplan pruning; NULL if we're not doing that */
314 
315 /* ----------------
316  * RecursiveUnion node -
317  * Generate a recursive union of two subplans.
318  *
319  * The "outer" subplan is always the non-recursive term, and the "inner"
320  * subplan is the recursive term.
321  * ----------------
322  */
323 typedef struct RecursiveUnion
324 {
326 
327  /* ID of Param representing work table */
328  int wtParam;
329 
330  /* Remaining fields are zero/null in UNION ALL case */
331 
332  /* number of columns to check for duplicate-ness */
333  int numCols;
334 
335  /* their indexes in the target list */
336  AttrNumber *dupColIdx pg_node_attr(array_size(numCols));
337 
338  /* equality operators to compare with */
339  Oid *dupOperators pg_node_attr(array_size(numCols));
340  Oid *dupCollations pg_node_attr(array_size(numCols));
341 
342  /* estimated number of groups in input */
343  long numGroups;
345 
346 /* ----------------
347  * BitmapAnd node -
348  * Generate the intersection of the results of sub-plans.
349  *
350  * The subplans must be of types that yield tuple bitmaps. The targetlist
351  * and qual fields of the plan are unused and are always NIL.
352  * ----------------
353  */
354 typedef struct BitmapAnd
355 {
359 
360 /* ----------------
361  * BitmapOr node -
362  * Generate the union of the results of sub-plans.
363  *
364  * The subplans must be of types that yield tuple bitmaps. The targetlist
365  * and qual fields of the plan are unused and are always NIL.
366  * ----------------
367  */
368 typedef struct BitmapOr
369 {
371  bool isshared;
374 
375 /*
376  * ==========
377  * Scan nodes
378  *
379  * Scan is an abstract type that all relation scan plan types inherit from.
380  * ==========
381  */
382 typedef struct Scan
383 {
384  pg_node_attr(abstract)
385 
386  Plan plan;
387  Index scanrelid; /* relid is index into the range table */
389 
390 /* ----------------
391  * sequential scan node
392  * ----------------
393  */
394 typedef struct SeqScan
395 {
398 
399 /* ----------------
400  * table sample scan node
401  * ----------------
402  */
403 typedef struct SampleScan
404 {
406  /* use struct pointer to avoid including parsenodes.h here */
409 
410 /* ----------------
411  * index scan node
412  *
413  * indexqualorig is an implicitly-ANDed list of index qual expressions, each
414  * in the same form it appeared in the query WHERE condition. Each should
415  * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
416  * The indexkey is a Var or expression referencing column(s) of the index's
417  * base table. The comparisonval might be any expression, but it won't use
418  * any columns of the base table. The expressions are ordered by index
419  * column position (but items referencing the same index column can appear
420  * in any order). indexqualorig is used at runtime only if we have to recheck
421  * a lossy indexqual.
422  *
423  * indexqual has the same form, but the expressions have been commuted if
424  * necessary to put the indexkeys on the left, and the indexkeys are replaced
425  * by Var nodes identifying the index columns (their varno is INDEX_VAR and
426  * their varattno is the index column number).
427  *
428  * indexorderbyorig is similarly the original form of any ORDER BY expressions
429  * that are being implemented by the index, while indexorderby is modified to
430  * have index column Vars on the left-hand side. Here, multiple expressions
431  * must appear in exactly the ORDER BY order, and this is not necessarily the
432  * index column order. Only the expressions are provided, not the auxiliary
433  * sort-order information from the ORDER BY SortGroupClauses; it's assumed
434  * that the sort ordering is fully determinable from the top-level operators.
435  * indexorderbyorig is used at runtime to recheck the ordering, if the index
436  * cannot calculate an accurate ordering. It is also needed for EXPLAIN.
437  *
438  * indexorderbyops is a list of the OIDs of the operators used to sort the
439  * ORDER BY expressions. This is used together with indexorderbyorig to
440  * recheck ordering at run time. (Note that indexorderby, indexorderbyorig,
441  * and indexorderbyops are used for amcanorderbyop cases, not amcanorder.)
442  *
443  * indexorderdir specifies the scan ordering, for indexscans on amcanorder
444  * indexes (for other indexes it should be "don't care").
445  * ----------------
446  */
447 typedef struct IndexScan
448 {
450  Oid indexid; /* OID of index to scan */
451  List *indexqual; /* list of index quals (usually OpExprs) */
452  List *indexqualorig; /* the same in original form */
453  List *indexorderby; /* list of index ORDER BY exprs */
454  List *indexorderbyorig; /* the same in original form */
455  List *indexorderbyops; /* OIDs of sort ops for ORDER BY exprs */
456  ScanDirection indexorderdir; /* forward or backward or don't care */
458 
459 /* ----------------
460  * index-only scan node
461  *
462  * IndexOnlyScan is very similar to IndexScan, but it specifies an
463  * index-only scan, in which the data comes from the index not the heap.
464  * Because of this, *all* Vars in the plan node's targetlist, qual, and
465  * index expressions reference index columns and have varno = INDEX_VAR.
466  *
467  * We could almost use indexqual directly against the index's output tuple
468  * when rechecking lossy index operators, but that won't work for quals on
469  * index columns that are not retrievable. Hence, recheckqual is needed
470  * for rechecks: it expresses the same condition as indexqual, but using
471  * only index columns that are retrievable. (We will not generate an
472  * index-only scan if this is not possible. An example is that if an
473  * index has table column "x" in a retrievable index column "ind1", plus
474  * an expression f(x) in a non-retrievable column "ind2", an indexable
475  * query on f(x) will use "ind2" in indexqual and f(ind1) in recheckqual.
476  * Without the "ind1" column, an index-only scan would be disallowed.)
477  *
478  * We don't currently need a recheckable equivalent of indexorderby,
479  * because we don't support lossy operators in index ORDER BY.
480  *
481  * To help EXPLAIN interpret the index Vars for display, we provide
482  * indextlist, which represents the contents of the index as a targetlist
483  * with one TLE per index column. Vars appearing in this list reference
484  * the base table, and this is the only field in the plan node that may
485  * contain such Vars. Also, for the convenience of setrefs.c, TLEs in
486  * indextlist are marked as resjunk if they correspond to columns that
487  * the index AM cannot reconstruct.
488  * ----------------
489  */
490 typedef struct IndexOnlyScan
491 {
493  Oid indexid; /* OID of index to scan */
494  List *indexqual; /* list of index quals (usually OpExprs) */
495  List *recheckqual; /* index quals in recheckable form */
496  List *indexorderby; /* list of index ORDER BY exprs */
497  List *indextlist; /* TargetEntry list describing index's cols */
498  ScanDirection indexorderdir; /* forward or backward or don't care */
500 
501 /* ----------------
502  * bitmap index scan node
503  *
504  * BitmapIndexScan delivers a bitmap of potential tuple locations;
505  * it does not access the heap itself. The bitmap is used by an
506  * ancestor BitmapHeapScan node, possibly after passing through
507  * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
508  * the results of other BitmapIndexScans.
509  *
510  * The fields have the same meanings as for IndexScan, except we don't
511  * store a direction flag because direction is uninteresting.
512  *
513  * In a BitmapIndexScan plan node, the targetlist and qual fields are
514  * not used and are always NIL. The indexqualorig field is unused at
515  * run time too, but is saved for the benefit of EXPLAIN.
516  * ----------------
517  */
518 typedef struct BitmapIndexScan
519 {
521  Oid indexid; /* OID of index to scan */
522  bool isshared; /* Create shared bitmap if set */
523  List *indexqual; /* list of index quals (OpExprs) */
524  List *indexqualorig; /* the same in original form */
526 
527 /* ----------------
528  * bitmap sequential scan node
529  *
530  * This needs a copy of the qual conditions being used by the input index
531  * scans because there are various cases where we need to recheck the quals;
532  * for example, when the bitmap is lossy about the specific rows on a page
533  * that meet the index condition.
534  * ----------------
535  */
536 typedef struct BitmapHeapScan
537 {
539  List *bitmapqualorig; /* index quals, in standard expr form */
541 
542 /* ----------------
543  * tid scan node
544  *
545  * tidquals is an implicitly OR'ed list of qual expressions of the form
546  * "CTID = pseudoconstant", or "CTID = ANY(pseudoconstant_array)",
547  * or a CurrentOfExpr for the relation.
548  * ----------------
549  */
550 typedef struct TidScan
551 {
553  List *tidquals; /* qual(s) involving CTID = something */
555 
556 /* ----------------
557  * tid range scan node
558  *
559  * tidrangequals is an implicitly AND'ed list of qual expressions of the form
560  * "CTID relop pseudoconstant", where relop is one of >,>=,<,<=.
561  * ----------------
562  */
563 typedef struct TidRangeScan
564 {
566  List *tidrangequals; /* qual(s) involving CTID op something */
568 
569 /* ----------------
570  * subquery scan node
571  *
572  * SubqueryScan is for scanning the output of a sub-query in the range table.
573  * We often need an extra plan node above the sub-query's plan to perform
574  * expression evaluations (which we can't push into the sub-query without
575  * risking changing its semantics). Although we are not scanning a physical
576  * relation, we make this a descendant of Scan anyway for code-sharing
577  * purposes.
578  *
579  * SubqueryScanStatus caches the trivial_subqueryscan property of the node.
580  * SUBQUERY_SCAN_UNKNOWN means not yet determined. This is only used during
581  * planning.
582  *
583  * Note: we store the sub-plan in the type-specific subplan field, not in
584  * the generic lefttree field as you might expect. This is because we do
585  * not want plan-tree-traversal routines to recurse into the subplan without
586  * knowing that they are changing Query contexts.
587  * ----------------
588  */
589 typedef enum SubqueryScanStatus
590 {
595 
596 typedef struct SubqueryScan
597 {
602 
603 /* ----------------
604  * FunctionScan node
605  * ----------------
606  */
607 typedef struct FunctionScan
608 {
610  List *functions; /* list of RangeTblFunction nodes */
611  bool funcordinality; /* WITH ORDINALITY */
613 
614 /* ----------------
615  * ValuesScan node
616  * ----------------
617  */
618 typedef struct ValuesScan
619 {
621  List *values_lists; /* list of expression lists */
623 
624 /* ----------------
625  * TableFunc scan node
626  * ----------------
627  */
628 typedef struct TableFuncScan
629 {
631  TableFunc *tablefunc; /* table function node */
633 
634 /* ----------------
635  * CteScan node
636  * ----------------
637  */
638 typedef struct CteScan
639 {
641  int ctePlanId; /* ID of init SubPlan for CTE */
642  int cteParam; /* ID of Param representing CTE output */
644 
645 /* ----------------
646  * NamedTuplestoreScan node
647  * ----------------
648  */
649 typedef struct NamedTuplestoreScan
650 {
652  char *enrname; /* Name given to Ephemeral Named Relation */
654 
655 /* ----------------
656  * WorkTableScan node
657  * ----------------
658  */
659 typedef struct WorkTableScan
660 {
662  int wtParam; /* ID of Param representing work table */
664 
665 /* ----------------
666  * ForeignScan node
667  *
668  * fdw_exprs and fdw_private are both under the control of the foreign-data
669  * wrapper, but fdw_exprs is presumed to contain expression trees and will
670  * be post-processed accordingly by the planner; fdw_private won't be.
671  * Note that everything in both lists must be copiable by copyObject().
672  * One way to store an arbitrary blob of bytes is to represent it as a bytea
673  * Const. Usually, though, you'll be better off choosing a representation
674  * that can be dumped usefully by nodeToString().
675  *
676  * fdw_scan_tlist is a targetlist describing the contents of the scan tuple
677  * returned by the FDW; it can be NIL if the scan tuple matches the declared
678  * rowtype of the foreign table, which is the normal case for a simple foreign
679  * table scan. (If the plan node represents a foreign join, fdw_scan_tlist
680  * is required since there is no rowtype available from the system catalogs.)
681  * When fdw_scan_tlist is provided, Vars in the node's tlist and quals must
682  * have varno INDEX_VAR, and their varattnos correspond to resnos in the
683  * fdw_scan_tlist (which are also column numbers in the actual scan tuple).
684  * fdw_scan_tlist is never actually executed; it just holds expression trees
685  * describing what is in the scan tuple's columns.
686  *
687  * fdw_recheck_quals should contain any quals which the core system passed to
688  * the FDW but which were not added to scan.plan.qual; that is, it should
689  * contain the quals being checked remotely. This is needed for correct
690  * behavior during EvalPlanQual rechecks.
691  *
692  * When the plan node represents a foreign join, scan.scanrelid is zero and
693  * fs_relids must be consulted to identify the join relation. (fs_relids
694  * is valid for simple scans as well, but will always match scan.scanrelid.)
695  * fs_relids includes outer joins; fs_base_relids does not.
696  *
697  * If the FDW's PlanDirectModify() callback decides to repurpose a ForeignScan
698  * node to perform the UPDATE or DELETE operation directly in the remote
699  * server, it sets 'operation' and 'resultRelation' to identify the operation
700  * type and target relation. Note that these fields are only set if the
701  * modification is performed *fully* remotely; otherwise, the modification is
702  * driven by a local ModifyTable node and 'operation' is left to CMD_SELECT.
703  * ----------------
704  */
705 typedef struct ForeignScan
706 {
708  CmdType operation; /* SELECT/INSERT/UPDATE/DELETE */
709  Index resultRelation; /* direct modification target's RT index */
710  Oid checkAsUser; /* user to perform the scan as; 0 means to
711  * check as current user */
712  Oid fs_server; /* OID of foreign server */
713  List *fdw_exprs; /* expressions that FDW may evaluate */
714  List *fdw_private; /* private data for FDW */
715  List *fdw_scan_tlist; /* optional tlist describing scan tuple */
716  List *fdw_recheck_quals; /* original quals not in scan.plan.qual */
717  Bitmapset *fs_relids; /* base+OJ RTIs generated by this scan */
718  Bitmapset *fs_base_relids; /* base RTIs generated by this scan */
719  bool fsSystemCol; /* true if any "system column" is needed */
721 
722 /* ----------------
723  * CustomScan node
724  *
725  * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist,
726  * and fs_relids fields apply equally to CustomScan's custom_exprs,
727  * custom_private, custom_scan_tlist, and custom_relids fields. The
728  * convention of setting scan.scanrelid to zero for joins applies as well.
729  *
730  * Note that since Plan trees can be copied, custom scan providers *must*
731  * fit all plan data they need into those fields; embedding CustomScan in
732  * a larger struct will not work.
733  * ----------------
734  */
735 struct CustomScanMethods;
736 
737 typedef struct CustomScan
738 {
740  uint32 flags; /* mask of CUSTOMPATH_* flags, see
741  * nodes/extensible.h */
742  List *custom_plans; /* list of Plan nodes, if any */
743  List *custom_exprs; /* expressions that custom code may evaluate */
744  List *custom_private; /* private data for custom code */
745  List *custom_scan_tlist; /* optional tlist describing scan tuple */
746  Bitmapset *custom_relids; /* RTIs generated by this scan */
747 
748  /*
749  * NOTE: The method field of CustomScan is required to be a pointer to a
750  * static table of callback functions. So we don't copy the table itself,
751  * just reference the original one.
752  */
753  const struct CustomScanMethods *methods;
755 
756 /*
757  * ==========
758  * Join nodes
759  * ==========
760  */
761 
762 /* ----------------
763  * Join node
764  *
765  * jointype: rule for joining tuples from left and right subtrees
766  * inner_unique each outer tuple can match to no more than one inner tuple
767  * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
768  * (plan.qual contains conditions that came from WHERE)
769  *
770  * When jointype is INNER, joinqual and plan.qual are semantically
771  * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
772  * only joinqual is used to determine whether a match has been found for
773  * the purpose of deciding whether to generate null-extended tuples.
774  * (But plan.qual is still applied before actually returning a tuple.)
775  * For an outer join, only joinquals are allowed to be used as the merge
776  * or hash condition of a merge or hash join.
777  *
778  * inner_unique is set if the joinquals are such that no more than one inner
779  * tuple could match any given outer tuple. This allows the executor to
780  * skip searching for additional matches. (This must be provable from just
781  * the joinquals, ignoring plan.qual, due to where the executor tests it.)
782  * ----------------
783  */
784 typedef struct Join
785 {
786  pg_node_attr(abstract)
787 
788  Plan plan;
789  JoinType jointype;
790  bool inner_unique;
791  List *joinqual; /* JOIN quals (in addition to plan.qual) */
793 
794 /* ----------------
795  * nest loop join node
796  *
797  * The nestParams list identifies any executor Params that must be passed
798  * into execution of the inner subplan carrying values from the current row
799  * of the outer subplan. Currently we restrict these values to be simple
800  * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
801  * creation, the paramval can actually be a PlaceHolderVar expression; but it
802  * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
803  * ----------------
804  */
805 typedef struct NestLoop
806 {
808  List *nestParams; /* list of NestLoopParam nodes */
810 
811 typedef struct NestLoopParam
812 {
813  pg_node_attr(no_equal, no_query_jumble)
814 
815  NodeTag type;
816  int paramno; /* number of the PARAM_EXEC Param to set */
817  Var *paramval; /* outer-relation Var to assign to Param */
819 
820 /* ----------------
821  * merge join node
822  *
823  * The expected ordering of each mergeable column is described by a btree
824  * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
825  * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
826  * of each mergeclause may be of different datatypes, but they are ordered the
827  * same way according to the common opfamily and collation. The operator in
828  * each mergeclause must be an equality operator of the indicated opfamily.
829  * ----------------
830  */
831 typedef struct MergeJoin
832 {
834 
835  /* Can we skip mark/restore calls? */
837 
838  /* mergeclauses as expression trees */
840 
841  /* these are arrays, but have the same length as the mergeclauses list: */
842 
843  /* per-clause OIDs of btree opfamilies */
844  Oid *mergeFamilies pg_node_attr(array_size(mergeclauses));
845 
846  /* per-clause OIDs of collations */
847  Oid *mergeCollations pg_node_attr(array_size(mergeclauses));
848 
849  /* per-clause ordering (ASC or DESC) */
850  int *mergeStrategies pg_node_attr(array_size(mergeclauses));
851 
852  /* per-clause nulls ordering */
853  bool *mergeNullsFirst pg_node_attr(array_size(mergeclauses));
855 
856 /* ----------------
857  * hash join node
858  * ----------------
859  */
860 typedef struct HashJoin
861 {
866 
867  /*
868  * List of expressions to be hashed for tuples from the outer plan, to
869  * perform lookups in the hashtable over the inner plan.
870  */
873 
874 /* ----------------
875  * materialization node
876  * ----------------
877  */
878 typedef struct Material
879 {
882 
883 /* ----------------
884  * memoize node
885  * ----------------
886  */
887 typedef struct Memoize
888 {
890 
891  /* size of the two arrays below */
892  int numKeys;
893 
894  /* hash operators for each key */
895  Oid *hashOperators pg_node_attr(array_size(numKeys));
896 
897  /* collations for each key */
898  Oid *collations pg_node_attr(array_size(numKeys));
899 
900  /* cache keys in the form of exprs containing parameters */
902 
903  /*
904  * true if the cache entry should be marked as complete after we store the
905  * first tuple in it.
906  */
907  bool singlerow;
908 
909  /*
910  * true when cache key should be compared bit by bit, false when using
911  * hash equality ops
912  */
914 
915  /*
916  * The maximum number of entries that the planner expects will fit in the
917  * cache, or 0 if unknown
918  */
920 
921  /* paramids from param_exprs */
924 
925 /* ----------------
926  * sort node
927  * ----------------
928  */
929 typedef struct Sort
930 {
932 
933  /* number of sort-key columns */
934  int numCols;
935 
936  /* their indexes in the target list */
937  AttrNumber *sortColIdx pg_node_attr(array_size(numCols));
938 
939  /* OIDs of operators to sort them by */
940  Oid *sortOperators pg_node_attr(array_size(numCols));
941 
942  /* OIDs of collations */
943  Oid *collations pg_node_attr(array_size(numCols));
944 
945  /* NULLS FIRST/LAST directions */
946  bool *nullsFirst pg_node_attr(array_size(numCols));
948 
949 /* ----------------
950  * incremental sort node
951  * ----------------
952  */
953 typedef struct IncrementalSort
954 {
956  int nPresortedCols; /* number of presorted columns */
958 
959 /* ---------------
960  * group node -
961  * Used for queries with GROUP BY (but no aggregates) specified.
962  * The input must be presorted according to the grouping columns.
963  * ---------------
964  */
965 typedef struct Group
966 {
968 
969  /* number of grouping columns */
970  int numCols;
971 
972  /* their indexes in the target list */
973  AttrNumber *grpColIdx pg_node_attr(array_size(numCols));
974 
975  /* equality operators to compare with */
976  Oid *grpOperators pg_node_attr(array_size(numCols));
977  Oid *grpCollations pg_node_attr(array_size(numCols));
979 
980 /* ---------------
981  * aggregate node
982  *
983  * An Agg node implements plain or grouped aggregation. For grouped
984  * aggregation, we can work with presorted input or unsorted input;
985  * the latter strategy uses an internal hashtable.
986  *
987  * Notice the lack of any direct info about the aggregate functions to be
988  * computed. They are found by scanning the node's tlist and quals during
989  * executor startup. (It is possible that there are no aggregate functions;
990  * this could happen if they get optimized away by constant-folding, or if
991  * we are using the Agg node to implement hash-based grouping.)
992  * ---------------
993  */
994 typedef struct Agg
995 {
997 
998  /* basic strategy, see nodes.h */
1000 
1001  /* agg-splitting mode, see nodes.h */
1003 
1004  /* number of grouping columns */
1005  int numCols;
1006 
1007  /* their indexes in the target list */
1008  AttrNumber *grpColIdx pg_node_attr(array_size(numCols));
1009 
1010  /* equality operators to compare with */
1011  Oid *grpOperators pg_node_attr(array_size(numCols));
1012  Oid *grpCollations pg_node_attr(array_size(numCols));
1013 
1014  /* estimated number of groups in input */
1016 
1017  /* for pass-by-ref transition data */
1019 
1020  /* IDs of Params used in Aggref inputs */
1022 
1023  /* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */
1024 
1025  /* grouping sets to use */
1027 
1028  /* chained Agg/Sort nodes */
1031 
1032 /* ----------------
1033  * window aggregate node
1034  * ----------------
1035  */
1036 typedef struct WindowAgg
1037 {
1039 
1040  /* ID referenced by window functions */
1042 
1043  /* number of columns in partition clause */
1045 
1046  /* their indexes in the target list */
1047  AttrNumber *partColIdx pg_node_attr(array_size(partNumCols));
1048 
1049  /* equality operators for partition columns */
1050  Oid *partOperators pg_node_attr(array_size(partNumCols));
1051 
1052  /* collations for partition columns */
1053  Oid *partCollations pg_node_attr(array_size(partNumCols));
1054 
1055  /* number of columns in ordering clause */
1057 
1058  /* their indexes in the target list */
1059  AttrNumber *ordColIdx pg_node_attr(array_size(ordNumCols));
1060 
1061  /* equality operators for ordering columns */
1062  Oid *ordOperators pg_node_attr(array_size(ordNumCols));
1063 
1064  /* collations for ordering columns */
1065  Oid *ordCollations pg_node_attr(array_size(ordNumCols));
1066 
1067  /* frame_clause options, see WindowDef */
1069 
1070  /* expression for starting bound, if any */
1072 
1073  /* expression for ending bound, if any */
1075 
1076  /* qual to help short-circuit execution */
1078 
1079  /* runCondition for display in EXPLAIN */
1081 
1082  /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */
1083 
1084  /* in_range function for startOffset */
1086 
1087  /* in_range function for endOffset */
1089 
1090  /* collation for in_range tests */
1092 
1093  /* use ASC sort order for in_range tests? */
1095 
1096  /* nulls sort first for in_range tests? */
1098 
1099  /*
1100  * false for all apart from the WindowAgg that's closest to the root of
1101  * the plan
1102  */
1105 
1106 /* ----------------
1107  * unique node
1108  * ----------------
1109  */
1110 typedef struct Unique
1111 {
1113 
1114  /* number of columns to check for uniqueness */
1115  int numCols;
1116 
1117  /* their indexes in the target list */
1118  AttrNumber *uniqColIdx pg_node_attr(array_size(numCols));
1119 
1120  /* equality operators to compare with */
1121  Oid *uniqOperators pg_node_attr(array_size(numCols));
1122 
1123  /* collations for equality comparisons */
1124  Oid *uniqCollations pg_node_attr(array_size(numCols));
1126 
1127 /* ------------
1128  * gather node
1129  *
1130  * Note: rescan_param is the ID of a PARAM_EXEC parameter slot. That slot
1131  * will never actually contain a value, but the Gather node must flag it as
1132  * having changed whenever it is rescanned. The child parallel-aware scan
1133  * nodes are marked as depending on that parameter, so that the rescan
1134  * machinery is aware that their output is likely to change across rescans.
1135  * In some cases we don't need a rescan Param, so rescan_param is set to -1.
1136  * ------------
1137  */
1138 typedef struct Gather
1139 {
1141  int num_workers; /* planned number of worker processes */
1142  int rescan_param; /* ID of Param that signals a rescan, or -1 */
1143  bool single_copy; /* don't execute plan more than once */
1144  bool invisible; /* suppress EXPLAIN display (for testing)? */
1145  Bitmapset *initParam; /* param id's of initplans which are referred
1146  * at gather or one of it's child node */
1148 
1149 /* ------------
1150  * gather merge node
1151  * ------------
1152  */
1153 typedef struct GatherMerge
1154 {
1156 
1157  /* planned number of worker processes */
1159 
1160  /* ID of Param that signals a rescan, or -1 */
1162 
1163  /* remaining fields are just like the sort-key info in struct Sort */
1164 
1165  /* number of sort-key columns */
1166  int numCols;
1167 
1168  /* their indexes in the target list */
1169  AttrNumber *sortColIdx pg_node_attr(array_size(numCols));
1170 
1171  /* OIDs of operators to sort them by */
1172  Oid *sortOperators pg_node_attr(array_size(numCols));
1173 
1174  /* OIDs of collations */
1175  Oid *collations pg_node_attr(array_size(numCols));
1176 
1177  /* NULLS FIRST/LAST directions */
1178  bool *nullsFirst pg_node_attr(array_size(numCols));
1179 
1180  /*
1181  * param id's of initplans which are referred at gather merge or one of
1182  * it's child node
1183  */
1186 
1187 /* ----------------
1188  * hash build node
1189  *
1190  * If the executor is supposed to try to apply skew join optimization, then
1191  * skewTable/skewColumn/skewInherit identify the outer relation's join key
1192  * column, from which the relevant MCV statistics can be fetched.
1193  * ----------------
1194  */
1195 typedef struct Hash
1196 {
1198 
1199  /*
1200  * List of expressions to be hashed for tuples from Hash's outer plan,
1201  * needed to put them into the hashtable.
1202  */
1203  List *hashkeys; /* hash keys for the hashjoin condition */
1204  Oid skewTable; /* outer join key's table OID, or InvalidOid */
1205  AttrNumber skewColumn; /* outer join key's column #, or zero */
1206  bool skewInherit; /* is outer join rel an inheritance tree? */
1207  /* all other info is in the parent HashJoin node */
1208  Cardinality rows_total; /* estimate total rows if parallel_aware */
1210 
1211 /* ----------------
1212  * setop node
1213  * ----------------
1214  */
1215 typedef struct SetOp
1216 {
1218 
1219  /* what to do, see nodes.h */
1221 
1222  /* how to do it, see nodes.h */
1224 
1225  /* number of columns to check for duplicate-ness */
1226  int numCols;
1227 
1228  /* their indexes in the target list */
1229  AttrNumber *dupColIdx pg_node_attr(array_size(numCols));
1230 
1231  /* equality operators to compare with */
1232  Oid *dupOperators pg_node_attr(array_size(numCols));
1233  Oid *dupCollations pg_node_attr(array_size(numCols));
1234 
1235  /* where is the flag column, if any */
1237 
1238  /* flag value for first input relation */
1240 
1241  /* estimated number of groups in input */
1244 
1245 /* ----------------
1246  * lock-rows node
1247  *
1248  * rowMarks identifies the rels to be locked by this node; it should be
1249  * a subset of the rowMarks listed in the top-level PlannedStmt.
1250  * epqParam is a Param that all scan nodes below this one must depend on.
1251  * It is used to force re-evaluation of the plan during EvalPlanQual.
1252  * ----------------
1253  */
1254 typedef struct LockRows
1255 {
1257  List *rowMarks; /* a list of PlanRowMark's */
1258  int epqParam; /* ID of Param for EvalPlanQual re-eval */
1260 
1261 /* ----------------
1262  * limit node
1263  *
1264  * Note: as of Postgres 8.2, the offset and count expressions are expected
1265  * to yield int8, rather than int4 as before.
1266  * ----------------
1267  */
1268 typedef struct Limit
1269 {
1271 
1272  /* OFFSET parameter, or NULL if none */
1274 
1275  /* COUNT parameter, or NULL if none */
1277 
1278  /* limit type */
1280 
1281  /* number of columns to check for similarity */
1283 
1284  /* their indexes in the target list */
1285  AttrNumber *uniqColIdx pg_node_attr(array_size(uniqNumCols));
1286 
1287  /* equality operators to compare with */
1288  Oid *uniqOperators pg_node_attr(array_size(uniqNumCols));
1289 
1290  /* collations for equality comparisons */
1291  Oid *uniqCollations pg_node_attr(array_size(uniqNumCols));
1293 
1294 
1295 /*
1296  * RowMarkType -
1297  * enums for types of row-marking operations
1298  *
1299  * The first four of these values represent different lock strengths that
1300  * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
1301  * We support these on regular tables, as well as on foreign tables whose FDWs
1302  * report support for late locking. For other foreign tables, any locking
1303  * that might be done for such requests must happen during the initial row
1304  * fetch; their FDWs provide no mechanism for going back to lock a row later.
1305  * This means that the semantics will be a bit different than for a local
1306  * table; in particular we are likely to lock more rows than would be locked
1307  * locally, since remote rows will be locked even if they then fail
1308  * locally-checked restriction or join quals. However, the prospect of
1309  * doing a separate remote query to lock each selected row is usually pretty
1310  * unappealing, so early locking remains a credible design choice for FDWs.
1311  *
1312  * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely
1313  * identify all the source rows, not only those from the target relations, so
1314  * that we can perform EvalPlanQual rechecking at need. For plain tables we
1315  * can just fetch the TID, much as for a target relation; this case is
1316  * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
1317  * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
1318  * pretty inefficient, since most of the time we'll never need the data; but
1319  * fortunately the overhead is usually not performance-critical in practice.
1320  * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
1321  * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
1322  * (Again, this probably doesn't make sense if a physical remote fetch is
1323  * needed, but for FDWs that map to local storage it might be credible.)
1324  */
1325 typedef enum RowMarkType
1326 {
1327  ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
1328  ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
1329  ROW_MARK_SHARE, /* obtain shared tuple lock */
1330  ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
1331  ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
1332  ROW_MARK_COPY /* physically copy the row value */
1334 
1335 #define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
1336 
1337 /*
1338  * PlanRowMark -
1339  * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
1340  *
1341  * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate
1342  * PlanRowMark node for each non-target relation in the query. Relations that
1343  * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
1344  * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
1345  *
1346  * Initially all PlanRowMarks have rti == prti and isParent == false.
1347  * When the planner discovers that a relation is the root of an inheritance
1348  * tree, it sets isParent true, and adds an additional PlanRowMark to the
1349  * list for each child relation (including the target rel itself in its role
1350  * as a child, if it is not a partitioned table). Any non-leaf partitioned
1351  * child relations will also have entries with isParent = true. The child
1352  * entries have rti == child rel's RT index and prti == top parent's RT index,
1353  * and can therefore be recognized as children by the fact that prti != rti.
1354  * The parent's allMarkTypes field gets the OR of (1<<markType) across all
1355  * its children (this definition allows children to use different markTypes).
1356  *
1357  * The planner also adds resjunk output columns to the plan that carry
1358  * information sufficient to identify the locked or fetched rows. When
1359  * markType != ROW_MARK_COPY, these columns are named
1360  * tableoid%u OID of table
1361  * ctid%u TID of row
1362  * The tableoid column is only present for an inheritance hierarchy.
1363  * When markType == ROW_MARK_COPY, there is instead a single column named
1364  * wholerow%u whole-row value of relation
1365  * (An inheritance hierarchy could have all three resjunk output columns,
1366  * if some children use a different markType than others.)
1367  * In all three cases, %u represents the rowmark ID number (rowmarkId).
1368  * This number is unique within a plan tree, except that child relation
1369  * entries copy their parent's rowmarkId. (Assigning unique numbers
1370  * means we needn't renumber rowmarkIds when flattening subqueries, which
1371  * would require finding and renaming the resjunk columns as well.)
1372  * Note this means that all tables in an inheritance hierarchy share the
1373  * same resjunk column names.
1374  */
1375 typedef struct PlanRowMark
1376 {
1377  pg_node_attr(no_equal, no_query_jumble)
1378 
1379  NodeTag type;
1380  Index rti; /* range table index of markable relation */
1381  Index prti; /* range table index of parent relation */
1382  Index rowmarkId; /* unique identifier for resjunk columns */
1383  RowMarkType markType; /* see enum above */
1384  int allMarkTypes; /* OR of (1<<markType) for all children */
1385  LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */
1386  LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED options */
1387  bool isParent; /* true if this is a "dummy" parent entry */
1389 
1390 
1391 /*
1392  * Node types to represent partition pruning information.
1393  */
1394 
1395 /*
1396  * PartitionPruneInfo - Details required to allow the executor to prune
1397  * partitions.
1398  *
1399  * Here we store mapping details to allow translation of a partitioned table's
1400  * index as returned by the partition pruning code into subplan indexes for
1401  * plan types which support arbitrary numbers of subplans, such as Append.
1402  * We also store various details to tell the executor when it should be
1403  * performing partition pruning.
1404  *
1405  * Each PartitionedRelPruneInfo describes the partitioning rules for a single
1406  * partitioned table (a/k/a level of partitioning). Since a partitioning
1407  * hierarchy could contain multiple levels, we represent it by a List of
1408  * PartitionedRelPruneInfos, where the first entry represents the topmost
1409  * partitioned table and additional entries represent non-leaf child
1410  * partitions, ordered such that parents appear before their children.
1411  * Then, since an Append-type node could have multiple partitioning
1412  * hierarchies among its children, we have an unordered List of those Lists.
1413  *
1414  * prune_infos List of Lists containing PartitionedRelPruneInfo nodes,
1415  * one sublist per run-time-prunable partition hierarchy
1416  * appearing in the parent plan node's subplans.
1417  * other_subplans Indexes of any subplans that are not accounted for
1418  * by any of the PartitionedRelPruneInfo nodes in
1419  * "prune_infos". These subplans must not be pruned.
1420  */
1421 typedef struct PartitionPruneInfo
1422 {
1423  pg_node_attr(no_equal, no_query_jumble)
1424 
1425  NodeTag type;
1429 
1430 /*
1431  * PartitionedRelPruneInfo - Details required to allow the executor to prune
1432  * partitions for a single partitioned table.
1433  *
1434  * subplan_map[] and subpart_map[] are indexed by partition index of the
1435  * partitioned table referenced by 'rtindex', the partition index being the
1436  * order that the partitions are defined in the table's PartitionDesc. For a
1437  * leaf partition p, subplan_map[p] contains the zero-based index of the
1438  * partition's subplan in the parent plan's subplan list; it is -1 if the
1439  * partition is non-leaf or has been pruned. For a non-leaf partition p,
1440  * subpart_map[p] contains the zero-based index of that sub-partition's
1441  * PartitionedRelPruneInfo in the hierarchy's PartitionedRelPruneInfo list;
1442  * it is -1 if the partition is a leaf or has been pruned. Note that subplan
1443  * indexes, as stored in 'subplan_map', are global across the parent plan
1444  * node, but partition indexes are valid only within a particular hierarchy.
1445  * relid_map[p] contains the partition's OID, or 0 if the partition was pruned.
1446  */
1448 {
1449  pg_node_attr(no_equal, no_query_jumble)
1450 
1451  NodeTag type;
1452 
1453  /* RT index of partition rel for this level */
1455 
1456  /* Indexes of all partitions which subplans or subparts are present for */
1458 
1459  /* Length of the following arrays: */
1460  int nparts;
1461 
1462  /* subplan index by partition index, or -1 */
1463  int *subplan_map pg_node_attr(array_size(nparts));
1464 
1465  /* subpart index by partition index, or -1 */
1466  int *subpart_map pg_node_attr(array_size(nparts));
1467 
1468  /* relation OID by partition index, or 0 */
1469  Oid *relid_map pg_node_attr(array_size(nparts));
1470 
1471  /*
1472  * initial_pruning_steps shows how to prune during executor startup (i.e.,
1473  * without use of any PARAM_EXEC Params); it is NIL if no startup pruning
1474  * is required. exec_pruning_steps shows how to prune with PARAM_EXEC
1475  * Params; it is NIL if no per-scan pruning is required.
1476  */
1477  List *initial_pruning_steps; /* List of PartitionPruneStep */
1478  List *exec_pruning_steps; /* List of PartitionPruneStep */
1479 
1480  /* All PARAM_EXEC Param IDs in exec_pruning_steps */
1483 
1484 /*
1485  * Abstract Node type for partition pruning steps (there are no concrete
1486  * Nodes of this type).
1487  *
1488  * step_id is the global identifier of the step within its pruning context.
1489  */
1490 typedef struct PartitionPruneStep
1491 {
1492  pg_node_attr(abstract, no_equal, no_query_jumble)
1493 
1494  NodeTag type;
1495  int step_id;
1497 
1498 /*
1499  * PartitionPruneStepOp - Information to prune using a set of mutually ANDed
1500  * OpExpr clauses
1501  *
1502  * This contains information extracted from up to partnatts OpExpr clauses,
1503  * where partnatts is the number of partition key columns. 'opstrategy' is the
1504  * strategy of the operator in the clause matched to the last partition key.
1505  * 'exprs' contains expressions which comprise the lookup key to be passed to
1506  * the partition bound search function. 'cmpfns' contains the OIDs of
1507  * comparison functions used to compare aforementioned expressions with
1508  * partition bounds. Both 'exprs' and 'cmpfns' contain the same number of
1509  * items, up to partnatts items.
1510  *
1511  * Once we find the offset of a partition bound using the lookup key, we
1512  * determine which partitions to include in the result based on the value of
1513  * 'opstrategy'. For example, if it were equality, we'd return just the
1514  * partition that would contain that key or a set of partitions if the key
1515  * didn't consist of all partitioning columns. For non-equality strategies,
1516  * we'd need to include other partitions as appropriate.
1517  *
1518  * 'nullkeys' is the set containing the offset of the partition keys (0 to
1519  * partnatts - 1) that were matched to an IS NULL clause. This is only
1520  * considered for hash partitioning as we need to pass which keys are null
1521  * to the hash partition bound search function. It is never possible to
1522  * have an expression be present in 'exprs' for a given partition key and
1523  * the corresponding bit set in 'nullkeys'.
1524  */
1525 typedef struct PartitionPruneStepOp
1526 {
1528 
1534 
1535 /*
1536  * PartitionPruneStepCombine - Information to prune using a BoolExpr clause
1537  *
1538  * For BoolExpr clauses, we combine the set of partitions determined for each
1539  * of the argument clauses.
1540  */
1542 {
1546 
1548 {
1550 
1554 
1555 
1556 /*
1557  * Plan invalidation info
1558  *
1559  * We track the objects on which a PlannedStmt depends in two ways:
1560  * relations are recorded as a simple list of OIDs, and everything else
1561  * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
1562  * to be used with the syscache invalidation mechanism, so it identifies a
1563  * system catalog entry by cache ID and hash value.
1564  */
1565 typedef struct PlanInvalItem
1566 {
1567  pg_node_attr(no_equal, no_query_jumble)
1568 
1569  NodeTag type;
1570  int cacheId; /* a syscache ID, see utils/syscache.h */
1571  uint32 hashValue; /* hash value of object's cache lookup key */
1573 
1574 /*
1575  * MonotonicFunction
1576  *
1577  * Allows the planner to track monotonic properties of functions. A function
1578  * is monotonically increasing if a subsequent call cannot yield a lower value
1579  * than the previous call. A monotonically decreasing function cannot yield a
1580  * higher value on subsequent calls, and a function which is both must return
1581  * the same value on each call.
1582  */
1583 typedef enum MonotonicFunction
1584 {
1590 
1591 #endif /* PLANNODES_H */
int16 AttrNumber
Definition: attnum.h:21
unsigned int uint32
Definition: c.h:495
unsigned int Index
Definition: c.h:603
LockWaitPolicy
Definition: lockoptions.h:37
LockClauseStrength
Definition: lockoptions.h:22
SetOpCmd
Definition: nodes.h:407
SetOpStrategy
Definition: nodes.h:415
double Cost
Definition: nodes.h:262
OnConflictAction
Definition: nodes.h:427
double Cardinality
Definition: nodes.h:263
CmdType
Definition: nodes.h:274
AggStrategy
Definition: nodes.h:363
NodeTag
Definition: nodes.h:27
AggSplit
Definition: nodes.h:385
LimitOption
Definition: nodes.h:440
JoinType
Definition: nodes.h:299
#define plan(x)
Definition: pg_regress.c:154
struct ForeignScan ForeignScan
struct TableFuncScan TableFuncScan
struct IndexScan IndexScan
struct MergeJoin MergeJoin
struct Memoize Memoize
struct Plan Plan
struct SampleScan SampleScan
struct WindowAgg WindowAgg
struct WorkTableScan WorkTableScan
struct ProjectSet ProjectSet
struct Sort Sort
struct PartitionedRelPruneInfo PartitionedRelPruneInfo
struct BitmapIndexScan BitmapIndexScan
struct TidScan TidScan
struct LockRows LockRows
struct TidRangeScan TidRangeScan
struct PartitionPruneStepOp PartitionPruneStepOp
SubqueryScanStatus
Definition: plannodes.h:590
@ SUBQUERY_SCAN_NONTRIVIAL
Definition: plannodes.h:593
@ SUBQUERY_SCAN_UNKNOWN
Definition: plannodes.h:591
@ SUBQUERY_SCAN_TRIVIAL
Definition: plannodes.h:592
struct PlanInvalItem PlanInvalItem
struct SubqueryScan SubqueryScan
PartitionPruneCombineOp
Definition: plannodes.h:1542
@ PARTPRUNE_COMBINE_INTERSECT
Definition: plannodes.h:1544
@ PARTPRUNE_COMBINE_UNION
Definition: plannodes.h:1543
struct IncrementalSort IncrementalSort
struct CteScan CteScan
struct NestLoop NestLoop
struct PlanRowMark PlanRowMark
struct Limit Limit
struct Unique Unique
struct BitmapOr BitmapOr
struct SeqScan SeqScan
struct HashJoin HashJoin
struct Group Group
struct PartitionPruneInfo PartitionPruneInfo
struct Append Append
struct Material Material
struct BitmapHeapScan BitmapHeapScan
struct NamedTuplestoreScan NamedTuplestoreScan
struct SetOp SetOp
struct NestLoopParam NestLoopParam
struct BitmapAnd BitmapAnd
struct GatherMerge GatherMerge
struct ModifyTable ModifyTable
struct PartitionPruneStep PartitionPruneStep
struct Hash Hash
RowMarkType
Definition: plannodes.h:1326
@ ROW_MARK_COPY
Definition: plannodes.h:1332
@ ROW_MARK_REFERENCE
Definition: plannodes.h:1331
@ ROW_MARK_SHARE
Definition: plannodes.h:1329
@ ROW_MARK_EXCLUSIVE
Definition: plannodes.h:1327
@ ROW_MARK_NOKEYEXCLUSIVE
Definition: plannodes.h:1328
@ ROW_MARK_KEYSHARE
Definition: plannodes.h:1330
MonotonicFunction
Definition: plannodes.h:1584
@ MONOTONICFUNC_NONE
Definition: plannodes.h:1585
@ MONOTONICFUNC_DECREASING
Definition: plannodes.h:1587
@ MONOTONICFUNC_INCREASING
Definition: plannodes.h:1586
@ MONOTONICFUNC_BOTH
Definition: plannodes.h:1588
struct RecursiveUnion RecursiveUnion
struct IndexOnlyScan IndexOnlyScan
struct FunctionScan FunctionScan
struct Result Result
struct MergeAppend MergeAppend
struct PartitionPruneStepCombine PartitionPruneStepCombine
struct CustomScan CustomScan
struct Agg Agg
struct ValuesScan ValuesScan
struct Gather Gather
struct PlannedStmt PlannedStmt
unsigned int Oid
Definition: postgres_ext.h:31
ScanDirection
Definition: sdir.h:25
uint16 StrategyNumber
Definition: stratnum.h:22
Definition: plannodes.h:995
AggSplit aggsplit
Definition: plannodes.h:1002
List * chain
Definition: plannodes.h:1029
long numGroups
Definition: plannodes.h:1015
AttrNumber *grpColIdx pg_node_attr(array_size(numCols))
List * groupingSets
Definition: plannodes.h:1026
Bitmapset * aggParams
Definition: plannodes.h:1021
Plan plan
Definition: plannodes.h:996
int numCols
Definition: plannodes.h:1005
uint64 transitionSpace
Definition: plannodes.h:1018
AggStrategy aggstrategy
Definition: plannodes.h:999
Oid *grpCollations pg_node_attr(array_size(numCols))
Oid *grpOperators pg_node_attr(array_size(numCols))
int first_partial_plan
Definition: plannodes.h:274
struct PartitionPruneInfo * part_prune_info
Definition: plannodes.h:277
int nasyncplans
Definition: plannodes.h:268
Bitmapset * apprelids
Definition: plannodes.h:266
Plan plan
Definition: plannodes.h:265
List * appendplans
Definition: plannodes.h:267
Plan plan
Definition: plannodes.h:356
List * bitmapplans
Definition: plannodes.h:357
List * bitmapqualorig
Definition: plannodes.h:539
List * indexqualorig
Definition: plannodes.h:524
List * indexqual
Definition: plannodes.h:523
List * bitmapplans
Definition: plannodes.h:372
bool isshared
Definition: plannodes.h:371
Plan plan
Definition: plannodes.h:370
int ctePlanId
Definition: plannodes.h:641
int cteParam
Definition: plannodes.h:642
Scan scan
Definition: plannodes.h:640
uint32 flags
Definition: plannodes.h:740
List * custom_scan_tlist
Definition: plannodes.h:745
Scan scan
Definition: plannodes.h:739
List * custom_private
Definition: plannodes.h:744
Bitmapset * custom_relids
Definition: plannodes.h:746
List * custom_exprs
Definition: plannodes.h:743
const struct CustomScanMethods * methods
Definition: plannodes.h:753
List * custom_plans
Definition: plannodes.h:742
Oid checkAsUser
Definition: plannodes.h:710
CmdType operation
Definition: plannodes.h:708
Oid fs_server
Definition: plannodes.h:712
List * fdw_exprs
Definition: plannodes.h:713
bool fsSystemCol
Definition: plannodes.h:719
Bitmapset * fs_relids
Definition: plannodes.h:717
List * fdw_private
Definition: plannodes.h:714
Bitmapset * fs_base_relids
Definition: plannodes.h:718
Index resultRelation
Definition: plannodes.h:709
List * fdw_recheck_quals
Definition: plannodes.h:716
List * fdw_scan_tlist
Definition: plannodes.h:715
List * functions
Definition: plannodes.h:610
bool funcordinality
Definition: plannodes.h:611
Oid *sortOperators pg_node_attr(array_size(numCols))
Oid *collations pg_node_attr(array_size(numCols))
bool *nullsFirst pg_node_attr(array_size(numCols))
AttrNumber *sortColIdx pg_node_attr(array_size(numCols))
int rescan_param
Definition: plannodes.h:1161
Bitmapset * initParam
Definition: plannodes.h:1184
int num_workers
Definition: plannodes.h:1158
int num_workers
Definition: plannodes.h:1141
bool invisible
Definition: plannodes.h:1144
Bitmapset * initParam
Definition: plannodes.h:1145
bool single_copy
Definition: plannodes.h:1143
Plan plan
Definition: plannodes.h:1140
int rescan_param
Definition: plannodes.h:1142
int numCols
Definition: plannodes.h:970
Plan plan
Definition: plannodes.h:967
Oid *grpCollations pg_node_attr(array_size(numCols))
AttrNumber *grpColIdx pg_node_attr(array_size(numCols))
Oid *grpOperators pg_node_attr(array_size(numCols))
List * hashcollations
Definition: plannodes.h:865
List * hashclauses
Definition: plannodes.h:863
List * hashoperators
Definition: plannodes.h:864
Join join
Definition: plannodes.h:862
List * hashkeys
Definition: plannodes.h:871
AttrNumber skewColumn
Definition: plannodes.h:1205
List * hashkeys
Definition: plannodes.h:1203
Oid skewTable
Definition: plannodes.h:1204
bool skewInherit
Definition: plannodes.h:1206
Cardinality rows_total
Definition: plannodes.h:1208
Plan plan
Definition: plannodes.h:1197
List * indexqual
Definition: plannodes.h:494
List * recheckqual
Definition: plannodes.h:495
List * indextlist
Definition: plannodes.h:497
ScanDirection indexorderdir
Definition: plannodes.h:498
List * indexorderby
Definition: plannodes.h:496
List * indexorderby
Definition: plannodes.h:453
List * indexorderbyops
Definition: plannodes.h:455
ScanDirection indexorderdir
Definition: plannodes.h:456
Scan scan
Definition: plannodes.h:449
List * indexqualorig
Definition: plannodes.h:452
Oid indexid
Definition: plannodes.h:450
List * indexqual
Definition: plannodes.h:451
List * indexorderbyorig
Definition: plannodes.h:454
pg_node_attr(abstract) Plan plan
LimitOption limitOption
Definition: plannodes.h:1279
Plan plan
Definition: plannodes.h:1270
AttrNumber *uniqColIdx pg_node_attr(array_size(uniqNumCols))
Node * limitCount
Definition: plannodes.h:1276
Oid *uniqCollations pg_node_attr(array_size(uniqNumCols))
int uniqNumCols
Definition: plannodes.h:1282
Oid *uniqOperators pg_node_attr(array_size(uniqNumCols))
Node * limitOffset
Definition: plannodes.h:1273
Definition: pg_list.h:54
int epqParam
Definition: plannodes.h:1258
List * rowMarks
Definition: plannodes.h:1257
Plan plan
Definition: plannodes.h:1256
Plan plan
Definition: plannodes.h:880
Plan plan
Definition: plannodes.h:889
bool singlerow
Definition: plannodes.h:907
Bitmapset * keyparamids
Definition: plannodes.h:922
bool binary_mode
Definition: plannodes.h:913
int numKeys
Definition: plannodes.h:892
List * param_exprs
Definition: plannodes.h:901
uint32 est_entries
Definition: plannodes.h:919
Oid *hashOperators pg_node_attr(array_size(numKeys))
Oid *collations pg_node_attr(array_size(numKeys))
struct PartitionPruneInfo * part_prune_info
Definition: plannodes.h:312
Oid *sortOperators pg_node_attr(array_size(numCols))
Oid *collations pg_node_attr(array_size(numCols))
Bitmapset * apprelids
Definition: plannodes.h:290
bool *nullsFirst pg_node_attr(array_size(numCols))
List * mergeplans
Definition: plannodes.h:292
AttrNumber *sortColIdx pg_node_attr(array_size(numCols))
Oid *mergeFamilies pg_node_attr(array_size(mergeclauses))
List * mergeclauses
Definition: plannodes.h:839
Join join
Definition: plannodes.h:833
int *mergeStrategies pg_node_attr(array_size(mergeclauses))
Oid *mergeCollations pg_node_attr(array_size(mergeclauses))
bool skip_mark_restore
Definition: plannodes.h:836
bool *mergeNullsFirst pg_node_attr(array_size(mergeclauses))
List * updateColnosLists
Definition: plannodes.h:238
Index nominalRelation
Definition: plannodes.h:234
List * arbiterIndexes
Definition: plannodes.h:246
List * onConflictCols
Definition: plannodes.h:248
CmdType operation
Definition: plannodes.h:232
int epqParam
Definition: plannodes.h:244
List * resultRelations
Definition: plannodes.h:237
Bitmapset * fdwDirectModifyPlans
Definition: plannodes.h:242
List * onConflictSet
Definition: plannodes.h:247
List * exclRelTlist
Definition: plannodes.h:251
List * mergeActionLists
Definition: plannodes.h:252
bool canSetTag
Definition: plannodes.h:233
List * fdwPrivLists
Definition: plannodes.h:241
bool partColsUpdated
Definition: plannodes.h:236
List * returningLists
Definition: plannodes.h:240
List * withCheckOptionLists
Definition: plannodes.h:239
Index rootRelation
Definition: plannodes.h:235
Node * onConflictWhere
Definition: plannodes.h:249
List * rowMarks
Definition: plannodes.h:243
OnConflictAction onConflictAction
Definition: plannodes.h:245
Index exclRelRTI
Definition: plannodes.h:250
Var * paramval
Definition: plannodes.h:817
pg_node_attr(no_equal, no_query_jumble) NodeTag type
List * nestParams
Definition: plannodes.h:808
Join join
Definition: plannodes.h:807
Definition: nodes.h:129
Bitmapset * other_subplans
Definition: plannodes.h:1427
pg_node_attr(no_equal, no_query_jumble) NodeTag type
PartitionPruneCombineOp combineOp
Definition: plannodes.h:1551
PartitionPruneStep step
Definition: plannodes.h:1549
PartitionPruneStep step
Definition: plannodes.h:1527
StrategyNumber opstrategy
Definition: plannodes.h:1529
Bitmapset * nullkeys
Definition: plannodes.h:1532
pg_node_attr(abstract, no_equal, no_query_jumble) NodeTag type
pg_node_attr(no_equal, no_query_jumble) NodeTag type
int *subpart_map pg_node_attr(array_size(nparts))
int *subplan_map pg_node_attr(array_size(nparts))
Bitmapset * present_parts
Definition: plannodes.h:1457
Bitmapset * execparamids
Definition: plannodes.h:1481
Oid *relid_map pg_node_attr(array_size(nparts))
uint32 hashValue
Definition: plannodes.h:1571
pg_node_attr(no_equal, no_query_jumble) NodeTag type
LockClauseStrength strength
Definition: plannodes.h:1385
Index prti
Definition: plannodes.h:1381
RowMarkType markType
Definition: plannodes.h:1383
LockWaitPolicy waitPolicy
Definition: plannodes.h:1386
bool isParent
Definition: plannodes.h:1387
Index rowmarkId
Definition: plannodes.h:1382
int allMarkTypes
Definition: plannodes.h:1384
pg_node_attr(no_equal, no_query_jumble) NodeTag type
Bitmapset * extParam
Definition: plannodes.h:171
struct Plan * lefttree
Definition: plannodes.h:155
bool async_capable
Definition: plannodes.h:147
Cost total_cost
Definition: plannodes.h:130
struct Plan * righttree
Definition: plannodes.h:156
bool parallel_aware
Definition: plannodes.h:141
Cost startup_cost
Definition: plannodes.h:129
List * qual
Definition: plannodes.h:154
int plan_width
Definition: plannodes.h:136
Bitmapset * allParam
Definition: plannodes.h:172
bool parallel_safe
Definition: plannodes.h:142
Cardinality plan_rows
Definition: plannodes.h:135
int plan_node_id
Definition: plannodes.h:152
List * targetlist
Definition: plannodes.h:153
pg_node_attr(abstract, no_equal, no_query_jumble) NodeTag type
List * initPlan
Definition: plannodes.h:157
struct Plan * planTree
Definition: plannodes.h:71
bool hasModifyingCTE
Definition: plannodes.h:59
List * appendRelations
Definition: plannodes.h:81
List * permInfos
Definition: plannodes.h:75
bool canSetTag
Definition: plannodes.h:61
List * rowMarks
Definition: plannodes.h:88
int stmt_location
Definition: plannodes.h:99
int stmt_len
Definition: plannodes.h:100
int jitFlags
Definition: plannodes.h:69
Bitmapset * rewindPlanIDs
Definition: plannodes.h:86
bool hasReturning
Definition: plannodes.h:57
List * invalItems
Definition: plannodes.h:92
bool transientPlan
Definition: plannodes.h:63
List * resultRelations
Definition: plannodes.h:79
List * subplans
Definition: plannodes.h:83
List * relationOids
Definition: plannodes.h:90
bool dependsOnRole
Definition: plannodes.h:65
CmdType commandType
Definition: plannodes.h:53
pg_node_attr(no_equal, no_query_jumble) NodeTag type
Node * utilityStmt
Definition: plannodes.h:96
List * rtable
Definition: plannodes.h:73
List * paramExecTypes
Definition: plannodes.h:94
bool parallelModeNeeded
Definition: plannodes.h:67
uint64 queryId
Definition: plannodes.h:55
Plan plan
Definition: plannodes.h:211
Oid *dupCollations pg_node_attr(array_size(numCols))
AttrNumber *dupColIdx pg_node_attr(array_size(numCols))
Oid *dupOperators pg_node_attr(array_size(numCols))
Node * resconstantqual
Definition: plannodes.h:200
Plan plan
Definition: plannodes.h:199
struct TableSampleClause * tablesample
Definition: plannodes.h:407
Scan scan
Definition: plannodes.h:405
Index scanrelid
Definition: plannodes.h:387
pg_node_attr(abstract) Plan plan
Scan scan
Definition: plannodes.h:396
Oid *dupOperators pg_node_attr(array_size(numCols))
SetOpStrategy strategy
Definition: plannodes.h:1223
AttrNumber flagColIdx
Definition: plannodes.h:1236
Oid *dupCollations pg_node_attr(array_size(numCols))
AttrNumber *dupColIdx pg_node_attr(array_size(numCols))
SetOpCmd cmd
Definition: plannodes.h:1220
int numCols
Definition: plannodes.h:1226
int firstFlag
Definition: plannodes.h:1239
Plan plan
Definition: plannodes.h:1217
long numGroups
Definition: plannodes.h:1242
int numCols
Definition: plannodes.h:934
Oid *collations pg_node_attr(array_size(numCols))
bool *nullsFirst pg_node_attr(array_size(numCols))
Plan plan
Definition: plannodes.h:931
Oid *sortOperators pg_node_attr(array_size(numCols))
AttrNumber *sortColIdx pg_node_attr(array_size(numCols))
SubqueryScanStatus scanstatus
Definition: plannodes.h:600
Plan * subplan
Definition: plannodes.h:599
TableFunc * tablefunc
Definition: plannodes.h:631
List * tidrangequals
Definition: plannodes.h:566
Scan scan
Definition: plannodes.h:552
List * tidquals
Definition: plannodes.h:553
Oid *uniqCollations pg_node_attr(array_size(numCols))
Oid *uniqOperators pg_node_attr(array_size(numCols))
AttrNumber *uniqColIdx pg_node_attr(array_size(numCols))
Plan plan
Definition: plannodes.h:1112
int numCols
Definition: plannodes.h:1115
Scan scan
Definition: plannodes.h:620
List * values_lists
Definition: plannodes.h:621
Definition: primnodes.h:226
Oid *partOperators pg_node_attr(array_size(partNumCols))
AttrNumber *partColIdx pg_node_attr(array_size(partNumCols))
int partNumCols
Definition: plannodes.h:1044
Oid endInRangeFunc
Definition: plannodes.h:1088
Node * endOffset
Definition: plannodes.h:1074
bool topWindow
Definition: plannodes.h:1103
Plan plan
Definition: plannodes.h:1038
List * runConditionOrig
Definition: plannodes.h:1080
Oid inRangeColl
Definition: plannodes.h:1091
Node * startOffset
Definition: plannodes.h:1071
List * runCondition
Definition: plannodes.h:1077
AttrNumber *ordColIdx pg_node_attr(array_size(ordNumCols))
Oid startInRangeFunc
Definition: plannodes.h:1085
bool inRangeAsc
Definition: plannodes.h:1094
Oid *partCollations pg_node_attr(array_size(partNumCols))
Index winref
Definition: plannodes.h:1041
Oid *ordOperators pg_node_attr(array_size(ordNumCols))
bool inRangeNullsFirst
Definition: plannodes.h:1097
Oid *ordCollations pg_node_attr(array_size(ordNumCols))
int ordNumCols
Definition: plannodes.h:1056
int frameOptions
Definition: plannodes.h:1068
const char * type