1 /*-------------------------------------------------------------------------
4 * definitions for query plan nodes
7 * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/nodes/plannodes.h
12 *-------------------------------------------------------------------------
17 #include "access/sdir.h"
18 #include "lib/stringinfo.h"
19 #include "nodes/bitmapset.h"
20 #include "nodes/lockoptions.h"
21 #include "nodes/primnodes.h"
24 /* ----------------------------------------------------------------
26 * ----------------------------------------------------------------
32 * The output of the planner is a Plan tree headed by a PlannedStmt node.
33 * PlannedStmt holds the "one time" information needed by the executor.
35 * For simplicity in APIs, we also wrap utility statements in PlannedStmt
36 * nodes; in such cases, commandType == CMD_UTILITY, the statement itself
37 * is in the utilityStmt field, and the rest of the struct is mostly dummy.
38 * (We do use canSetTag, stmt_location, stmt_len, and possibly queryId.)
41 typedef struct PlannedStmt
45 CmdType commandType; /* select|insert|update|delete|utility */
47 uint32 queryId; /* query identifier (copied from Query) */
49 bool hasReturning; /* is it insert|update|delete RETURNING? */
51 bool hasModifyingCTE; /* has insert|update|delete in WITH? */
53 bool canSetTag; /* do I set the command result tag? */
55 bool transientPlan; /* redo plan when TransactionXmin changes? */
57 bool dependsOnRole; /* is plan specific to current role? */
59 bool parallelModeNeeded; /* parallel mode required to execute? */
61 struct Plan *planTree; /* tree of Plan nodes */
63 List *rtable; /* list of RangeTblEntry nodes */
65 /* rtable indexes of target relations for INSERT/UPDATE/DELETE */
66 List *resultRelations; /* integer list of RT indexes, or NIL */
69 * rtable indexes of non-leaf target relations for UPDATE/DELETE on all
70 * the partitioned table mentioned in the query.
72 List *nonleafResultRelations;
75 * rtable indexes of root target relations for UPDATE/DELETE; this list
76 * maintains a subset of the RT indexes in nonleafResultRelations,
77 * indicating the roots of the respective partition hierarchies.
79 List *rootResultRelations;
81 List *subplans; /* Plan trees for SubPlan expressions; note
82 * that some could be NULL */
84 Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
86 List *rowMarks; /* a list of PlanRowMark's */
88 List *relationOids; /* OIDs of relations the plan depends on */
90 List *invalItems; /* other dependencies, as PlanInvalItems */
92 int nParamExec; /* number of PARAM_EXEC Params used */
94 Node *utilityStmt; /* non-null if this is utility stmt */
96 /* statement location in source string (copied from Query) */
97 int stmt_location; /* start location, or -1 if unknown */
98 int stmt_len; /* length in bytes; 0 means "rest of string" */
101 /* macro for fetching the Plan associated with a SubPlan node */
102 #define exec_subplan_get_plan(plannedstmt, subplan) \
103 ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
109 * All plan nodes "derive" from the Plan structure by having the
110 * Plan structure as the first field. This ensures that everything works
111 * when nodes are cast to Plan's. (node pointers are frequently cast to Plan*
112 * when passed around generically in the executor)
114 * We never actually instantiate any Plan nodes; this is just the common
115 * abstract superclass for all Plan-type nodes.
123 * estimated execution costs for plan (see costsize.c for more info)
125 Cost startup_cost; /* cost expended before fetching any tuples */
126 Cost total_cost; /* total cost (assuming all tuples fetched) */
129 * planner's estimate of result size of this plan step
131 double plan_rows; /* number of rows plan is expected to emit */
132 int plan_width; /* average row width in bytes */
135 * information needed for parallel query
137 bool parallel_aware; /* engage parallel-aware logic? */
138 bool parallel_safe; /* OK to use as part of parallel plan? */
141 * Common structural data for all Plan types.
143 int plan_node_id; /* unique across entire final plan tree */
144 List *targetlist; /* target list to be computed at this node */
145 List *qual; /* implicitly-ANDed qual conditions */
146 struct Plan *lefttree; /* input plan tree(s) */
147 struct Plan *righttree;
148 List *initPlan; /* Init Plan nodes (un-correlated expr
152 * Information for management of parameter-change-driven rescanning
154 * extParam includes the paramIDs of all external PARAM_EXEC params
155 * affecting this plan node or its children. setParam params from the
156 * node's initPlans are not included, but their extParams are.
158 * allParam includes all the extParam paramIDs, plus the IDs of local
159 * params that affect the node (i.e., the setParams of its initplans).
160 * These are _all_ the PARAM_EXEC params that affect this node.
167 * these are defined to avoid confusion problems with "left"
168 * and "right" and "inner" and "outer". The convention is that
169 * the "left" plan is the "outer" plan and the "right" plan is
170 * the inner plan, but these make the code more readable.
173 #define innerPlan(node) (((Plan *)(node))->righttree)
174 #define outerPlan(node) (((Plan *)(node))->lefttree)
179 * If no outer plan, evaluate a variable-free targetlist.
180 * If outer plan, return tuples from outer plan (after a level of
181 * projection as shown by targetlist).
183 * If resconstantqual isn't NULL, it represents a one-time qualification
184 * test (i.e., one that doesn't depend on any variables from the outer plan,
185 * so needs to be evaluated only once).
188 typedef struct Result
191 Node *resconstantqual;
196 * Apply a projection that includes set-returning functions to the
197 * output tuples of the outer plan.
200 typedef struct ProjectSet
207 * Apply rows produced by subplan(s) to result table(s),
208 * by inserting, updating, or deleting.
210 * Note that rowMarks and epqParam are presumed to be valid for all the
211 * subplan(s); they can't contain any info that varies across subplans.
214 typedef struct ModifyTable
217 CmdType operation; /* INSERT, UPDATE, or DELETE */
218 bool canSetTag; /* do we set the command tag/es_processed? */
219 Index nominalRelation; /* Parent RT index for use of EXPLAIN */
220 /* RT indexes of non-leaf tables in a partition tree */
221 List *partitioned_rels;
222 List *resultRelations; /* integer list of RT indexes */
223 int resultRelIndex; /* index of first resultRel in plan's list */
224 int rootResultRelIndex; /* index of the partitioned table root */
225 List *plans; /* plan(s) producing source data */
226 List *withCheckOptionLists; /* per-target-table WCO lists */
227 List *returningLists; /* per-target-table RETURNING tlists */
228 List *fdwPrivLists; /* per-target-table FDW private data lists */
229 Bitmapset *fdwDirectModifyPlans; /* indices of FDW DM plans */
230 List *rowMarks; /* PlanRowMarks (non-locking only) */
231 int epqParam; /* ID of Param for EvalPlanQual re-eval */
232 OnConflictAction onConflictAction; /* ON CONFLICT action */
233 List *arbiterIndexes; /* List of ON CONFLICT arbiter index OIDs */
234 List *onConflictSet; /* SET for INSERT ON CONFLICT DO UPDATE */
235 Node *onConflictWhere; /* WHERE for ON CONFLICT UPDATE */
236 Index exclRelRTI; /* RTI of the EXCLUDED pseudo relation */
237 List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
242 * Generate the concatenation of the results of sub-plans.
245 typedef struct Append
248 /* RT indexes of non-leaf tables in a partition tree */
249 List *partitioned_rels;
255 * Merge the results of pre-sorted sub-plans to preserve the ordering.
258 typedef struct MergeAppend
261 /* RT indexes of non-leaf tables in a partition tree */
262 List *partitioned_rels;
264 /* remaining fields are just like the sort-key info in struct Sort */
265 int numCols; /* number of sort-key columns */
266 AttrNumber *sortColIdx; /* their indexes in the target list */
267 Oid *sortOperators; /* OIDs of operators to sort them by */
268 Oid *collations; /* OIDs of collations */
269 bool *nullsFirst; /* NULLS FIRST/LAST directions */
273 * RecursiveUnion node -
274 * Generate a recursive union of two subplans.
276 * The "outer" subplan is always the non-recursive term, and the "inner"
277 * subplan is the recursive term.
280 typedef struct RecursiveUnion
283 int wtParam; /* ID of Param representing work table */
284 /* Remaining fields are zero/null in UNION ALL case */
285 int numCols; /* number of columns to check for
287 AttrNumber *dupColIdx; /* their indexes in the target list */
288 Oid *dupOperators; /* equality operators to compare with */
289 long numGroups; /* estimated number of groups in input */
294 * Generate the intersection of the results of sub-plans.
296 * The subplans must be of types that yield tuple bitmaps. The targetlist
297 * and qual fields of the plan are unused and are always NIL.
300 typedef struct BitmapAnd
308 * Generate the union of the results of sub-plans.
310 * The subplans must be of types that yield tuple bitmaps. The targetlist
311 * and qual fields of the plan are unused and are always NIL.
314 typedef struct BitmapOr
329 Index scanrelid; /* relid is index into the range table */
333 * sequential scan node
336 typedef Scan SeqScan;
339 * table sample scan node
342 typedef struct SampleScan
345 /* use struct pointer to avoid including parsenodes.h here */
346 struct TableSampleClause *tablesample;
352 * indexqualorig is an implicitly-ANDed list of index qual expressions, each
353 * in the same form it appeared in the query WHERE condition. Each should
354 * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
355 * The indexkey is a Var or expression referencing column(s) of the index's
356 * base table. The comparisonval might be any expression, but it won't use
357 * any columns of the base table. The expressions are ordered by index
358 * column position (but items referencing the same index column can appear
359 * in any order). indexqualorig is used at runtime only if we have to recheck
362 * indexqual has the same form, but the expressions have been commuted if
363 * necessary to put the indexkeys on the left, and the indexkeys are replaced
364 * by Var nodes identifying the index columns (their varno is INDEX_VAR and
365 * their varattno is the index column number).
367 * indexorderbyorig is similarly the original form of any ORDER BY expressions
368 * that are being implemented by the index, while indexorderby is modified to
369 * have index column Vars on the left-hand side. Here, multiple expressions
370 * must appear in exactly the ORDER BY order, and this is not necessarily the
371 * index column order. Only the expressions are provided, not the auxiliary
372 * sort-order information from the ORDER BY SortGroupClauses; it's assumed
373 * that the sort ordering is fully determinable from the top-level operators.
374 * indexorderbyorig is used at runtime to recheck the ordering, if the index
375 * cannot calculate an accurate ordering. It is also needed for EXPLAIN.
377 * indexorderbyops is a list of the OIDs of the operators used to sort the
378 * ORDER BY expressions. This is used together with indexorderbyorig to
379 * recheck ordering at run time. (Note that indexorderby, indexorderbyorig,
380 * and indexorderbyops are used for amcanorderbyop cases, not amcanorder.)
382 * indexorderdir specifies the scan ordering, for indexscans on amcanorder
383 * indexes (for other indexes it should be "don't care").
386 typedef struct IndexScan
389 Oid indexid; /* OID of index to scan */
390 List *indexqual; /* list of index quals (usually OpExprs) */
391 List *indexqualorig; /* the same in original form */
392 List *indexorderby; /* list of index ORDER BY exprs */
393 List *indexorderbyorig; /* the same in original form */
394 List *indexorderbyops; /* OIDs of sort ops for ORDER BY exprs */
395 ScanDirection indexorderdir; /* forward or backward or don't care */
399 * index-only scan node
401 * IndexOnlyScan is very similar to IndexScan, but it specifies an
402 * index-only scan, in which the data comes from the index not the heap.
403 * Because of this, *all* Vars in the plan node's targetlist, qual, and
404 * index expressions reference index columns and have varno = INDEX_VAR.
405 * Hence we do not need separate indexqualorig and indexorderbyorig lists,
406 * since their contents would be equivalent to indexqual and indexorderby.
408 * To help EXPLAIN interpret the index Vars for display, we provide
409 * indextlist, which represents the contents of the index as a targetlist
410 * with one TLE per index column. Vars appearing in this list reference
411 * the base table, and this is the only field in the plan node that may
415 typedef struct IndexOnlyScan
418 Oid indexid; /* OID of index to scan */
419 List *indexqual; /* list of index quals (usually OpExprs) */
420 List *indexorderby; /* list of index ORDER BY exprs */
421 List *indextlist; /* TargetEntry list describing index's cols */
422 ScanDirection indexorderdir; /* forward or backward or don't care */
426 * bitmap index scan node
428 * BitmapIndexScan delivers a bitmap of potential tuple locations;
429 * it does not access the heap itself. The bitmap is used by an
430 * ancestor BitmapHeapScan node, possibly after passing through
431 * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
432 * the results of other BitmapIndexScans.
434 * The fields have the same meanings as for IndexScan, except we don't
435 * store a direction flag because direction is uninteresting.
437 * In a BitmapIndexScan plan node, the targetlist and qual fields are
438 * not used and are always NIL. The indexqualorig field is unused at
439 * run time too, but is saved for the benefit of EXPLAIN.
442 typedef struct BitmapIndexScan
445 Oid indexid; /* OID of index to scan */
446 bool isshared; /* Create shared bitmap if set */
447 List *indexqual; /* list of index quals (OpExprs) */
448 List *indexqualorig; /* the same in original form */
452 * bitmap sequential scan node
454 * This needs a copy of the qual conditions being used by the input index
455 * scans because there are various cases where we need to recheck the quals;
456 * for example, when the bitmap is lossy about the specific rows on a page
457 * that meet the index condition.
460 typedef struct BitmapHeapScan
463 List *bitmapqualorig; /* index quals, in standard expr form */
469 * tidquals is an implicitly OR'ed list of qual expressions of the form
470 * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)".
473 typedef struct TidScan
476 List *tidquals; /* qual(s) involving CTID = something */
482 * SubqueryScan is for scanning the output of a sub-query in the range table.
483 * We often need an extra plan node above the sub-query's plan to perform
484 * expression evaluations (which we can't push into the sub-query without
485 * risking changing its semantics). Although we are not scanning a physical
486 * relation, we make this a descendant of Scan anyway for code-sharing
489 * Note: we store the sub-plan in the type-specific subplan field, not in
490 * the generic lefttree field as you might expect. This is because we do
491 * not want plan-tree-traversal routines to recurse into the subplan without
492 * knowing that they are changing Query contexts.
495 typedef struct SubqueryScan
505 typedef struct FunctionScan
508 List *functions; /* list of RangeTblFunction nodes */
509 bool funcordinality; /* WITH ORDINALITY */
516 typedef struct ValuesScan
519 List *values_lists; /* list of expression lists */
523 * TableFunc scan node
526 typedef struct TableFuncScan
529 TableFunc *tablefunc; /* table function node */
536 typedef struct CteScan
539 int ctePlanId; /* ID of init SubPlan for CTE */
540 int cteParam; /* ID of Param representing CTE output */
544 * NamedTuplestoreScan node
547 typedef struct NamedTuplestoreScan
550 char *enrname; /* Name given to Ephemeral Named Relation */
551 } NamedTuplestoreScan;
557 typedef struct WorkTableScan
560 int wtParam; /* ID of Param representing work table */
566 * fdw_exprs and fdw_private are both under the control of the foreign-data
567 * wrapper, but fdw_exprs is presumed to contain expression trees and will
568 * be post-processed accordingly by the planner; fdw_private won't be.
569 * Note that everything in both lists must be copiable by copyObject().
570 * One way to store an arbitrary blob of bytes is to represent it as a bytea
571 * Const. Usually, though, you'll be better off choosing a representation
572 * that can be dumped usefully by nodeToString().
574 * fdw_scan_tlist is a targetlist describing the contents of the scan tuple
575 * returned by the FDW; it can be NIL if the scan tuple matches the declared
576 * rowtype of the foreign table, which is the normal case for a simple foreign
577 * table scan. (If the plan node represents a foreign join, fdw_scan_tlist
578 * is required since there is no rowtype available from the system catalogs.)
579 * When fdw_scan_tlist is provided, Vars in the node's tlist and quals must
580 * have varno INDEX_VAR, and their varattnos correspond to resnos in the
581 * fdw_scan_tlist (which are also column numbers in the actual scan tuple).
582 * fdw_scan_tlist is never actually executed; it just holds expression trees
583 * describing what is in the scan tuple's columns.
585 * fdw_recheck_quals should contain any quals which the core system passed to
586 * the FDW but which were not added to scan.plan.qual; that is, it should
587 * contain the quals being checked remotely. This is needed for correct
588 * behavior during EvalPlanQual rechecks.
590 * When the plan node represents a foreign join, scan.scanrelid is zero and
591 * fs_relids must be consulted to identify the join relation. (fs_relids
592 * is valid for simple scans as well, but will always match scan.scanrelid.)
595 typedef struct ForeignScan
598 CmdType operation; /* SELECT/INSERT/UPDATE/DELETE */
599 Oid fs_server; /* OID of foreign server */
600 List *fdw_exprs; /* expressions that FDW may evaluate */
601 List *fdw_private; /* private data for FDW */
602 List *fdw_scan_tlist; /* optional tlist describing scan tuple */
603 List *fdw_recheck_quals; /* original quals not in
605 Bitmapset *fs_relids; /* RTIs generated by this scan */
606 bool fsSystemCol; /* true if any "system column" is needed */
612 * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist,
613 * and fs_relids fields apply equally to CustomScan's custom_exprs,
614 * custom_private, custom_scan_tlist, and custom_relids fields. The
615 * convention of setting scan.scanrelid to zero for joins applies as well.
617 * Note that since Plan trees can be copied, custom scan providers *must*
618 * fit all plan data they need into those fields; embedding CustomScan in
619 * a larger struct will not work.
622 struct CustomScanMethods;
624 typedef struct CustomScan
627 uint32 flags; /* mask of CUSTOMPATH_* flags, see
628 * nodes/extensible.h */
629 List *custom_plans; /* list of Plan nodes, if any */
630 List *custom_exprs; /* expressions that custom code may evaluate */
631 List *custom_private; /* private data for custom code */
632 List *custom_scan_tlist; /* optional tlist describing scan
634 Bitmapset *custom_relids; /* RTIs generated by this scan */
635 const struct CustomScanMethods *methods;
647 * jointype: rule for joining tuples from left and right subtrees
648 * inner_unique each outer tuple can match to no more than one inner tuple
649 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
650 * (plan.qual contains conditions that came from WHERE)
652 * When jointype is INNER, joinqual and plan.qual are semantically
653 * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
654 * only joinqual is used to determine whether a match has been found for
655 * the purpose of deciding whether to generate null-extended tuples.
656 * (But plan.qual is still applied before actually returning a tuple.)
657 * For an outer join, only joinquals are allowed to be used as the merge
658 * or hash condition of a merge or hash join.
660 * inner_unique is set if the joinquals are such that no more than one inner
661 * tuple could match any given outer tuple. This allows the executor to
662 * skip searching for additional matches. (This must be provable from just
663 * the joinquals, ignoring plan.qual, due to where the executor tests it.)
671 List *joinqual; /* JOIN quals (in addition to plan.qual) */
675 * nest loop join node
677 * The nestParams list identifies any executor Params that must be passed
678 * into execution of the inner subplan carrying values from the current row
679 * of the outer subplan. Currently we restrict these values to be simple
680 * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
681 * creation, the paramval can actually be a PlaceHolderVar expression; but it
682 * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
685 typedef struct NestLoop
688 List *nestParams; /* list of NestLoopParam nodes */
691 typedef struct NestLoopParam
694 int paramno; /* number of the PARAM_EXEC Param to set */
695 Var *paramval; /* outer-relation Var to assign to Param */
701 * The expected ordering of each mergeable column is described by a btree
702 * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
703 * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
704 * of each mergeclause may be of different datatypes, but they are ordered the
705 * same way according to the common opfamily and collation. The operator in
706 * each mergeclause must be an equality operator of the indicated opfamily.
709 typedef struct MergeJoin
712 bool skip_mark_restore; /* Can we skip mark/restore calls? */
713 List *mergeclauses; /* mergeclauses as expression trees */
714 /* these are arrays, but have the same length as the mergeclauses list: */
715 Oid *mergeFamilies; /* per-clause OIDs of btree opfamilies */
716 Oid *mergeCollations; /* per-clause OIDs of collations */
717 int *mergeStrategies; /* per-clause ordering (ASC or DESC) */
718 bool *mergeNullsFirst; /* per-clause nulls ordering */
725 typedef struct HashJoin
732 * materialization node
735 typedef struct Material
747 int numCols; /* number of sort-key columns */
748 AttrNumber *sortColIdx; /* their indexes in the target list */
749 Oid *sortOperators; /* OIDs of operators to sort them by */
750 Oid *collations; /* OIDs of collations */
751 bool *nullsFirst; /* NULLS FIRST/LAST directions */
756 * Used for queries with GROUP BY (but no aggregates) specified.
757 * The input must be presorted according to the grouping columns.
763 int numCols; /* number of grouping columns */
764 AttrNumber *grpColIdx; /* their indexes in the target list */
765 Oid *grpOperators; /* equality operators to compare with */
771 * An Agg node implements plain or grouped aggregation. For grouped
772 * aggregation, we can work with presorted input or unsorted input;
773 * the latter strategy uses an internal hashtable.
775 * Notice the lack of any direct info about the aggregate functions to be
776 * computed. They are found by scanning the node's tlist and quals during
777 * executor startup. (It is possible that there are no aggregate functions;
778 * this could happen if they get optimized away by constant-folding, or if
779 * we are using the Agg node to implement hash-based grouping.)
785 AggStrategy aggstrategy; /* basic strategy, see nodes.h */
786 AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
787 int numCols; /* number of grouping columns */
788 AttrNumber *grpColIdx; /* their indexes in the target list */
789 Oid *grpOperators; /* equality operators to compare with */
790 long numGroups; /* estimated number of groups in input */
791 Bitmapset *aggParams; /* IDs of Params used in Aggref inputs */
792 /* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */
793 List *groupingSets; /* grouping sets to use */
794 List *chain; /* chained Agg/Sort nodes */
798 * window aggregate node
801 typedef struct WindowAgg
804 Index winref; /* ID referenced by window functions */
805 int partNumCols; /* number of columns in partition clause */
806 AttrNumber *partColIdx; /* their indexes in the target list */
807 Oid *partOperators; /* equality operators for partition columns */
808 int ordNumCols; /* number of columns in ordering clause */
809 AttrNumber *ordColIdx; /* their indexes in the target list */
810 Oid *ordOperators; /* equality operators for ordering columns */
811 int frameOptions; /* frame_clause options, see WindowDef */
812 Node *startOffset; /* expression for starting bound, if any */
813 Node *endOffset; /* expression for ending bound, if any */
820 typedef struct Unique
823 int numCols; /* number of columns to check for uniqueness */
824 AttrNumber *uniqColIdx; /* their indexes in the target list */
825 Oid *uniqOperators; /* equality operators to compare with */
832 typedef struct Gather
837 bool invisible; /* suppress EXPLAIN display (for testing)? */
844 typedef struct GatherMerge
848 /* remaining fields are just like the sort-key info in struct Sort */
849 int numCols; /* number of sort-key columns */
850 AttrNumber *sortColIdx; /* their indexes in the target list */
851 Oid *sortOperators; /* OIDs of operators to sort them by */
852 Oid *collations; /* OIDs of collations */
853 bool *nullsFirst; /* NULLS FIRST/LAST directions */
859 * If the executor is supposed to try to apply skew join optimization, then
860 * skewTable/skewColumn/skewInherit identify the outer relation's join key
861 * column, from which the relevant MCV statistics can be fetched.
867 Oid skewTable; /* outer join key's table OID, or InvalidOid */
868 AttrNumber skewColumn; /* outer join key's column #, or zero */
869 bool skewInherit; /* is outer join rel an inheritance tree? */
870 /* all other info is in the parent HashJoin node */
880 SetOpCmd cmd; /* what to do, see nodes.h */
881 SetOpStrategy strategy; /* how to do it, see nodes.h */
882 int numCols; /* number of columns to check for
884 AttrNumber *dupColIdx; /* their indexes in the target list */
885 Oid *dupOperators; /* equality operators to compare with */
886 AttrNumber flagColIdx; /* where is the flag column, if any */
887 int firstFlag; /* flag value for first input relation */
888 long numGroups; /* estimated number of groups in input */
894 * rowMarks identifies the rels to be locked by this node; it should be
895 * a subset of the rowMarks listed in the top-level PlannedStmt.
896 * epqParam is a Param that all scan nodes below this one must depend on.
897 * It is used to force re-evaluation of the plan during EvalPlanQual.
900 typedef struct LockRows
903 List *rowMarks; /* a list of PlanRowMark's */
904 int epqParam; /* ID of Param for EvalPlanQual re-eval */
910 * Note: as of Postgres 8.2, the offset and count expressions are expected
911 * to yield int8, rather than int4 as before.
917 Node *limitOffset; /* OFFSET parameter, or NULL if none */
918 Node *limitCount; /* COUNT parameter, or NULL if none */
924 * enums for types of row-marking operations
926 * The first four of these values represent different lock strengths that
927 * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
928 * We support these on regular tables, as well as on foreign tables whose FDWs
929 * report support for late locking. For other foreign tables, any locking
930 * that might be done for such requests must happen during the initial row
931 * fetch; their FDWs provide no mechanism for going back to lock a row later.
932 * This means that the semantics will be a bit different than for a local
933 * table; in particular we are likely to lock more rows than would be locked
934 * locally, since remote rows will be locked even if they then fail
935 * locally-checked restriction or join quals. However, the prospect of
936 * doing a separate remote query to lock each selected row is usually pretty
937 * unappealing, so early locking remains a credible design choice for FDWs.
939 * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we have to uniquely
940 * identify all the source rows, not only those from the target relations, so
941 * that we can perform EvalPlanQual rechecking at need. For plain tables we
942 * can just fetch the TID, much as for a target relation; this case is
943 * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
944 * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
945 * pretty inefficient, since most of the time we'll never need the data; but
946 * fortunately the overhead is usually not performance-critical in practice.
947 * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
948 * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
949 * (Again, this probably doesn't make sense if a physical remote fetch is
950 * needed, but for FDWs that map to local storage it might be credible.)
952 typedef enum RowMarkType
954 ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
955 ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
956 ROW_MARK_SHARE, /* obtain shared tuple lock */
957 ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
958 ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
959 ROW_MARK_COPY /* physically copy the row value */
962 #define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
966 * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
968 * When doing UPDATE, DELETE, or SELECT FOR UPDATE/SHARE, we create a separate
969 * PlanRowMark node for each non-target relation in the query. Relations that
970 * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
971 * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
973 * Initially all PlanRowMarks have rti == prti and isParent == false.
974 * When the planner discovers that a relation is the root of an inheritance
975 * tree, it sets isParent true, and adds an additional PlanRowMark to the
976 * list for each child relation (including the target rel itself in its role
977 * as a child). isParent is also set to true for the partitioned child
978 * relations, which are not scanned just like the root parent. The child
979 * entries have rti == child rel's RT index and prti == parent's RT index,
980 * and can therefore be recognized as children by the fact that prti != rti.
981 * The parent's allMarkTypes field gets the OR of (1<<markType) across all
982 * its children (this definition allows children to use different markTypes).
984 * The planner also adds resjunk output columns to the plan that carry
985 * information sufficient to identify the locked or fetched rows. When
986 * markType != ROW_MARK_COPY, these columns are named
987 * tableoid%u OID of table
989 * The tableoid column is only present for an inheritance hierarchy.
990 * When markType == ROW_MARK_COPY, there is instead a single column named
991 * wholerow%u whole-row value of relation
992 * (An inheritance hierarchy could have all three resjunk output columns,
993 * if some children use a different markType than others.)
994 * In all three cases, %u represents the rowmark ID number (rowmarkId).
995 * This number is unique within a plan tree, except that child relation
996 * entries copy their parent's rowmarkId. (Assigning unique numbers
997 * means we needn't renumber rowmarkIds when flattening subqueries, which
998 * would require finding and renaming the resjunk columns as well.)
999 * Note this means that all tables in an inheritance hierarchy share the
1000 * same resjunk column names. However, in an inherited UPDATE/DELETE the
1001 * columns could have different physical column numbers in each subplan.
1003 typedef struct PlanRowMark
1006 Index rti; /* range table index of markable relation */
1007 Index prti; /* range table index of parent relation */
1008 Index rowmarkId; /* unique identifier for resjunk columns */
1009 RowMarkType markType; /* see enum above */
1010 int allMarkTypes; /* OR of (1<<markType) for all children */
1011 LockClauseStrength strength; /* LockingClause's strength, or LCS_NONE */
1012 LockWaitPolicy waitPolicy; /* NOWAIT and SKIP LOCKED options */
1013 bool isParent; /* true if this is a "dummy" parent entry */
1018 * Plan invalidation info
1020 * We track the objects on which a PlannedStmt depends in two ways:
1021 * relations are recorded as a simple list of OIDs, and everything else
1022 * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
1023 * to be used with the syscache invalidation mechanism, so it identifies a
1024 * system catalog entry by cache ID and hash value.
1026 typedef struct PlanInvalItem
1029 int cacheId; /* a syscache ID, see utils/syscache.h */
1030 uint32 hashValue; /* hash value of object's cache lookup key */
1033 #endif /* PLANNODES_H */