1/*-------------------------------------------------------------------------
4 * definitions for query plan nodes
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/nodes/plannodes.h
12 *-------------------------------------------------------------------------
26/* ----------------------------------------------------------------
28 * ----------------------------------------------------------------
34 * PlannedStmtOrigin identifies from where a PlannedStmt comes from.
49 * The output of the planner is a Plan tree headed by a PlannedStmt node.
50 * PlannedStmt holds the "one time" information needed by the executor.
52 * For simplicity in APIs, we also wrap utility statements in PlannedStmt
53 * nodes; in such cases, commandType == CMD_UTILITY, the statement itself
54 * is in the utilityStmt field, and the rest of the struct is mostly dummy.
55 * (We do use canSetTag, stmt_location, stmt_len, and possibly queryId.)
57 * PlannedStmt, as well as all varieties of Plan, do not support equal(),
58 * not because it's not sensible but because we currently have no need.
67 /* select|insert|update|delete|merge|utility */
70 /* query identifier (copied from Query) */
73 /* plan identifier (can be set by plugins) */
79 /* is it insert|update|delete|merge RETURNING? */
82 /* has insert|update|delete|merge in WITH? */
85 /* do I set the command result tag? */
88 /* redo plan when TransactionXmin changes? */
91 /* is plan specific to current role? */
94 /* parallel mode required to execute? */
97 /* which forms of JIT should be performed */
100 /* tree of Plan nodes */
104 * List of PartitionPruneInfo contained in the plan
108 /* list of RangeTblEntry nodes */
112 * RT indexes of relations that are not subject to runtime pruning or are
113 * needed to perform runtime pruning
118 * list of RTEPermissionInfo nodes for rtable entries needing one
122 /* rtable indexes of target relations for INSERT/UPDATE/DELETE/MERGE */
123 /* integer list of RT indexes, or NIL */
126 /* list of AppendRelInfo nodes */
130 * Plan trees for SubPlan expressions; note that some could be NULL
134 /* indices of subplans that require REWIND */
137 /* a list of PlanRowMark's */
140 /* OIDs of relations the plan depends on */
143 /* other dependencies, as PlanInvalItems */
146 /* type OIDs for PARAM_EXEC Params */
149 /* non-null if this is utility stmt */
152 /* statement location in source string (copied from Query) */
153 /* start location, or -1 if unknown */
155 /* length in bytes; 0 means "rest of string" */
159/* macro for fetching the Plan associated with a SubPlan node */
160 #define exec_subplan_get_plan(plannedstmt, subplan) \
161 ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
167 * All plan nodes "derive" from the Plan structure by having the
168 * Plan structure as the first field. This ensures that everything works
169 * when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
170 * when passed around generically in the executor)
172 * We never actually instantiate any Plan nodes; this is just the common
173 * abstract superclass for all Plan-type nodes.
183 * estimated execution costs for plan (see costsize.c for more info)
185 /* count of disabled nodes */
187 /* cost expended before fetching any tuples */
189 /* total cost (assuming all tuples fetched) */
193 * planner's estimate of result size of this plan step
195 /* number of rows plan is expected to emit */
197 /* average row width in bytes */
201 * information needed for parallel query
203 /* engage parallel-aware logic? */
205 /* OK to use as part of parallel plan? */
209 * information needed for asynchronous execution
211 /* engage asynchronous-capable logic? */
215 * Common structural data for all Plan types.
217 /* unique across entire final plan tree */
219 /* target list to be computed at this node */
221 /* implicitly-ANDed qual conditions */
223 /* input plan tree(s) */
226 /* Init Plan nodes (un-correlated expr subselects) */
230 * Information for management of parameter-change-driven rescanning
232 * extParam includes the paramIDs of all external PARAM_EXEC params
233 * affecting this plan node or its children. setParam params from the
234 * node's initPlans are not included, but their extParams are.
236 * allParam includes all the extParam paramIDs, plus the IDs of local
237 * params that affect the node (i.e., the setParams of its initplans).
238 * These are _all_ the PARAM_EXEC params that affect this node.
245 * these are defined to avoid confusion problems with "left"
246 * and "right" and "inner" and "outer". The convention is that
247 * the "left" plan is the "outer" plan and the "right" plan is
248 * the inner plan, but these make the code more readable.
251 #define innerPlan(node) (((Plan *)(node))->righttree)
252 #define outerPlan(node) (((Plan *)(node))->lefttree)
257 * Classification of Result nodes
271 * If no outer plan, evaluate a variable-free targetlist.
272 * If outer plan, return tuples from outer plan (after a level of
273 * projection as shown by targetlist).
275 * If resconstantqual isn't NULL, it represents a one-time qualification
276 * test (i.e., one that doesn't depend on any variables from the outer plan,
277 * so needs to be evaluated only once).
279 * relids identifies the relation for which this Result node is generating the
280 * tuples. When subplan is not NULL, it should be empty: this node is not
281 * generating anything in that case, just acting on tuples generated by the
282 * subplan. Otherwise, it contains the relids of the planner relation that
283 * the Result represents.
296 * Apply a projection that includes set-returning functions to the
297 * output tuples of the outer plan.
307 * Apply rows produced by outer plan to result table(s),
308 * by inserting, updating, or deleting.
310 * If the originally named target table is a partitioned table or inheritance
311 * tree, both nominalRelation and rootRelation contain the RT index of the
312 * partition root or appendrel RTE, which is not otherwise mentioned in the
313 * plan. Otherwise rootRelation is zero. However, nominalRelation will
314 * always be set, as it's the rel that EXPLAIN should claim is the
315 * INSERT/UPDATE/DELETE/MERGE target.
317 * Note that rowMarks and epqParam are presumed to be valid for all the
318 * table(s); they can't contain any info that varies across tables.
324 /* INSERT, UPDATE, DELETE, or MERGE */
326 /* do we set the command tag/es_processed? */
328 /* Parent RT index for use of EXPLAIN */
330 /* Root RT index, if partitioned/inherited */
332 /* some part key in hierarchy updated? */
334 /* integer list of RT indexes */
336 /* per-target-table update_colnos lists */
338 /* per-target-table WCO lists */
340 /* alias for OLD in RETURNING lists */
342 /* alias for NEW in RETURNING lists */
344 /* per-target-table RETURNING tlists */
346 /* per-target-table FDW private data lists */
348 /* indices of FDW DM plans */
350 /* PlanRowMarks (non-locking only) */
352 /* ID of Param for EvalPlanQual re-eval */
354 /* ON CONFLICT action */
356 /* List of ON CONFLICT arbiter index OIDs */
358 /* INSERT ON CONFLICT DO UPDATE targetlist */
360 /* target column numbers for onConflictSet */
362 /* WHERE for ON CONFLICT UPDATE */
364 /* RTI of the EXCLUDED pseudo relation */
366 /* tlist of the EXCLUDED pseudo relation */
368 /* per-target-table lists of actions for MERGE */
370 /* per-target-table join conditions for MERGE */
378 * Generate the concatenation of the results of sub-plans.
384 /* RTIs of appendrel(s) formed by this node */
387 /* # of asynchronous plans */
391 * All 'appendplans' preceding this index are non-partial plans. All
392 * 'appendplans' from this index onwards are partial plans.
397 * Index into PlannedStmt.partPruneInfos and parallel lists in EState:
398 * es_part_prune_states and es_part_prune_results. Set to -1 if no
399 * run-time pruning is used.
406 * Merge the results of pre-sorted sub-plans to preserve the ordering.
413 /* RTIs of appendrel(s) formed by this node */
418 /* these fields are just like the sort-key info in struct Sort: */
420 /* number of sort-key columns */
423 /* their indexes in the target list */
426 /* OIDs of operators to sort them by */
429 /* OIDs of collations */
432 /* NULLS FIRST/LAST directions */
436 * Index into PlannedStmt.partPruneInfos and parallel lists in EState:
437 * es_part_prune_states and es_part_prune_results. Set to -1 if no
438 * run-time pruning is used.
444 * RecursiveUnion node -
445 * Generate a recursive union of two subplans.
447 * The "outer" subplan is always the non-recursive term, and the "inner"
448 * subplan is the recursive term.
455 /* ID of Param representing work table */
458 /* Remaining fields are zero/null in UNION ALL case */
460 /* number of columns to check for duplicate-ness */
463 /* their indexes in the target list */
466 /* equality operators to compare with */
470 /* estimated number of groups in input */
476 * Generate the intersection of the results of sub-plans.
478 * The subplans must be of types that yield tuple bitmaps. The targetlist
479 * and qual fields of the plan are unused and are always NIL.
490 * Generate the union of the results of sub-plans.
492 * The subplans must be of types that yield tuple bitmaps. The targetlist
493 * and qual fields of the plan are unused and are always NIL.
507 * Scan is an abstract type that all relation scan plan types inherit from.
515 /* relid is index into the range table */
520 * sequential scan node
529 * table sample scan node
535 /* use struct pointer to avoid including parsenodes.h here */
542 * indexqualorig is an implicitly-ANDed list of index qual expressions, each
543 * in the same form it appeared in the query WHERE condition. Each should
544 * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
545 * The indexkey is a Var or expression referencing column(s) of the index's
546 * base table. The comparisonval might be any expression, but it won't use
547 * any columns of the base table. The expressions are ordered by index
548 * column position (but items referencing the same index column can appear
549 * in any order). indexqualorig is used at runtime only if we have to recheck
552 * indexqual has the same form, but the expressions have been commuted if
553 * necessary to put the indexkeys on the left, and the indexkeys are replaced
554 * by Var nodes identifying the index columns (their varno is INDEX_VAR and
555 * their varattno is the index column number).
557 * indexorderbyorig is similarly the original form of any ORDER BY expressions
558 * that are being implemented by the index, while indexorderby is modified to
559 * have index column Vars on the left-hand side. Here, multiple expressions
560 * must appear in exactly the ORDER BY order, and this is not necessarily the
561 * index column order. Only the expressions are provided, not the auxiliary
562 * sort-order information from the ORDER BY SortGroupClauses; it's assumed
563 * that the sort ordering is fully determinable from the top-level operators.
564 * indexorderbyorig is used at runtime to recheck the ordering, if the index
565 * cannot calculate an accurate ordering. It is also needed for EXPLAIN.
567 * indexorderbyops is a list of the OIDs of the operators used to sort the
568 * ORDER BY expressions. This is used together with indexorderbyorig to
569 * recheck ordering at run time. (Note that indexorderby, indexorderbyorig,
570 * and indexorderbyops are used for amcanorderbyop cases, not amcanorder.)
572 * indexorderdir specifies the scan ordering, for indexscans on amcanorder
573 * indexes (for other indexes it should be "don't care").
579 /* OID of index to scan */
581 /* list of index quals (usually OpExprs) */
583 /* the same in original form */
585 /* list of index ORDER BY exprs */
587 /* the same in original form */
589 /* OIDs of sort ops for ORDER BY exprs */
591 /* forward or backward or don't care */
596 * index-only scan node
598 * IndexOnlyScan is very similar to IndexScan, but it specifies an
599 * index-only scan, in which the data comes from the index not the heap.
600 * Because of this, *all* Vars in the plan node's targetlist, qual, and
601 * index expressions reference index columns and have varno = INDEX_VAR.
603 * We could almost use indexqual directly against the index's output tuple
604 * when rechecking lossy index operators, but that won't work for quals on
605 * index columns that are not retrievable. Hence, recheckqual is needed
606 * for rechecks: it expresses the same condition as indexqual, but using
607 * only index columns that are retrievable. (We will not generate an
608 * index-only scan if this is not possible. An example is that if an
609 * index has table column "x" in a retrievable index column "ind1", plus
610 * an expression f(x) in a non-retrievable column "ind2", an indexable
611 * query on f(x) will use "ind2" in indexqual and f(ind1) in recheckqual.
612 * Without the "ind1" column, an index-only scan would be disallowed.)
614 * We don't currently need a recheckable equivalent of indexorderby,
615 * because we don't support lossy operators in index ORDER BY.
617 * To help EXPLAIN interpret the index Vars for display, we provide
618 * indextlist, which represents the contents of the index as a targetlist
619 * with one TLE per index column. Vars appearing in this list reference
620 * the base table, and this is the only field in the plan node that may
621 * contain such Vars. Also, for the convenience of setrefs.c, TLEs in
622 * indextlist are marked as resjunk if they correspond to columns that
623 * the index AM cannot reconstruct.
629 /* OID of index to scan */
631 /* list of index quals (usually OpExprs) */
633 /* index quals in recheckable form */
635 /* list of index ORDER BY exprs */
637 /* TargetEntry list describing index's cols */
639 /* forward or backward or don't care */
644 * bitmap index scan node
646 * BitmapIndexScan delivers a bitmap of potential tuple locations;
647 * it does not access the heap itself. The bitmap is used by an
648 * ancestor BitmapHeapScan node, possibly after passing through
649 * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
650 * the results of other BitmapIndexScans.
652 * The fields have the same meanings as for IndexScan, except we don't
653 * store a direction flag because direction is uninteresting.
655 * In a BitmapIndexScan plan node, the targetlist and qual fields are
656 * not used and are always NIL. The indexqualorig field is unused at
657 * run time too, but is saved for the benefit of EXPLAIN.
663 /* OID of index to scan */
665 /* Create shared bitmap if set */
667 /* list of index quals (OpExprs) */
669 /* the same in original form */
674 * bitmap sequential scan node
676 * This needs a copy of the qual conditions being used by the input index
677 * scans because there are various cases where we need to recheck the quals;
678 * for example, when the bitmap is lossy about the specific rows on a page
679 * that meet the index condition.
685 /* index quals, in standard expr form */
692 * tidquals is an implicitly OR'ed list of qual expressions of the form
693 * "CTID = pseudoconstant", or "CTID = ANY(pseudoconstant_array)",
694 * or a CurrentOfExpr for the relation.
700 /* qual(s) involving CTID = something */
705 * tid range scan node
707 * tidrangequals is an implicitly AND'ed list of qual expressions of the form
708 * "CTID relop pseudoconstant", where relop is one of >,>=,<,<=.
714 /* qual(s) involving CTID op something */
721 * SubqueryScan is for scanning the output of a sub-query in the range table.
722 * We often need an extra plan node above the sub-query's plan to perform
723 * expression evaluations (which we can't push into the sub-query without
724 * risking changing its semantics). Although we are not scanning a physical
725 * relation, we make this a descendant of Scan anyway for code-sharing
728 * SubqueryScanStatus caches the trivial_subqueryscan property of the node.
729 * SUBQUERY_SCAN_UNKNOWN means not yet determined. This is only used during
732 * Note: we store the sub-plan in the type-specific subplan field, not in
733 * the generic lefttree field as you might expect. This is because we do
734 * not want plan-tree-traversal routines to recurse into the subplan without
735 * knowing that they are changing Query contexts.
759 /* list of RangeTblFunction nodes */
761 /* WITH ORDINALITY */
772 /* list of expression lists */
777 * TableFunc scan node
783 /* table function node */
794 /* ID of init SubPlan for CTE */
796 /* ID of Param representing CTE output */
801 * NamedTuplestoreScan node
807 /* Name given to Ephemeral Named Relation */
818 /* ID of Param representing work table */
825 * fdw_exprs and fdw_private are both under the control of the foreign-data
826 * wrapper, but fdw_exprs is presumed to contain expression trees and will
827 * be post-processed accordingly by the planner; fdw_private won't be.
828 * Note that everything in both lists must be copiable by copyObject().
829 * One way to store an arbitrary blob of bytes is to represent it as a bytea
830 * Const. Usually, though, you'll be better off choosing a representation
831 * that can be dumped usefully by nodeToString().
833 * fdw_scan_tlist is a targetlist describing the contents of the scan tuple
834 * returned by the FDW; it can be NIL if the scan tuple matches the declared
835 * rowtype of the foreign table, which is the normal case for a simple foreign
836 * table scan. (If the plan node represents a foreign join, fdw_scan_tlist
837 * is required since there is no rowtype available from the system catalogs.)
838 * When fdw_scan_tlist is provided, Vars in the node's tlist and quals must
839 * have varno INDEX_VAR, and their varattnos correspond to resnos in the
840 * fdw_scan_tlist (which are also column numbers in the actual scan tuple).
841 * fdw_scan_tlist is never actually executed; it just holds expression trees
842 * describing what is in the scan tuple's columns.
844 * fdw_recheck_quals should contain any quals which the core system passed to
845 * the FDW but which were not added to scan.plan.qual; that is, it should
846 * contain the quals being checked remotely. This is needed for correct
847 * behavior during EvalPlanQual rechecks.
849 * When the plan node represents a foreign join, scan.scanrelid is zero and
850 * fs_relids must be consulted to identify the join relation. (fs_relids
851 * is valid for simple scans as well, but will always match scan.scanrelid.)
852 * fs_relids includes outer joins; fs_base_relids does not.
854 * If the FDW's PlanDirectModify() callback decides to repurpose a ForeignScan
855 * node to perform the UPDATE or DELETE operation directly in the remote
856 * server, it sets 'operation' and 'resultRelation' to identify the operation
857 * type and target relation. Note that these fields are only set if the
858 * modification is performed *fully* remotely; otherwise, the modification is
859 * driven by a local ModifyTable node and 'operation' is left to CMD_SELECT.
865 /* SELECT/INSERT/UPDATE/DELETE */
867 /* direct modification target's RT index */
869 /* user to perform the scan as; 0 means to check as current user */
871 /* OID of foreign server */
873 /* expressions that FDW may evaluate */
875 /* private data for FDW */
877 /* optional tlist describing scan tuple */
879 /* original quals not in scan.plan.qual */
881 /* base+OJ RTIs generated by this scan */
883 /* base RTIs generated by this scan */
885 /* true if any "system column" is needed */
892 * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist,
893 * and fs_relids fields apply equally to CustomScan's custom_exprs,
894 * custom_private, custom_scan_tlist, and custom_relids fields. The
895 * convention of setting scan.scanrelid to zero for joins applies as well.
897 * Note that since Plan trees can be copied, custom scan providers *must*
898 * fit all plan data they need into those fields; embedding CustomScan in
899 * a larger struct will not work.
907 /* mask of CUSTOMPATH_* flags, see nodes/extensible.h */
909 /* list of Plan nodes, if any */
911 /* expressions that custom code may evaluate */
913 /* private data for custom code */
915 /* optional tlist describing scan tuple */
917 /* RTIs generated by this scan */
921 * NOTE: The method field of CustomScan is required to be a pointer to a
922 * static table of callback functions. So we don't copy the table itself,
923 * just reference the original one.
937 * jointype: rule for joining tuples from left and right subtrees
938 * inner_unique each outer tuple can match to no more than one inner tuple
939 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
940 * (plan.qual contains conditions that came from WHERE)
942 * When jointype is INNER, joinqual and plan.qual are semantically
943 * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
944 * only joinqual is used to determine whether a match has been found for
945 * the purpose of deciding whether to generate null-extended tuples.
946 * (But plan.qual is still applied before actually returning a tuple.)
947 * For an outer join, only joinquals are allowed to be used as the merge
948 * or hash condition of a merge or hash join.
950 * inner_unique is set if the joinquals are such that no more than one inner
951 * tuple could match any given outer tuple. This allows the executor to
952 * skip searching for additional matches. (This must be provable from just
953 * the joinquals, ignoring plan.qual, due to where the executor tests it.)
963 /* JOIN quals (in addition to plan.qual) */
968 * nest loop join node
970 * The nestParams list identifies any executor Params that must be passed
971 * into execution of the inner subplan carrying values from the current row
972 * of the outer subplan. Currently we restrict these values to be simple
973 * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
974 * creation, the paramval can actually be a PlaceHolderVar expression; but it
975 * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
981 /* list of NestLoopParam nodes */
990 /* number of the PARAM_EXEC Param to set */
992 /* outer-relation Var to assign to Param */
999 * The expected ordering of each mergeable column is described by a btree
1000 * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
1001 * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
1002 * of each mergeclause may be of different datatypes, but they are ordered the
1003 * same way according to the common opfamily and collation. The operator in
1004 * each mergeclause must be an equality operator of the indicated opfamily.
1011 /* Can we skip mark/restore calls? */
1014 /* mergeclauses as expression trees */
1017 /* these are arrays, but have the same length as the mergeclauses list: */
1019 /* per-clause OIDs of btree opfamilies */
1022 /* per-clause OIDs of collations */
1025 /* per-clause ordering (ASC or DESC) */
1028 /* per-clause nulls ordering */
1044 * List of expressions to be hashed for tuples from the outer plan, to
1045 * perform lookups in the hashtable over the inner plan.
1051 * materialization node
1067 /* size of the two arrays below */
1070 /* hash operators for each key */
1073 /* collations for each key */
1076 /* cache keys in the form of exprs containing parameters */
1080 * true if the cache entry should be marked as complete after we store the
1081 * first tuple in it.
1086 * true when cache key should be compared bit by bit, false when using
1092 * The maximum number of entries that the planner expects will fit in the
1093 * cache, or 0 if unknown
1097 /* paramids from param_exprs */
1100 /* Estimated number of rescans, for EXPLAIN */
1103 /* Estimated number of distinct lookup keys, for EXPLAIN */
1106 /* Estimated cache hit ratio, for EXPLAIN */
1119 /* number of sort-key columns */
1122 /* their indexes in the target list */
1125 /* OIDs of operators to sort them by */
1128 /* OIDs of collations */
1131 /* NULLS FIRST/LAST directions */
1136 * incremental sort node
1142 /* number of presorted columns */
1148 * Used for queries with GROUP BY (but no aggregates) specified.
1149 * The input must be presorted according to the grouping columns.
1156 /* number of grouping columns */
1159 /* their indexes in the target list */
1162 /* equality operators to compare with */
1170 * An Agg node implements plain or grouped aggregation. For grouped
1171 * aggregation, we can work with presorted input or unsorted input;
1172 * the latter strategy uses an internal hashtable.
1174 * Notice the lack of any direct info about the aggregate functions to be
1175 * computed. They are found by scanning the node's tlist and quals during
1176 * executor startup. (It is possible that there are no aggregate functions;
1177 * this could happen if they get optimized away by constant-folding, or if
1178 * we are using the Agg node to implement hash-based grouping.)
1185 /* basic strategy, see nodes.h */
1188 /* agg-splitting mode, see nodes.h */
1191 /* number of grouping columns */
1194 /* their indexes in the target list */
1197 /* equality operators to compare with */
1201 /* estimated number of groups in input */
1204 /* for pass-by-ref transition data */
1207 /* IDs of Params used in Aggref inputs */
1210 /* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */
1212 /* grouping sets to use */
1215 /* chained Agg/Sort nodes */
1220 * window aggregate node
1227 /* name of WindowClause implemented by this node */
1230 /* ID referenced by window functions */
1233 /* number of columns in partition clause */
1236 /* their indexes in the target list */
1239 /* equality operators for partition columns */
1242 /* collations for partition columns */
1245 /* number of columns in ordering clause */
1248 /* their indexes in the target list */
1251 /* equality operators for ordering columns */
1254 /* collations for ordering columns */
1257 /* frame_clause options, see WindowDef */
1260 /* expression for starting bound, if any */
1263 /* expression for ending bound, if any */
1266 /* qual to help short-circuit execution */
1269 /* runCondition for display in EXPLAIN */
1272 /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */
1274 /* in_range function for startOffset */
1277 /* in_range function for endOffset */
1280 /* collation for in_range tests */
1283 /* use ASC sort order for in_range tests? */
1286 /* nulls sort first for in_range tests? */
1290 * false for all apart from the WindowAgg that's closest to the root of
1304 /* number of columns to check for uniqueness */
1307 /* their indexes in the target list */
1310 /* equality operators to compare with */
1313 /* collations for equality comparisons */
1320 * Note: rescan_param is the ID of a PARAM_EXEC parameter slot. That slot
1321 * will never actually contain a value, but the Gather node must flag it as
1322 * having changed whenever it is rescanned. The child parallel-aware scan
1323 * nodes are marked as depending on that parameter, so that the rescan
1324 * machinery is aware that their output is likely to change across rescans.
1325 * In some cases we don't need a rescan Param, so rescan_param is set to -1.
1331 /* planned number of worker processes */
1333 /* ID of Param that signals a rescan, or -1 */
1335 /* don't execute plan more than once */
1337 /* suppress EXPLAIN display (for testing)? */
1341 * param id's of initplans which are referred at gather or one of its
1355 /* planned number of worker processes */
1358 /* ID of Param that signals a rescan, or -1 */
1361 /* remaining fields are just like the sort-key info in struct Sort */
1363 /* number of sort-key columns */
1366 /* their indexes in the target list */
1369 /* OIDs of operators to sort them by */
1372 /* OIDs of collations */
1375 /* NULLS FIRST/LAST directions */
1379 * param id's of initplans which are referred at gather merge or one of
1388 * If the executor is supposed to try to apply skew join optimization, then
1389 * skewTable/skewColumn/skewInherit identify the outer relation's join key
1390 * column, from which the relevant MCV statistics can be fetched.
1398 * List of expressions to be hashed for tuples from Hash's outer plan,
1399 * needed to put them into the hashtable.
1401 /* hash keys for the hashjoin condition */
1403 /* outer join key's table OID, or InvalidOid */
1405 /* outer join key's column #, or zero */
1407 /* is outer join rel an inheritance tree? */
1409 /* all other info is in the parent HashJoin node */
1410 /* estimate total rows if parallel_aware */
1422 /* what to do, see nodes.h */
1425 /* how to do it, see nodes.h */
1428 /* number of columns to compare */
1431 /* their indexes in the target list */
1434 /* comparison operators (either equality operators or sort operators) */
1438 /* nulls-first flags if sorting, otherwise not interesting */
1441 /* estimated number of groups in left input */
1448 * rowMarks identifies the rels to be locked by this node; it should be
1449 * a subset of the rowMarks listed in the top-level PlannedStmt.
1450 * epqParam is a Param that all scan nodes below this one must depend on.
1451 * It is used to force re-evaluation of the plan during EvalPlanQual.
1457 /* a list of PlanRowMark's */
1459 /* ID of Param for EvalPlanQual re-eval */
1466 * Note: as of Postgres 8.2, the offset and count expressions are expected
1467 * to yield int8, rather than int4 as before.
1474 /* OFFSET parameter, or NULL if none */
1477 /* COUNT parameter, or NULL if none */
1483 /* number of columns to check for similarity */
1486 /* their indexes in the target list */
1489 /* equality operators to compare with */
1492 /* collations for equality comparisons */
1499 * enums for types of row-marking operations
1501 * The first four of these values represent different lock strengths that
1502 * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
1503 * We support these on regular tables, as well as on foreign tables whose FDWs
1504 * report support for late locking. For other foreign tables, any locking
1505 * that might be done for such requests must happen during the initial row
1506 * fetch; their FDWs provide no mechanism for going back to lock a row later.
1507 * This means that the semantics will be a bit different than for a local
1508 * table; in particular we are likely to lock more rows than would be locked
1509 * locally, since remote rows will be locked even if they then fail
1510 * locally-checked restriction or join quals. However, the prospect of
1511 * doing a separate remote query to lock each selected row is usually pretty
1512 * unappealing, so early locking remains a credible design choice for FDWs.
1514 * When doing UPDATE/DELETE/MERGE/SELECT FOR UPDATE/SHARE, we have to uniquely
1515 * identify all the source rows, not only those from the target relations, so
1516 * that we can perform EvalPlanQual rechecking at need. For plain tables we
1517 * can just fetch the TID, much as for a target relation; this case is
1518 * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
1519 * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
1520 * pretty inefficient, since most of the time we'll never need the data; but
1521 * fortunately the overhead is usually not performance-critical in practice.
1522 * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
1523 * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
1524 * (Again, this probably doesn't make sense if a physical remote fetch is
1525 * needed, but for FDWs that map to local storage it might be credible.)
1537 #define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
1541 * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
1543 * When doing UPDATE/DELETE/MERGE/SELECT FOR UPDATE/SHARE, we create a separate
1544 * PlanRowMark node for each non-target relation in the query. Relations that
1545 * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
1546 * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
1548 * Initially all PlanRowMarks have rti == prti and isParent == false.
1549 * When the planner discovers that a relation is the root of an inheritance
1550 * tree, it sets isParent true, and adds an additional PlanRowMark to the
1551 * list for each child relation (including the target rel itself in its role
1552 * as a child, if it is not a partitioned table). Any non-leaf partitioned
1553 * child relations will also have entries with isParent = true. The child
1554 * entries have rti == child rel's RT index and prti == top parent's RT index,
1555 * and can therefore be recognized as children by the fact that prti != rti.
1556 * The parent's allMarkTypes field gets the OR of (1<<markType) across all
1557 * its children (this definition allows children to use different markTypes).
1559 * The planner also adds resjunk output columns to the plan that carry
1560 * information sufficient to identify the locked or fetched rows. When
1561 * markType != ROW_MARK_COPY, these columns are named
1562 * tableoid%u OID of table
1564 * The tableoid column is only present for an inheritance hierarchy.
1565 * When markType == ROW_MARK_COPY, there is instead a single column named
1566 * wholerow%u whole-row value of relation
1567 * (An inheritance hierarchy could have all three resjunk output columns,
1568 * if some children use a different markType than others.)
1569 * In all three cases, %u represents the rowmark ID number (rowmarkId).
1570 * This number is unique within a plan tree, except that child relation
1571 * entries copy their parent's rowmarkId. (Assigning unique numbers
1572 * means we needn't renumber rowmarkIds when flattening subqueries, which
1573 * would require finding and renaming the resjunk columns as well.)
1574 * Note this means that all tables in an inheritance hierarchy share the
1575 * same resjunk column names.
1582 /* range table index of markable relation */
1584 /* range table index of parent relation */
1586 /* unique identifier for resjunk columns */
1588 /* see enum above */
1590 /* OR of (1<<markType) for all children */
1592 /* LockingClause's strength, or LCS_NONE */
1594 /* NOWAIT and SKIP LOCKED options */
1596 /* true if this is a "dummy" parent entry */
1602 * Node types to represent partition pruning information.
1606 * PartitionPruneInfo - Details required to allow the executor to prune
1609 * Here we store mapping details to allow translation of a partitioned table's
1610 * index as returned by the partition pruning code into subplan indexes for
1611 * plan types which support arbitrary numbers of subplans, such as Append.
1612 * We also store various details to tell the executor when it should be
1613 * performing partition pruning.
1615 * Each PartitionedRelPruneInfo describes the partitioning rules for a single
1616 * partitioned table (a/k/a level of partitioning). Since a partitioning
1617 * hierarchy could contain multiple levels, we represent it by a List of
1618 * PartitionedRelPruneInfos, where the first entry represents the topmost
1619 * partitioned table and additional entries represent non-leaf child
1620 * partitions, ordered such that parents appear before their children.
1621 * Then, since an Append-type node could have multiple partitioning
1622 * hierarchies among its children, we have an unordered List of those Lists.
1624 * relids RelOptInfo.relids of the parent plan node (e.g. Append
1625 * or MergeAppend) to which this PartitionPruneInfo node
1626 * belongs. The pruning logic ensures that this matches
1627 * the parent plan node's apprelids.
1628 * prune_infos List of Lists containing PartitionedRelPruneInfo nodes,
1629 * one sublist per run-time-prunable partition hierarchy
1630 * appearing in the parent plan node's subplans.
1631 * other_subplans Indexes of any subplans that are not accounted for
1632 * by any of the PartitionedRelPruneInfo nodes in
1633 * "prune_infos". These subplans must not be pruned.
1646 * PartitionedRelPruneInfo - Details required to allow the executor to prune
1647 * partitions for a single partitioned table.
1649 * subplan_map[], subpart_map[], and leafpart_rti_map[] are indexed by partition
1650 * index of the partitioned table referenced by 'rtindex', the partition index
1651 * being the order that the partitions are defined in the table's
1652 * PartitionDesc. For a leaf partition p, subplan_map[p] contains the
1653 * zero-based index of the partition's subplan in the parent plan's subplan
1654 * list; it is -1 if the partition is non-leaf or has been pruned. For a
1655 * non-leaf partition p, subpart_map[p] contains the zero-based index of that
1656 * sub-partition's PartitionedRelPruneInfo in the hierarchy's
1657 * PartitionedRelPruneInfo list; it is -1 if the partition is a leaf or has
1658 * been pruned. leafpart_rti_map[p] contains the RT index of a leaf partition
1659 * if its subplan is in the parent plan' subplan list; it is 0 either if the
1660 * partition is non-leaf or it is leaf but has been pruned during planning.
1661 * Note that subplan indexes, as stored in 'subplan_map', are global across the
1662 * parent plan node, but partition indexes are valid only within a particular
1663 * hierarchy. relid_map[p] contains the partition's OID, or 0 if the partition
1672 /* RT index of partition rel for this level */
1675 /* Indexes of all partitions which subplans or subparts are present for */
1678 /* Length of the following arrays: */
1681 /* subplan index by partition index, or -1 */
1684 /* subpart index by partition index, or -1 */
1687 /* RT index by partition index, or 0 */
1690 /* relation OID by partition index, or 0 */
1694 * initial_pruning_steps shows how to prune during executor startup (i.e.,
1695 * without use of any PARAM_EXEC Params); it is NIL if no startup pruning
1696 * is required. exec_pruning_steps shows how to prune with PARAM_EXEC
1697 * Params; it is NIL if no per-scan pruning is required.
1699 /* List of PartitionPruneStep */
1701 /* List of PartitionPruneStep */
1704 /* All PARAM_EXEC Param IDs in exec_pruning_steps */
1709 * Abstract Node type for partition pruning steps (there are no concrete
1710 * Nodes of this type).
1712 * step_id is the global identifier of the step within its pruning context.
1723 * PartitionPruneStepOp - Information to prune using a set of mutually ANDed
1726 * This contains information extracted from up to partnatts OpExpr clauses,
1727 * where partnatts is the number of partition key columns. 'opstrategy' is the
1728 * strategy of the operator in the clause matched to the last partition key.
1729 * 'exprs' contains expressions which comprise the lookup key to be passed to
1730 * the partition bound search function. 'cmpfns' contains the OIDs of
1731 * comparison functions used to compare aforementioned expressions with
1732 * partition bounds. Both 'exprs' and 'cmpfns' contain the same number of
1733 * items, up to partnatts items.
1735 * Once we find the offset of a partition bound using the lookup key, we
1736 * determine which partitions to include in the result based on the value of
1737 * 'opstrategy'. For example, if it were equality, we'd return just the
1738 * partition that would contain that key or a set of partitions if the key
1739 * didn't consist of all partitioning columns. For non-equality strategies,
1740 * we'd need to include other partitions as appropriate.
1742 * 'nullkeys' is the set containing the offset of the partition keys (0 to
1743 * partnatts - 1) that were matched to an IS NULL clause. This is only
1744 * considered for hash partitioning as we need to pass which keys are null
1745 * to the hash partition bound search function. It is never possible to
1746 * have an expression be present in 'exprs' for a given partition key and
1747 * the corresponding bit set in 'nullkeys'.
1760 * PartitionPruneStepCombine - Information to prune using a BoolExpr clause
1762 * For BoolExpr clauses, we combine the set of partitions determined for each
1763 * of the argument clauses.
1781 * Plan invalidation info
1783 * We track the objects on which a PlannedStmt depends in two ways:
1784 * relations are recorded as a simple list of OIDs, and everything else
1785 * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
1786 * to be used with the syscache invalidation mechanism, so it identifies a
1787 * system catalog entry by cache ID and hash value.
1794 /* a syscache ID, see utils/syscache.h */
1796 /* hash value of object's cache lookup key */
1803 * Allows the planner to track monotonic properties of functions. A function
1804 * is monotonically increasing if a subsequent call cannot yield a lower value
1805 * than the previous call. A monotonically decreasing function cannot yield a
1806 * higher value on subsequent calls, and a function which is both must return
1807 * the same value on each call.
1817#endif /* PLANNODES_H */
struct ForeignScan ForeignScan
struct TableFuncScan TableFuncScan
struct IndexScan IndexScan
struct MergeJoin MergeJoin
struct SampleScan SampleScan
struct WindowAgg WindowAgg
struct WorkTableScan WorkTableScan
struct ProjectSet ProjectSet
struct PartitionedRelPruneInfo PartitionedRelPruneInfo
struct BitmapIndexScan BitmapIndexScan
struct TidRangeScan TidRangeScan
struct PartitionPruneStepOp PartitionPruneStepOp
@ SUBQUERY_SCAN_NONTRIVIAL
struct PlanInvalItem PlanInvalItem
struct SubqueryScan SubqueryScan
@ PARTPRUNE_COMBINE_INTERSECT
@ PARTPRUNE_COMBINE_UNION
struct IncrementalSort IncrementalSort
struct PlanRowMark PlanRowMark
struct PartitionPruneInfo PartitionPruneInfo
struct BitmapHeapScan BitmapHeapScan
struct NamedTuplestoreScan NamedTuplestoreScan
@ PLAN_STMT_CACHE_GENERIC
struct NestLoopParam NestLoopParam
struct BitmapAnd BitmapAnd
struct GatherMerge GatherMerge
struct ModifyTable ModifyTable
struct PartitionPruneStep PartitionPruneStep
@ ROW_MARK_NOKEYEXCLUSIVE
@ MONOTONICFUNC_DECREASING
@ MONOTONICFUNC_INCREASING
struct RecursiveUnion RecursiveUnion
struct IndexOnlyScan IndexOnlyScan
struct FunctionScan FunctionScan
struct MergeAppend MergeAppend
struct PartitionPruneStepCombine PartitionPruneStepCombine
struct CustomScan CustomScan
struct ValuesScan ValuesScan
struct PlannedStmt PlannedStmt
Oid *grpCollations pg_node_attr(array_size(numCols))
Oid *grpOperators pg_node_attr(array_size(numCols))
AttrNumber *grpColIdx pg_node_attr(array_size(numCols))
Bitmapset * custom_relids
const struct CustomScanMethods * methods
Bitmapset * fs_base_relids
Oid *collations pg_node_attr(array_size(numCols))
Oid *sortOperators pg_node_attr(array_size(numCols))
bool *nullsFirst pg_node_attr(array_size(numCols))
AttrNumber *sortColIdx pg_node_attr(array_size(numCols))
AttrNumber *grpColIdx pg_node_attr(array_size(numCols))
Oid *grpCollations pg_node_attr(array_size(numCols))
Oid *grpOperators pg_node_attr(array_size(numCols))
ScanDirection indexorderdir
ScanDirection indexorderdir
pg_node_attr(abstract) Plan plan
Oid *uniqOperators pg_node_attr(array_size(uniqNumCols))
AttrNumber *uniqColIdx pg_node_attr(array_size(uniqNumCols))
Oid *uniqCollations pg_node_attr(array_size(uniqNumCols))
Oid *hashOperators pg_node_attr(array_size(numKeys))
Cardinality est_unique_keys
Oid *collations pg_node_attr(array_size(numKeys))
bool *nullsFirst pg_node_attr(array_size(numCols))
AttrNumber *sortColIdx pg_node_attr(array_size(numCols))
Oid *sortOperators pg_node_attr(array_size(numCols))
Oid *collations pg_node_attr(array_size(numCols))
Oid *mergeFamilies pg_node_attr(array_size(mergeclauses))
bool *mergeReversals pg_node_attr(array_size(mergeclauses))
bool *mergeNullsFirst pg_node_attr(array_size(mergeclauses))
Oid *mergeCollations pg_node_attr(array_size(mergeclauses))
List * mergeJoinConditions
Bitmapset * fdwDirectModifyPlans
List * withCheckOptionLists
OnConflictAction onConflictAction
pg_node_attr(no_equal, no_query_jumble) NodeTag type
Bitmapset * other_subplans
pg_node_attr(no_equal, no_query_jumble) NodeTag type
PartitionPruneCombineOp combineOp
StrategyNumber opstrategy
pg_node_attr(abstract, no_equal, no_query_jumble) NodeTag type
Oid *relid_map pg_node_attr(array_size(nparts))
pg_node_attr(no_equal, no_query_jumble) NodeTag type
Bitmapset * present_parts
int *leafpart_rti_map pg_node_attr(array_size(nparts))
List * initial_pruning_steps
int *subplan_map pg_node_attr(array_size(nparts))
int *subpart_map pg_node_attr(array_size(nparts))
List * exec_pruning_steps
pg_node_attr(no_equal, no_query_jumble) NodeTag type
LockClauseStrength strength
LockWaitPolicy waitPolicy
pg_node_attr(no_equal, no_query_jumble) NodeTag type
pg_node_attr(abstract, no_equal, no_query_jumble) NodeTag type
Bitmapset * rewindPlanIDs
PlannedStmtOrigin planOrigin
Bitmapset * unprunableRelids
pg_node_attr(no_equal, no_query_jumble) NodeTag type
AttrNumber *dupColIdx pg_node_attr(array_size(numCols))
Oid *dupOperators pg_node_attr(array_size(numCols))
Oid *dupCollations pg_node_attr(array_size(numCols))
struct TableSampleClause * tablesample
pg_node_attr(abstract) Plan plan
Oid *cmpOperators pg_node_attr(array_size(numCols))
AttrNumber *cmpColIdx pg_node_attr(array_size(numCols))
Oid *cmpCollations pg_node_attr(array_size(numCols))
bool *cmpNullsFirst pg_node_attr(array_size(numCols))
Oid *collations pg_node_attr(array_size(numCols))
bool *nullsFirst pg_node_attr(array_size(numCols))
Oid *sortOperators pg_node_attr(array_size(numCols))
AttrNumber *sortColIdx pg_node_attr(array_size(numCols))
SubqueryScanStatus scanstatus
AttrNumber *uniqColIdx pg_node_attr(array_size(numCols))
Oid *uniqOperators pg_node_attr(array_size(numCols))
Oid *uniqCollations pg_node_attr(array_size(numCols))
AttrNumber *ordColIdx pg_node_attr(array_size(ordNumCols))
Oid *partCollations pg_node_attr(array_size(partNumCols))
Oid *ordOperators pg_node_attr(array_size(ordNumCols))
AttrNumber *partColIdx pg_node_attr(array_size(partNumCols))
Oid *partOperators pg_node_attr(array_size(partNumCols))
Oid *ordCollations pg_node_attr(array_size(ordNumCols))