PostgreSQL Source Code git master
Loading...
Searching...
No Matches
plannodes.h File Reference
#include "access/sdir.h"
#include "access/stratnum.h"
#include "common/relpath.h"
#include "lib/stringinfo.h"
#include "nodes/bitmapset.h"
#include "nodes/lockoptions.h"
#include "nodes/primnodes.h"
Include dependency graph for plannodes.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PlannedStmt
 
struct  Plan
 
struct  Result
 
struct  ProjectSet
 
struct  ModifyTable
 
struct  Append
 
struct  MergeAppend
 
struct  RecursiveUnion
 
struct  BitmapAnd
 
struct  BitmapOr
 
struct  Scan
 
struct  SeqScan
 
struct  SampleScan
 
struct  IndexScan
 
struct  IndexOnlyScan
 
struct  BitmapIndexScan
 
struct  BitmapHeapScan
 
struct  TidScan
 
struct  TidRangeScan
 
struct  SubqueryScan
 
struct  FunctionScan
 
struct  ValuesScan
 
struct  TableFuncScan
 
struct  CteScan
 
struct  NamedTuplestoreScan
 
struct  WorkTableScan
 
struct  ForeignScan
 
struct  CustomScan
 
struct  Join
 
struct  NestLoop
 
struct  NestLoopParam
 
struct  MergeJoin
 
struct  HashJoin
 
struct  Material
 
struct  Memoize
 
struct  Sort
 
struct  IncrementalSort
 
struct  Group
 
struct  Agg
 
struct  WindowAgg
 
struct  Unique
 
struct  Gather
 
struct  GatherMerge
 
struct  Hash
 
struct  SetOp
 
struct  LockRows
 
struct  Limit
 
struct  PlanRowMark
 
struct  PartitionPruneInfo
 
struct  PartitionedRelPruneInfo
 
struct  PartitionPruneStep
 
struct  PartitionPruneStepOp
 
struct  PartitionPruneStepCombine
 
struct  PlanInvalItem
 
struct  SubPlanRTInfo
 
struct  ElidedNode
 

Macros

#define exec_subplan_get_plan(plannedstmt, subplan)    ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))
 
#define innerPlan(node)   (((Plan *)(node))->righttree)
 
#define outerPlan(node)   (((Plan *)(node))->lefttree)
 
#define RowMarkRequiresRowShareLock(marktype)   ((marktype) <= ROW_MARK_KEYSHARE)
 

Typedefs

typedef enum PlannedStmtOrigin PlannedStmtOrigin
 
typedef struct PlannedStmt PlannedStmt
 
typedef struct Plan Plan
 
typedef enum ResultType ResultType
 
typedef struct Result Result
 
typedef struct ProjectSet ProjectSet
 
typedef struct ModifyTable ModifyTable
 
typedef struct Append Append
 
typedef struct MergeAppend MergeAppend
 
typedef struct RecursiveUnion RecursiveUnion
 
typedef struct BitmapAnd BitmapAnd
 
typedef struct BitmapOr BitmapOr
 
typedef struct Scan Scan
 
typedef struct SeqScan SeqScan
 
typedef struct SampleScan SampleScan
 
typedef struct IndexScan IndexScan
 
typedef struct IndexOnlyScan IndexOnlyScan
 
typedef struct BitmapIndexScan BitmapIndexScan
 
typedef struct BitmapHeapScan BitmapHeapScan
 
typedef struct TidScan TidScan
 
typedef struct TidRangeScan TidRangeScan
 
typedef enum SubqueryScanStatus SubqueryScanStatus
 
typedef struct SubqueryScan SubqueryScan
 
typedef struct FunctionScan FunctionScan
 
typedef struct ValuesScan ValuesScan
 
typedef struct TableFuncScan TableFuncScan
 
typedef struct CteScan CteScan
 
typedef struct NamedTuplestoreScan NamedTuplestoreScan
 
typedef struct WorkTableScan WorkTableScan
 
typedef struct ForeignScan ForeignScan
 
typedef struct CustomScan CustomScan
 
typedef struct Join Join
 
typedef struct NestLoop NestLoop
 
typedef struct NestLoopParam NestLoopParam
 
typedef struct MergeJoin MergeJoin
 
typedef struct HashJoin HashJoin
 
typedef struct Material Material
 
typedef struct Memoize Memoize
 
typedef struct Sort Sort
 
typedef struct IncrementalSort IncrementalSort
 
typedef struct Group Group
 
typedef struct Agg Agg
 
typedef struct WindowAgg WindowAgg
 
typedef struct Unique Unique
 
typedef struct Gather Gather
 
typedef struct GatherMerge GatherMerge
 
typedef struct Hash Hash
 
typedef struct SetOp SetOp
 
typedef struct LockRows LockRows
 
typedef struct Limit Limit
 
typedef enum RowMarkType RowMarkType
 
typedef struct PlanRowMark PlanRowMark
 
typedef struct PartitionPruneInfo PartitionPruneInfo
 
typedef struct PartitionedRelPruneInfo PartitionedRelPruneInfo
 
typedef struct PartitionPruneStep PartitionPruneStep
 
typedef struct PartitionPruneStepOp PartitionPruneStepOp
 
typedef enum PartitionPruneCombineOp PartitionPruneCombineOp
 
typedef struct PartitionPruneStepCombine PartitionPruneStepCombine
 
typedef struct PlanInvalItem PlanInvalItem
 
typedef enum MonotonicFunction MonotonicFunction
 
typedef struct SubPlanRTInfo SubPlanRTInfo
 
typedef struct ElidedNode ElidedNode
 

Enumerations

enum  PlannedStmtOrigin {
  PLAN_STMT_UNKNOWN = 0 , PLAN_STMT_INTERNAL , PLAN_STMT_STANDARD , PLAN_STMT_CACHE_GENERIC ,
  PLAN_STMT_CACHE_CUSTOM
}
 
enum  ResultType {
  RESULT_TYPE_GATING , RESULT_TYPE_SCAN , RESULT_TYPE_JOIN , RESULT_TYPE_UPPER ,
  RESULT_TYPE_MINMAX
}
 
enum  SubqueryScanStatus { SUBQUERY_SCAN_UNKNOWN , SUBQUERY_SCAN_TRIVIAL , SUBQUERY_SCAN_NONTRIVIAL }
 
enum  RowMarkType {
  ROW_MARK_EXCLUSIVE , ROW_MARK_NOKEYEXCLUSIVE , ROW_MARK_SHARE , ROW_MARK_KEYSHARE ,
  ROW_MARK_REFERENCE , ROW_MARK_COPY
}
 
enum  PartitionPruneCombineOp { PARTPRUNE_COMBINE_UNION , PARTPRUNE_COMBINE_INTERSECT }
 
enum  MonotonicFunction { MONOTONICFUNC_NONE = 0 , MONOTONICFUNC_INCREASING = (1 << 0) , MONOTONICFUNC_DECREASING = (1 << 1) , MONOTONICFUNC_BOTH = MONOTONICFUNC_INCREASING | MONOTONICFUNC_DECREASING }
 

Macro Definition Documentation

◆ exec_subplan_get_plan

#define exec_subplan_get_plan (   plannedstmt,
  subplan 
)     ((Plan *) list_nth((plannedstmt)->subplans, (subplan)->plan_id - 1))

Definition at line 175 of file plannodes.h.

191{
193
195
196 /*
197 * estimated execution costs for plan (see costsize.c for more info)
198 */
199 /* count of disabled nodes */
200 int disabled_nodes;
201 /* cost expended before fetching any tuples */
202 Cost startup_cost;
203 /* total cost (assuming all tuples fetched) */
204 Cost total_cost;
205
206 /*
207 * planner's estimate of result size of this plan step
208 */
209 /* number of rows plan is expected to emit */
210 Cardinality plan_rows;
211 /* average row width in bytes */
212 int plan_width;
213
214 /*
215 * information needed for parallel query
216 */
217 /* engage parallel-aware logic? */
218 bool parallel_aware;
219 /* OK to use as part of parallel plan? */
220 bool parallel_safe;
221
222 /*
223 * information needed for asynchronous execution
224 */
225 /* engage asynchronous-capable logic? */
226 bool async_capable;
227
228 /*
229 * Common structural data for all Plan types.
230 */
231 /* unique across entire final plan tree */
232 int plan_node_id;
233 /* target list to be computed at this node */
234 List *targetlist;
235 /* implicitly-ANDed qual conditions */
236 List *qual;
237 /* input plan tree(s) */
238 struct Plan *lefttree;
239 struct Plan *righttree;
240 /* Init Plan nodes (un-correlated expr subselects) */
241 List *initPlan;
242
243 /*
244 * Information for management of parameter-change-driven rescanning
245 *
246 * extParam includes the paramIDs of all external PARAM_EXEC params
247 * affecting this plan node or its children. setParam params from the
248 * node's initPlans are not included, but their extParams are.
249 *
250 * allParam includes all the extParam paramIDs, plus the IDs of local
251 * params that affect the node (i.e., the setParams of its initplans).
252 * These are _all_ the PARAM_EXEC params that affect this node.
253 */
256} Plan;
257
258/* ----------------
259 * these are defined to avoid confusion problems with "left"
260 * and "right" and "inner" and "outer". The convention is that
261 * the "left" plan is the "outer" plan and the "right" plan is
262 * the inner plan, but these make the code more readable.
263 * ----------------
264 */
265#define innerPlan(node) (((Plan *)(node))->righttree)
266#define outerPlan(node) (((Plan *)(node))->lefttree)
267
268
269/* ----------------
270 * ResultType -
271 * Classification of Result nodes
272 * ----------------
273 */
274typedef enum ResultType
275{
276 RESULT_TYPE_GATING, /* project or one-time-filter outer plan */
277 RESULT_TYPE_SCAN, /* replace empty scan */
278 RESULT_TYPE_JOIN, /* replace empty join */
279 RESULT_TYPE_UPPER, /* replace degenerate upper rel */
280 RESULT_TYPE_MINMAX /* implement minmax aggregate */
281} ResultType;
282
283/* ----------------
284 * Result node -
285 * If no outer plan, evaluate a variable-free targetlist.
286 * If outer plan, return tuples from outer plan (after a level of
287 * projection as shown by targetlist).
288 *
289 * If resconstantqual isn't NULL, it represents a one-time qualification
290 * test (i.e., one that doesn't depend on any variables from the outer plan,
291 * so needs to be evaluated only once).
292 *
293 * relids identifies the relation for which this Result node is generating the
294 * tuples. When subplan is not NULL, it should be empty: this node is not
295 * generating anything in that case, just acting on tuples generated by the
296 * subplan. Otherwise, it contains the relids of the planner relation that
297 * the Result represents.
298 * ----------------
299 */
300typedef struct Result
301{
302 Plan plan;
306} Result;
307
308/* ----------------
309 * ProjectSet node -
310 * Apply a projection that includes set-returning functions to the
311 * output tuples of the outer plan.
312 * ----------------
313 */
314typedef struct ProjectSet
315{
316 Plan plan;
317} ProjectSet;
318
319/* ----------------
320 * ModifyTable node -
321 * Apply rows produced by outer plan to result table(s),
322 * by inserting, updating, or deleting.
323 *
324 * If the originally named target table is a partitioned table or inheritance
325 * tree, both nominalRelation and rootRelation contain the RT index of the
326 * partition root or appendrel RTE, which is not otherwise mentioned in the
327 * plan. Otherwise rootRelation is zero. However, nominalRelation will
328 * always be set, as it's the rel that EXPLAIN should claim is the
329 * INSERT/UPDATE/DELETE/MERGE target.
330 *
331 * Note that rowMarks and epqParam are presumed to be valid for all the
332 * table(s); they can't contain any info that varies across tables.
333 * ----------------
334 */
335typedef struct ModifyTable
336{
337 Plan plan;
338 /* INSERT, UPDATE, DELETE, or MERGE */
340 /* do we set the command tag/es_processed? */
341 bool canSetTag;
342 /* Parent RT index for use of EXPLAIN */
344 /* Root RT index, if partitioned/inherited */
346 /* integer list of RT indexes */
348 /* per-target-table update_colnos lists */
350 /* per-target-table WCO lists */
352 /* alias for OLD in RETURNING lists */
353 char *returningOldAlias;
354 /* alias for NEW in RETURNING lists */
355 char *returningNewAlias;
356 /* per-target-table RETURNING tlists */
358 /* per-target-table FDW private data lists */
360 /* indices of FDW DM plans */
362 /* PlanRowMarks (non-locking only) */
363 List *rowMarks;
364 /* ID of Param for EvalPlanQual re-eval */
365 int epqParam;
366 /* ON CONFLICT action */
368 /* List of ON CONFLICT arbiter index OIDs */
370 /* lock strength for ON CONFLICT DO SELECT */
372 /* INSERT ON CONFLICT DO UPDATE targetlist */
374 /* target column numbers for onConflictSet */
376 /* WHERE for ON CONFLICT DO SELECT/UPDATE */
378 /* RTI of the EXCLUDED pseudo relation */
380 /* tlist of the EXCLUDED pseudo relation */
382 /* per-target-table lists of actions for MERGE */
384 /* per-target-table join conditions for MERGE */
387
388struct PartitionPruneInfo; /* forward reference to struct below */
389
390/* ----------------
391 * Append node -
392 * Generate the concatenation of the results of sub-plans.
393 * ----------------
394 */
395typedef struct Append
396{
397 Plan plan;
398
399 /* RTIs of appendrel(s) formed by this node */
401
402 /* sets of RTIs of appendrels consolidated into this node */
404
405 /* plans to run */
407
408 /* # of asynchronous plans */
409 int nasyncplans;
410
411 /*
412 * All 'appendplans' preceding this index are non-partial plans. All
413 * 'appendplans' from this index onwards are partial plans.
414 */
416
417 /*
418 * Index into PlannedStmt.partPruneInfos and parallel lists in EState:
419 * es_part_prune_states and es_part_prune_results. Set to -1 if no
420 * run-time pruning is used.
421 */
423} Append;
424
425/* ----------------
426 * MergeAppend node -
427 * Merge the results of pre-sorted sub-plans to preserve the ordering.
428 * ----------------
429 */
430typedef struct MergeAppend
431{
432 Plan plan;
433
434 /* RTIs of appendrel(s) formed by this node */
436
437 /* sets of RTIs of appendrels consolidated into this node */
439
440 /* plans to run */
442
443 /* these fields are just like the sort-key info in struct Sort: */
444
445 /* number of sort-key columns */
446 int numCols;
447
448 /* their indexes in the target list */
450
451 /* OIDs of operators to sort them by */
452 Oid *sortOperators pg_node_attr(array_size(numCols));
453
454 /* OIDs of collations */
455 Oid *collations pg_node_attr(array_size(numCols));
456
457 /* NULLS FIRST/LAST directions */
459
460 /*
461 * Index into PlannedStmt.partPruneInfos and parallel lists in EState:
462 * es_part_prune_states and es_part_prune_results. Set to -1 if no
463 * run-time pruning is used.
464 */
467
468/* ----------------
469 * RecursiveUnion node -
470 * Generate a recursive union of two subplans.
471 *
472 * The "outer" subplan is always the non-recursive term, and the "inner"
473 * subplan is the recursive term.
474 * ----------------
475 */
476typedef struct RecursiveUnion
477{
478 Plan plan;
479
480 /* ID of Param representing work table */
481 int wtParam;
482
483 /* Remaining fields are zero/null in UNION ALL case */
484
485 /* number of columns to check for duplicate-ness */
486 int numCols;
487
488 /* their indexes in the target list */
490
491 /* equality operators to compare with */
494
495 /* estimated number of groups in input */
498
499/* ----------------
500 * BitmapAnd node -
501 * Generate the intersection of the results of sub-plans.
502 *
503 * The subplans must be of types that yield tuple bitmaps. The targetlist
504 * and qual fields of the plan are unused and are always NIL.
505 * ----------------
506 */
507typedef struct BitmapAnd
508{
509 Plan plan;
511} BitmapAnd;
512
513/* ----------------
514 * BitmapOr node -
515 * Generate the union of the results of sub-plans.
516 *
517 * The subplans must be of types that yield tuple bitmaps. The targetlist
518 * and qual fields of the plan are unused and are always NIL.
519 * ----------------
520 */
521typedef struct BitmapOr
522{
523 Plan plan;
524 bool isshared;
526} BitmapOr;
527
528/*
529 * ==========
530 * Scan nodes
531 *
532 * Scan is an abstract type that all relation scan plan types inherit from.
533 * ==========
534 */
535typedef struct Scan
536{
537 pg_node_attr(abstract)
538
539 Plan plan;
540 /* relid is index into the range table */
542} Scan;
543
544/* ----------------
545 * sequential scan node
546 * ----------------
547 */
548typedef struct SeqScan
549{
550 Scan scan;
551} SeqScan;
552
553/* ----------------
554 * table sample scan node
555 * ----------------
556 */
557typedef struct SampleScan
558{
559 Scan scan;
560 /* use struct pointer to avoid including parsenodes.h here */
561 struct TableSampleClause *tablesample;
562} SampleScan;
563
564/* ----------------
565 * index scan node
566 *
567 * indexqualorig is an implicitly-ANDed list of index qual expressions, each
568 * in the same form it appeared in the query WHERE condition. Each should
569 * be of the form (indexkey OP comparisonval) or (comparisonval OP indexkey).
570 * The indexkey is a Var or expression referencing column(s) of the index's
571 * base table. The comparisonval might be any expression, but it won't use
572 * any columns of the base table. The expressions are ordered by index
573 * column position (but items referencing the same index column can appear
574 * in any order). indexqualorig is used at runtime only if we have to recheck
575 * a lossy indexqual.
576 *
577 * indexqual has the same form, but the expressions have been commuted if
578 * necessary to put the indexkeys on the left, and the indexkeys are replaced
579 * by Var nodes identifying the index columns (their varno is INDEX_VAR and
580 * their varattno is the index column number).
581 *
582 * indexorderbyorig is similarly the original form of any ORDER BY expressions
583 * that are being implemented by the index, while indexorderby is modified to
584 * have index column Vars on the left-hand side. Here, multiple expressions
585 * must appear in exactly the ORDER BY order, and this is not necessarily the
586 * index column order. Only the expressions are provided, not the auxiliary
587 * sort-order information from the ORDER BY SortGroupClauses; it's assumed
588 * that the sort ordering is fully determinable from the top-level operators.
589 * indexorderbyorig is used at runtime to recheck the ordering, if the index
590 * cannot calculate an accurate ordering. It is also needed for EXPLAIN.
591 *
592 * indexorderbyops is a list of the OIDs of the operators used to sort the
593 * ORDER BY expressions. This is used together with indexorderbyorig to
594 * recheck ordering at run time. (Note that indexorderby, indexorderbyorig,
595 * and indexorderbyops are used for amcanorderbyop cases, not amcanorder.)
596 *
597 * indexorderdir specifies the scan ordering, for indexscans on amcanorder
598 * indexes (for other indexes it should be "don't care").
599 * ----------------
600 */
601typedef struct IndexScan
602{
603 Scan scan;
604 /* OID of index to scan */
605 Oid indexid;
606 /* list of index quals (usually OpExprs) */
607 List *indexqual;
608 /* the same in original form */
609 List *indexqualorig;
610 /* list of index ORDER BY exprs */
611 List *indexorderby;
612 /* the same in original form */
613 List *indexorderbyorig;
614 /* OIDs of sort ops for ORDER BY exprs */
615 List *indexorderbyops;
616 /* forward or backward or don't care */
617 ScanDirection indexorderdir;
618} IndexScan;
619
620/* ----------------
621 * index-only scan node
622 *
623 * IndexOnlyScan is very similar to IndexScan, but it specifies an
624 * index-only scan, in which the data comes from the index not the heap.
625 * Because of this, *all* Vars in the plan node's targetlist, qual, and
626 * index expressions reference index columns and have varno = INDEX_VAR.
627 *
628 * We could almost use indexqual directly against the index's output tuple
629 * when rechecking lossy index operators, but that won't work for quals on
630 * index columns that are not retrievable. Hence, recheckqual is needed
631 * for rechecks: it expresses the same condition as indexqual, but using
632 * only index columns that are retrievable. (We will not generate an
633 * index-only scan if this is not possible. An example is that if an
634 * index has table column "x" in a retrievable index column "ind1", plus
635 * an expression f(x) in a non-retrievable column "ind2", an indexable
636 * query on f(x) will use "ind2" in indexqual and f(ind1) in recheckqual.
637 * Without the "ind1" column, an index-only scan would be disallowed.)
638 *
639 * We don't currently need a recheckable equivalent of indexorderby,
640 * because we don't support lossy operators in index ORDER BY.
641 *
642 * To help EXPLAIN interpret the index Vars for display, we provide
643 * indextlist, which represents the contents of the index as a targetlist
644 * with one TLE per index column. Vars appearing in this list reference
645 * the base table, and this is the only field in the plan node that may
646 * contain such Vars. Also, for the convenience of setrefs.c, TLEs in
647 * indextlist are marked as resjunk if they correspond to columns that
648 * the index AM cannot reconstruct.
649 * ----------------
650 */
651typedef struct IndexOnlyScan
652{
653 Scan scan;
654 /* OID of index to scan */
655 Oid indexid;
656 /* list of index quals (usually OpExprs) */
657 List *indexqual;
658 /* index quals in recheckable form */
659 List *recheckqual;
660 /* list of index ORDER BY exprs */
661 List *indexorderby;
662 /* TargetEntry list describing index's cols */
663 List *indextlist;
664 /* forward or backward or don't care */
665 ScanDirection indexorderdir;
667
668/* ----------------
669 * bitmap index scan node
670 *
671 * BitmapIndexScan delivers a bitmap of potential tuple locations;
672 * it does not access the heap itself. The bitmap is used by an
673 * ancestor BitmapHeapScan node, possibly after passing through
674 * intermediate BitmapAnd and/or BitmapOr nodes to combine it with
675 * the results of other BitmapIndexScans.
676 *
677 * The fields have the same meanings as for IndexScan, except we don't
678 * store a direction flag because direction is uninteresting.
679 *
680 * In a BitmapIndexScan plan node, the targetlist and qual fields are
681 * not used and are always NIL. The indexqualorig field is unused at
682 * run time too, but is saved for the benefit of EXPLAIN.
683 * ----------------
684 */
685typedef struct BitmapIndexScan
686{
687 Scan scan;
688 /* OID of index to scan */
689 Oid indexid;
690 /* Create shared bitmap if set */
691 bool isshared;
692 /* list of index quals (OpExprs) */
693 List *indexqual;
694 /* the same in original form */
695 List *indexqualorig;
697
698/* ----------------
699 * bitmap sequential scan node
700 *
701 * This needs a copy of the qual conditions being used by the input index
702 * scans because there are various cases where we need to recheck the quals;
703 * for example, when the bitmap is lossy about the specific rows on a page
704 * that meet the index condition.
705 * ----------------
706 */
707typedef struct BitmapHeapScan
708{
709 Scan scan;
710 /* index quals, in standard expr form */
711 List *bitmapqualorig;
713
714/* ----------------
715 * tid scan node
716 *
717 * tidquals is an implicitly OR'ed list of qual expressions of the form
718 * "CTID = pseudoconstant", or "CTID = ANY(pseudoconstant_array)",
719 * or a CurrentOfExpr for the relation.
720 * ----------------
721 */
722typedef struct TidScan
723{
724 Scan scan;
725 /* qual(s) involving CTID = something */
726 List *tidquals;
727} TidScan;
728
729/* ----------------
730 * tid range scan node
731 *
732 * tidrangequals is an implicitly AND'ed list of qual expressions of the form
733 * "CTID relop pseudoconstant", where relop is one of >,>=,<,<=.
734 * ----------------
735 */
736typedef struct TidRangeScan
737{
738 Scan scan;
739 /* qual(s) involving CTID op something */
740 List *tidrangequals;
742
743/* ----------------
744 * subquery scan node
745 *
746 * SubqueryScan is for scanning the output of a sub-query in the range table.
747 * We often need an extra plan node above the sub-query's plan to perform
748 * expression evaluations (which we can't push into the sub-query without
749 * risking changing its semantics). Although we are not scanning a physical
750 * relation, we make this a descendant of Scan anyway for code-sharing
751 * purposes.
752 *
753 * SubqueryScanStatus caches the trivial_subqueryscan property of the node.
754 * SUBQUERY_SCAN_UNKNOWN means not yet determined. This is only used during
755 * planning.
756 *
757 * Note: we store the sub-plan in the type-specific subplan field, not in
758 * the generic lefttree field as you might expect. This is because we do
759 * not want plan-tree-traversal routines to recurse into the subplan without
760 * knowing that they are changing Query contexts.
761 * ----------------
762 */
763typedef enum SubqueryScanStatus
764{
769
770typedef struct SubqueryScan
771{
772 Scan scan;
773 Plan *subplan;
774 SubqueryScanStatus scanstatus;
776
777/* ----------------
778 * FunctionScan node
779 * ----------------
780 */
781typedef struct FunctionScan
782{
783 Scan scan;
784 /* list of RangeTblFunction nodes */
786 /* WITH ORDINALITY */
787 bool funcordinality;
789
790/* ----------------
791 * ValuesScan node
792 * ----------------
793 */
794typedef struct ValuesScan
795{
796 Scan scan;
797 /* list of expression lists */
798 List *values_lists;
799} ValuesScan;
800
801/* ----------------
802 * TableFunc scan node
803 * ----------------
804 */
805typedef struct TableFuncScan
806{
807 Scan scan;
808 /* table function node */
809 TableFunc *tablefunc;
811
812/* ----------------
813 * CteScan node
814 * ----------------
815 */
816typedef struct CteScan
817{
818 Scan scan;
819 /* ID of init SubPlan for CTE */
820 int ctePlanId;
821 /* ID of Param representing CTE output */
822 int cteParam;
823} CteScan;
824
825/* ----------------
826 * NamedTuplestoreScan node
827 * ----------------
828 */
829typedef struct NamedTuplestoreScan
830{
831 Scan scan;
832 /* Name given to Ephemeral Named Relation */
833 char *enrname;
835
836/* ----------------
837 * WorkTableScan node
838 * ----------------
839 */
840typedef struct WorkTableScan
841{
842 Scan scan;
843 /* ID of Param representing work table */
844 int wtParam;
846
847/* ----------------
848 * ForeignScan node
849 *
850 * fdw_exprs and fdw_private are both under the control of the foreign-data
851 * wrapper, but fdw_exprs is presumed to contain expression trees and will
852 * be post-processed accordingly by the planner; fdw_private won't be.
853 * Note that everything in both lists must be copiable by copyObject().
854 * One way to store an arbitrary blob of bytes is to represent it as a bytea
855 * Const. Usually, though, you'll be better off choosing a representation
856 * that can be dumped usefully by nodeToString().
857 *
858 * fdw_scan_tlist is a targetlist describing the contents of the scan tuple
859 * returned by the FDW; it can be NIL if the scan tuple matches the declared
860 * rowtype of the foreign table, which is the normal case for a simple foreign
861 * table scan. (If the plan node represents a foreign join, fdw_scan_tlist
862 * is required since there is no rowtype available from the system catalogs.)
863 * When fdw_scan_tlist is provided, Vars in the node's tlist and quals must
864 * have varno INDEX_VAR, and their varattnos correspond to resnos in the
865 * fdw_scan_tlist (which are also column numbers in the actual scan tuple).
866 * fdw_scan_tlist is never actually executed; it just holds expression trees
867 * describing what is in the scan tuple's columns.
868 *
869 * fdw_recheck_quals should contain any quals which the core system passed to
870 * the FDW but which were not added to scan.plan.qual; that is, it should
871 * contain the quals being checked remotely. This is needed for correct
872 * behavior during EvalPlanQual rechecks.
873 *
874 * When the plan node represents a foreign join, scan.scanrelid is zero and
875 * fs_relids must be consulted to identify the join relation. (fs_relids
876 * is valid for simple scans as well, but will always match scan.scanrelid.)
877 * fs_relids includes outer joins; fs_base_relids does not.
878 *
879 * If the FDW's PlanDirectModify() callback decides to repurpose a ForeignScan
880 * node to perform the UPDATE or DELETE operation directly in the remote
881 * server, it sets 'operation' and 'resultRelation' to identify the operation
882 * type and target relation. Note that these fields are only set if the
883 * modification is performed *fully* remotely; otherwise, the modification is
884 * driven by a local ModifyTable node and 'operation' is left to CMD_SELECT.
885 * ----------------
886 */
887typedef struct ForeignScan
888{
889 Scan scan;
890 /* SELECT/INSERT/UPDATE/DELETE */
891 CmdType operation;
892 /* direct modification target's RT index */
893 Index resultRelation;
894 /* user to perform the scan as; 0 means to check as current user */
895 Oid checkAsUser;
896 /* OID of foreign server */
897 Oid fs_server;
898 /* expressions that FDW may evaluate */
899 List *fdw_exprs;
900 /* private data for FDW */
901 List *fdw_private;
902 /* optional tlist describing scan tuple */
903 List *fdw_scan_tlist;
904 /* original quals not in scan.plan.qual */
905 List *fdw_recheck_quals;
906 /* base+OJ RTIs generated by this scan */
907 Bitmapset *fs_relids;
908 /* base RTIs generated by this scan */
909 Bitmapset *fs_base_relids;
910 /* true if any "system column" is needed */
911 bool fsSystemCol;
913
914/* ----------------
915 * CustomScan node
916 *
917 * The comments for ForeignScan's fdw_exprs, fdw_private, fdw_scan_tlist,
918 * and fs_relids fields apply equally to CustomScan's custom_exprs,
919 * custom_private, custom_scan_tlist, and custom_relids fields. The
920 * convention of setting scan.scanrelid to zero for joins applies as well.
921 *
922 * Note that since Plan trees can be copied, custom scan providers *must*
923 * fit all plan data they need into those fields; embedding CustomScan in
924 * a larger struct will not work.
925 * ----------------
926 */
927struct CustomScanMethods;
928
929typedef struct CustomScan
930{
931 Scan scan;
932 /* mask of CUSTOMPATH_* flags, see nodes/extensible.h */
933 uint32 flags;
934 /* list of Plan nodes, if any */
935 List *custom_plans;
936 /* expressions that custom code may evaluate */
937 List *custom_exprs;
938 /* private data for custom code */
939 List *custom_private;
940 /* optional tlist describing scan tuple */
941 List *custom_scan_tlist;
942 /* RTIs generated by this scan */
943 Bitmapset *custom_relids;
944
945 /*
946 * NOTE: The method field of CustomScan is required to be a pointer to a
947 * static table of callback functions. So we don't copy the table itself,
948 * just reference the original one.
949 */
950 const struct CustomScanMethods *methods;
951} CustomScan;
952
953/*
954 * ==========
955 * Join nodes
956 * ==========
957 */
958
959/* ----------------
960 * Join node
961 *
962 * jointype: rule for joining tuples from left and right subtrees
963 * inner_unique each outer tuple can match to no more than one inner tuple
964 * joinqual: qual conditions that came from JOIN/ON or JOIN/USING
965 * (plan.qual contains conditions that came from WHERE)
966 *
967 * When jointype is INNER, joinqual and plan.qual are semantically
968 * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
969 * only joinqual is used to determine whether a match has been found for
970 * the purpose of deciding whether to generate null-extended tuples.
971 * (But plan.qual is still applied before actually returning a tuple.)
972 * For an outer join, only joinquals are allowed to be used as the merge
973 * or hash condition of a merge or hash join.
974 *
975 * inner_unique is set if the joinquals are such that no more than one inner
976 * tuple could match any given outer tuple. This allows the executor to
977 * skip searching for additional matches. (This must be provable from just
978 * the joinquals, ignoring plan.qual, due to where the executor tests it.)
979 * ----------------
980 */
981typedef struct Join
982{
983 pg_node_attr(abstract)
984
985 Plan plan;
986 JoinType jointype;
987 bool inner_unique;
988 /* JOIN quals (in addition to plan.qual) */
989 List *joinqual;
990} Join;
991
992/* ----------------
993 * nest loop join node
994 *
995 * The nestParams list identifies any executor Params that must be passed
996 * into execution of the inner subplan carrying values from the current row
997 * of the outer subplan. Currently we restrict these values to be simple
998 * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
999 * creation, the paramval can actually be a PlaceHolderVar expression; but it
1000 * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
1001 * ----------------
1002 */
1003typedef struct NestLoop
1004{
1005 Join join;
1006 /* list of NestLoopParam nodes */
1007 List *nestParams;
1008} NestLoop;
1009
1010typedef struct NestLoopParam
1011{
1013
1014 NodeTag type;
1015 /* number of the PARAM_EXEC Param to set */
1016 int paramno;
1017 /* outer-relation Var to assign to Param */
1018 Var *paramval;
1020
1021/* ----------------
1022 * merge join node
1023 *
1024 * The expected ordering of each mergeable column is described by a btree
1025 * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
1026 * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
1027 * of each mergeclause may be of different datatypes, but they are ordered the
1028 * same way according to the common opfamily and collation. The operator in
1029 * each mergeclause must be an equality operator of the indicated opfamily.
1030 * ----------------
1031 */
1032typedef struct MergeJoin
1033{
1034 Join join;
1035
1036 /* Can we skip mark/restore calls? */
1037 bool skip_mark_restore;
1038
1039 /* mergeclauses as expression trees */
1040 List *mergeclauses;
1041
1042 /* these are arrays, but have the same length as the mergeclauses list: */
1043
1044 /* per-clause OIDs of btree opfamilies */
1045 Oid *mergeFamilies pg_node_attr(array_size(mergeclauses));
1046
1047 /* per-clause OIDs of collations */
1049
1050 /* per-clause ordering (ASC or DESC) */
1051 bool *mergeReversals pg_node_attr(array_size(mergeclauses));
1052
1053 /* per-clause nulls ordering */
1054 bool *mergeNullsFirst pg_node_attr(array_size(mergeclauses));
1055} MergeJoin;
1056
1057/* ----------------
1058 * hash join node
1059 * ----------------
1060 */
1061typedef struct HashJoin
1062{
1063 Join join;
1064 List *hashclauses;
1065 List *hashoperators;
1066 List *hashcollations;
1067
1068 /*
1069 * List of expressions to be hashed for tuples from the outer plan, to
1070 * perform lookups in the hashtable over the inner plan.
1071 */
1072 List *hashkeys;
1073} HashJoin;
1074
1075/* ----------------
1076 * materialization node
1077 * ----------------
1078 */
1079typedef struct Material
1080{
1081 Plan plan;
1082} Material;
1083
1084/* ----------------
1085 * memoize node
1086 * ----------------
1087 */
1088typedef struct Memoize
1089{
1090 Plan plan;
1091
1092 /* size of the two arrays below */
1093 int numKeys;
1094
1095 /* hash operators for each key */
1097
1098 /* collations for each key */
1099 Oid *collations pg_node_attr(array_size(numKeys));
1100
1101 /* cache keys in the form of exprs containing parameters */
1102 List *param_exprs;
1103
1104 /*
1105 * true if the cache entry should be marked as complete after we store the
1106 * first tuple in it.
1107 */
1108 bool singlerow;
1109
1110 /*
1111 * true when cache key should be compared bit by bit, false when using
1112 * hash equality ops
1113 */
1114 bool binary_mode;
1115
1116 /*
1117 * The maximum number of entries that the planner expects will fit in the
1118 * cache, or 0 if unknown
1119 */
1120 uint32 est_entries;
1121
1122 /* paramids from param_exprs */
1123 Bitmapset *keyparamids;
1124
1125 /* Estimated number of rescans, for EXPLAIN */
1126 Cardinality est_calls;
1127
1128 /* Estimated number of distinct lookup keys, for EXPLAIN */
1129 Cardinality est_unique_keys;
1130
1131 /* Estimated cache hit ratio, for EXPLAIN */
1132 double est_hit_ratio;
1133
1134} Memoize;
1135
1136/* ----------------
1137 * sort node
1138 * ----------------
1139 */
1140typedef struct Sort
1141{
1142 Plan plan;
1143
1144 /* number of sort-key columns */
1145 int numCols;
1146
1147 /* their indexes in the target list */
1148 AttrNumber *sortColIdx pg_node_attr(array_size(numCols));
1149
1150 /* OIDs of operators to sort them by */
1151 Oid *sortOperators pg_node_attr(array_size(numCols));
1152
1153 /* OIDs of collations */
1154 Oid *collations pg_node_attr(array_size(numCols));
1155
1156 /* NULLS FIRST/LAST directions */
1157 bool *nullsFirst pg_node_attr(array_size(numCols));
1158} Sort;
1159
1160/* ----------------
1161 * incremental sort node
1162 * ----------------
1163 */
1164typedef struct IncrementalSort
1165{
1166 Sort sort;
1167 /* number of presorted columns */
1168 int nPresortedCols;
1170
1171/* ---------------
1172 * group node -
1173 * Used for queries with GROUP BY (but no aggregates) specified.
1174 * The input must be presorted according to the grouping columns.
1175 * ---------------
1176 */
1177typedef struct Group
1178{
1179 Plan plan;
1180
1181 /* number of grouping columns */
1182 int numCols;
1183
1184 /* their indexes in the target list */
1186
1187 /* equality operators to compare with */
1190} Group;
1191
1192/* ---------------
1193 * aggregate node
1194 *
1195 * An Agg node implements plain or grouped aggregation. For grouped
1196 * aggregation, we can work with presorted input or unsorted input;
1197 * the latter strategy uses an internal hashtable.
1198 *
1199 * Notice the lack of any direct info about the aggregate functions to be
1200 * computed. They are found by scanning the node's tlist and quals during
1201 * executor startup. (It is possible that there are no aggregate functions;
1202 * this could happen if they get optimized away by constant-folding, or if
1203 * we are using the Agg node to implement hash-based grouping.)
1204 * ---------------
1205 */
1206typedef struct Agg
1207{
1208 Plan plan;
1209
1210 /* basic strategy, see nodes.h */
1211 AggStrategy aggstrategy;
1212
1213 /* agg-splitting mode, see nodes.h */
1214 AggSplit aggsplit;
1215
1216 /* number of grouping columns */
1217 int numCols;
1218
1219 /* their indexes in the target list */
1221
1222 /* equality operators to compare with */
1225
1226 /* estimated number of groups in input */
1227 Cardinality numGroups;
1228
1229 /* for pass-by-ref transition data */
1230 uint64 transitionSpace;
1231
1232 /* IDs of Params used in Aggref inputs */
1233 Bitmapset *aggParams;
1234
1235 /* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */
1236
1237 /* grouping sets to use */
1238 List *groupingSets;
1239
1240 /* chained Agg/Sort nodes */
1241 List *chain;
1242} Agg;
1243
1244/* ----------------
1245 * window aggregate node
1246 * ----------------
1247 */
1248typedef struct WindowAgg
1249{
1250 Plan plan;
1251
1252 /* name of WindowClause implemented by this node */
1253 char *winname;
1254
1255 /* ID referenced by window functions */
1256 Index winref;
1257
1258 /* number of columns in partition clause */
1259 int partNumCols;
1260
1261 /* their indexes in the target list */
1263
1264 /* equality operators for partition columns */
1266
1267 /* collations for partition columns */
1269
1270 /* number of columns in ordering clause */
1271 int ordNumCols;
1272
1273 /* their indexes in the target list */
1275
1276 /* equality operators for ordering columns */
1278
1279 /* collations for ordering columns */
1281
1282 /* frame_clause options, see WindowDef */
1283 int frameOptions;
1284
1285 /* expression for starting bound, if any */
1286 Node *startOffset;
1287
1288 /* expression for ending bound, if any */
1289 Node *endOffset;
1290
1291 /* qual to help short-circuit execution */
1292 List *runCondition;
1293
1294 /* runCondition for display in EXPLAIN */
1295 List *runConditionOrig;
1296
1297 /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */
1298
1299 /* in_range function for startOffset */
1300 Oid startInRangeFunc;
1301
1302 /* in_range function for endOffset */
1303 Oid endInRangeFunc;
1304
1305 /* collation for in_range tests */
1306 Oid inRangeColl;
1307
1308 /* use ASC sort order for in_range tests? */
1309 bool inRangeAsc;
1310
1311 /* nulls sort first for in_range tests? */
1312 bool inRangeNullsFirst;
1313
1314 /*
1315 * false for all apart from the WindowAgg that's closest to the root of
1316 * the plan
1317 */
1318 bool topWindow;
1319} WindowAgg;
1320
1321/* ----------------
1322 * unique node
1323 * ----------------
1324 */
1325typedef struct Unique
1326{
1327 Plan plan;
1328
1329 /* number of columns to check for uniqueness */
1330 int numCols;
1331
1332 /* their indexes in the target list */
1334
1335 /* equality operators to compare with */
1337
1338 /* collations for equality comparisons */
1340} Unique;
1341
1342/* ------------
1343 * gather node
1344 *
1345 * Note: rescan_param is the ID of a PARAM_EXEC parameter slot. That slot
1346 * will never actually contain a value, but the Gather node must flag it as
1347 * having changed whenever it is rescanned. The child parallel-aware scan
1348 * nodes are marked as depending on that parameter, so that the rescan
1349 * machinery is aware that their output is likely to change across rescans.
1350 * In some cases we don't need a rescan Param, so rescan_param is set to -1.
1351 * ------------
1352 */
1353typedef struct Gather
1354{
1355 Plan plan;
1356 /* planned number of worker processes */
1357 int num_workers;
1358 /* ID of Param that signals a rescan, or -1 */
1359 int rescan_param;
1360 /* don't execute plan more than once */
1361 bool single_copy;
1362 /* suppress EXPLAIN display (for testing)? */
1363 bool invisible;
1364
1365 /*
1366 * param id's of initplans which are referred at gather or one of its
1367 * child nodes
1368 */
1369 Bitmapset *initParam;
1370} Gather;
1371
1372/* ------------
1373 * gather merge node
1374 * ------------
1375 */
1376typedef struct GatherMerge
1377{
1378 Plan plan;
1379
1380 /* planned number of worker processes */
1381 int num_workers;
1382
1383 /* ID of Param that signals a rescan, or -1 */
1384 int rescan_param;
1385
1386 /* remaining fields are just like the sort-key info in struct Sort */
1387
1388 /* number of sort-key columns */
1389 int numCols;
1390
1391 /* their indexes in the target list */
1392 AttrNumber *sortColIdx pg_node_attr(array_size(numCols));
1393
1394 /* OIDs of operators to sort them by */
1395 Oid *sortOperators pg_node_attr(array_size(numCols));
1396
1397 /* OIDs of collations */
1398 Oid *collations pg_node_attr(array_size(numCols));
1399
1400 /* NULLS FIRST/LAST directions */
1401 bool *nullsFirst pg_node_attr(array_size(numCols));
1402
1403 /*
1404 * param id's of initplans which are referred at gather merge or one of
1405 * its child nodes
1406 */
1407 Bitmapset *initParam;
1408} GatherMerge;
1409
1410/* ----------------
1411 * hash build node
1412 *
1413 * If the executor is supposed to try to apply skew join optimization, then
1414 * skewTable/skewColumn/skewInherit identify the outer relation's join key
1415 * column, from which the relevant MCV statistics can be fetched.
1416 * ----------------
1417 */
1418typedef struct Hash
1419{
1420 Plan plan;
1421
1422 /*
1423 * List of expressions to be hashed for tuples from Hash's outer plan,
1424 * needed to put them into the hashtable.
1425 */
1426 /* hash keys for the hashjoin condition */
1427 List *hashkeys;
1428 /* outer join key's table OID, or InvalidOid */
1429 Oid skewTable;
1430 /* outer join key's column #, or zero */
1431 AttrNumber skewColumn;
1432 /* is outer join rel an inheritance tree? */
1433 bool skewInherit;
1434 /* all other info is in the parent HashJoin node */
1435 /* estimate total rows if parallel_aware */
1436 Cardinality rows_total;
1437} Hash;
1438
1439/* ----------------
1440 * setop node
1441 * ----------------
1442 */
1443typedef struct SetOp
1444{
1445 Plan plan;
1446
1447 /* what to do, see nodes.h */
1448 SetOpCmd cmd;
1449
1450 /* how to do it, see nodes.h */
1451 SetOpStrategy strategy;
1452
1453 /* number of columns to compare */
1454 int numCols;
1455
1456 /* their indexes in the target list */
1458
1459 /* comparison operators (either equality operators or sort operators) */
1462
1463 /* nulls-first flags if sorting, otherwise not interesting */
1464 bool *cmpNullsFirst pg_node_attr(array_size(numCols));
1465
1466 /* estimated number of groups in left input */
1467 Cardinality numGroups;
1468} SetOp;
1469
1470/* ----------------
1471 * lock-rows node
1472 *
1473 * rowMarks identifies the rels to be locked by this node; it should be
1474 * a subset of the rowMarks listed in the top-level PlannedStmt.
1475 * epqParam is a Param that all scan nodes below this one must depend on.
1476 * It is used to force re-evaluation of the plan during EvalPlanQual.
1477 * ----------------
1478 */
1479typedef struct LockRows
1480{
1481 Plan plan;
1482 /* a list of PlanRowMark's */
1483 List *rowMarks;
1484 /* ID of Param for EvalPlanQual re-eval */
1485 int epqParam;
1486} LockRows;
1487
1488/* ----------------
1489 * limit node
1490 *
1491 * Note: as of Postgres 8.2, the offset and count expressions are expected
1492 * to yield int8, rather than int4 as before.
1493 * ----------------
1494 */
1495typedef struct Limit
1496{
1497 Plan plan;
1498
1499 /* OFFSET parameter, or NULL if none */
1500 Node *limitOffset;
1501
1502 /* COUNT parameter, or NULL if none */
1503 Node *limitCount;
1504
1505 /* limit type */
1506 LimitOption limitOption;
1507
1508 /* number of columns to check for similarity */
1509 int uniqNumCols;
1510
1511 /* their indexes in the target list */
1513
1514 /* equality operators to compare with */
1516
1517 /* collations for equality comparisons */
1519} Limit;
1520
1521
1522/*
1523 * RowMarkType -
1524 * enums for types of row-marking operations
1525 *
1526 * The first four of these values represent different lock strengths that
1527 * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
1528 * We support these on regular tables, as well as on foreign tables whose FDWs
1529 * report support for late locking. For other foreign tables, any locking
1530 * that might be done for such requests must happen during the initial row
1531 * fetch; their FDWs provide no mechanism for going back to lock a row later.
1532 * This means that the semantics will be a bit different than for a local
1533 * table; in particular we are likely to lock more rows than would be locked
1534 * locally, since remote rows will be locked even if they then fail
1535 * locally-checked restriction or join quals. However, the prospect of
1536 * doing a separate remote query to lock each selected row is usually pretty
1537 * unappealing, so early locking remains a credible design choice for FDWs.
1538 *
1539 * When doing UPDATE/DELETE/MERGE/SELECT FOR UPDATE/SHARE, we have to uniquely
1540 * identify all the source rows, not only those from the target relations, so
1541 * that we can perform EvalPlanQual rechecking at need. For plain tables we
1542 * can just fetch the TID, much as for a target relation; this case is
1543 * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
1544 * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
1545 * pretty inefficient, since most of the time we'll never need the data; but
1546 * fortunately the overhead is usually not performance-critical in practice.
1547 * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
1548 * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
1549 * (Again, this probably doesn't make sense if a physical remote fetch is
1550 * needed, but for FDWs that map to local storage it might be credible.)
1551 */
1552typedef enum RowMarkType
1553{
1554 ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
1555 ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
1556 ROW_MARK_SHARE, /* obtain shared tuple lock */
1557 ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
1558 ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
1559 ROW_MARK_COPY, /* physically copy the row value */
1560} RowMarkType;
1561
1562#define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
1563
1564/*
1565 * PlanRowMark -
1566 * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
1567 *
1568 * When doing UPDATE/DELETE/MERGE/SELECT FOR UPDATE/SHARE, we create a separate
1569 * PlanRowMark node for each non-target relation in the query. Relations that
1570 * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
1571 * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
1572 *
1573 * Initially all PlanRowMarks have rti == prti and isParent == false.
1574 * When the planner discovers that a relation is the root of an inheritance
1575 * tree, it sets isParent true, and adds an additional PlanRowMark to the
1576 * list for each child relation (including the target rel itself in its role
1577 * as a child, if it is not a partitioned table). Any non-leaf partitioned
1578 * child relations will also have entries with isParent = true. The child
1579 * entries have rti == child rel's RT index and prti == top parent's RT index,
1580 * and can therefore be recognized as children by the fact that prti != rti.
1581 * The parent's allMarkTypes field gets the OR of (1<<markType) across all
1582 * its children (this definition allows children to use different markTypes).
1583 *
1584 * The planner also adds resjunk output columns to the plan that carry
1585 * information sufficient to identify the locked or fetched rows. When
1586 * markType != ROW_MARK_COPY, these columns are named
1587 * tableoid%u OID of table
1588 * ctid%u TID of row
1589 * The tableoid column is only present for an inheritance hierarchy.
1590 * When markType == ROW_MARK_COPY, there is instead a single column named
1591 * wholerow%u whole-row value of relation
1592 * (An inheritance hierarchy could have all three resjunk output columns,
1593 * if some children use a different markType than others.)
1594 * In all three cases, %u represents the rowmark ID number (rowmarkId).
1595 * This number is unique within a plan tree, except that child relation
1596 * entries copy their parent's rowmarkId. (Assigning unique numbers
1597 * means we needn't renumber rowmarkIds when flattening subqueries, which
1598 * would require finding and renaming the resjunk columns as well.)
1599 * Note this means that all tables in an inheritance hierarchy share the
1600 * same resjunk column names.
1601 */
1602typedef struct PlanRowMark
1603{
1605
1606 NodeTag type;
1607 /* range table index of markable relation */
1608 Index rti;
1609 /* range table index of parent relation */
1610 Index prti;
1611 /* unique identifier for resjunk columns */
1612 Index rowmarkId;
1613 /* see enum above */
1614 RowMarkType markType;
1615 /* OR of (1<<markType) for all children */
1616 int allMarkTypes;
1617 /* LockingClause's strength, or LCS_NONE */
1618 LockClauseStrength strength;
1619 /* NOWAIT and SKIP LOCKED options */
1620 LockWaitPolicy waitPolicy;
1621 /* true if this is a "dummy" parent entry */
1622 bool isParent;
1623} PlanRowMark;
1624
1625
1626/*
1627 * Node types to represent partition pruning information.
1628 */
1629
1630/*
1631 * PartitionPruneInfo - Details required to allow the executor to prune
1632 * partitions.
1633 *
1634 * Here we store mapping details to allow translation of a partitioned table's
1635 * index as returned by the partition pruning code into subplan indexes for
1636 * plan types which support arbitrary numbers of subplans, such as Append.
1637 * We also store various details to tell the executor when it should be
1638 * performing partition pruning.
1639 *
1640 * Each PartitionedRelPruneInfo describes the partitioning rules for a single
1641 * partitioned table (a/k/a level of partitioning). Since a partitioning
1642 * hierarchy could contain multiple levels, we represent it by a List of
1643 * PartitionedRelPruneInfos, where the first entry represents the topmost
1644 * partitioned table and additional entries represent non-leaf child
1645 * partitions, ordered such that parents appear before their children.
1646 * Then, since an Append-type node could have multiple partitioning
1647 * hierarchies among its children, we have an unordered List of those Lists.
1648 *
1649 * relids RelOptInfo.relids of the parent plan node (e.g. Append
1650 * or MergeAppend) to which this PartitionPruneInfo node
1651 * belongs. The pruning logic ensures that this matches
1652 * the parent plan node's apprelids.
1653 * prune_infos List of Lists containing PartitionedRelPruneInfo nodes,
1654 * one sublist per run-time-prunable partition hierarchy
1655 * appearing in the parent plan node's subplans.
1656 * other_subplans Indexes of any subplans that are not accounted for
1657 * by any of the PartitionedRelPruneInfo nodes in
1658 * "prune_infos". These subplans must not be pruned.
1659 */
1660typedef struct PartitionPruneInfo
1661{
1663
1664 NodeTag type;
1665 Bitmapset *relids;
1666 List *prune_infos;
1667 Bitmapset *other_subplans;
1669
1670/*
1671 * PartitionedRelPruneInfo - Details required to allow the executor to prune
1672 * partitions for a single partitioned table.
1673 *
1674 * subplan_map[], subpart_map[], and leafpart_rti_map[] are indexed by partition
1675 * index of the partitioned table referenced by 'rtindex', the partition index
1676 * being the order that the partitions are defined in the table's
1677 * PartitionDesc. For a leaf partition p, subplan_map[p] contains the
1678 * zero-based index of the partition's subplan in the parent plan's subplan
1679 * list; it is -1 if the partition is non-leaf or has been pruned. For a
1680 * non-leaf partition p, subpart_map[p] contains the zero-based index of that
1681 * sub-partition's PartitionedRelPruneInfo in the hierarchy's
1682 * PartitionedRelPruneInfo list; it is -1 if the partition is a leaf or has
1683 * been pruned. leafpart_rti_map[p] contains the RT index of a leaf partition
1684 * if its subplan is in the parent plan' subplan list; it is 0 either if the
1685 * partition is non-leaf or it is leaf but has been pruned during planning.
1686 * Note that subplan indexes, as stored in 'subplan_map', are global across the
1687 * parent plan node, but partition indexes are valid only within a particular
1688 * hierarchy. relid_map[p] contains the partition's OID, or 0 if the partition
1689 * was pruned.
1690 */
1691typedef struct PartitionedRelPruneInfo
1692{
1694
1695 NodeTag type;
1696
1697 /* RT index of partition rel for this level */
1698 Index rtindex;
1699
1700 /* Indexes of all partitions which subplans or subparts are present for */
1701 Bitmapset *present_parts;
1702
1703 /* Length of the following arrays: */
1704 int nparts;
1705
1706 /* subplan index by partition index, or -1 */
1707 int *subplan_map pg_node_attr(array_size(nparts));
1708
1709 /* subpart index by partition index, or -1 */
1710 int *subpart_map pg_node_attr(array_size(nparts));
1711
1712 /* RT index by partition index, or 0 */
1713 int *leafpart_rti_map pg_node_attr(array_size(nparts));
1714
1715 /* relation OID by partition index, or 0 */
1717
1718 /*
1719 * initial_pruning_steps shows how to prune during executor startup (i.e.,
1720 * without use of any PARAM_EXEC Params); it is NIL if no startup pruning
1721 * is required. exec_pruning_steps shows how to prune with PARAM_EXEC
1722 * Params; it is NIL if no per-scan pruning is required.
1723 */
1724 /* List of PartitionPruneStep */
1725 List *initial_pruning_steps;
1726 /* List of PartitionPruneStep */
1727 List *exec_pruning_steps;
1728
1729 /* All PARAM_EXEC Param IDs in exec_pruning_steps */
1730 Bitmapset *execparamids;
1732
1733/*
1734 * Abstract Node type for partition pruning steps (there are no concrete
1735 * Nodes of this type).
1736 *
1737 * step_id is the global identifier of the step within its pruning context.
1738 */
1739typedef struct PartitionPruneStep
1740{
1742
1743 NodeTag type;
1744 int step_id;
1746
1747/*
1748 * PartitionPruneStepOp - Information to prune using a set of mutually ANDed
1749 * OpExpr clauses
1750 *
1751 * This contains information extracted from up to partnatts OpExpr clauses,
1752 * where partnatts is the number of partition key columns. 'opstrategy' is the
1753 * strategy of the operator in the clause matched to the last partition key.
1754 * 'exprs' contains expressions which comprise the lookup key to be passed to
1755 * the partition bound search function. 'cmpfns' contains the OIDs of
1756 * comparison functions used to compare aforementioned expressions with
1757 * partition bounds. Both 'exprs' and 'cmpfns' contain the same number of
1758 * items, up to partnatts items.
1759 *
1760 * Once we find the offset of a partition bound using the lookup key, we
1761 * determine which partitions to include in the result based on the value of
1762 * 'opstrategy'. For example, if it were equality, we'd return just the
1763 * partition that would contain that key or a set of partitions if the key
1764 * didn't consist of all partitioning columns. For non-equality strategies,
1765 * we'd need to include other partitions as appropriate.
1766 *
1767 * 'nullkeys' is the set containing the offset of the partition keys (0 to
1768 * partnatts - 1) that were matched to an IS NULL clause. This is only
1769 * considered for hash partitioning as we need to pass which keys are null
1770 * to the hash partition bound search function. It is never possible to
1771 * have an expression be present in 'exprs' for a given partition key and
1772 * the corresponding bit set in 'nullkeys'.
1773 */
1774typedef struct PartitionPruneStepOp
1775{
1776 PartitionPruneStep step;
1777
1778 StrategyNumber opstrategy;
1779 List *exprs;
1780 List *cmpfns;
1781 Bitmapset *nullkeys;
1783
1784/*
1785 * PartitionPruneStepCombine - Information to prune using a BoolExpr clause
1786 *
1787 * For BoolExpr clauses, we combine the set of partitions determined for each
1788 * of the argument clauses.
1789 */
1790typedef enum PartitionPruneCombineOp
1791{
1795
1796typedef struct PartitionPruneStepCombine
1797{
1798 PartitionPruneStep step;
1799
1800 PartitionPruneCombineOp combineOp;
1801 List *source_stepids;
1803
1804
1805/*
1806 * Plan invalidation info
1807 *
1808 * We track the objects on which a PlannedStmt depends in two ways:
1809 * relations are recorded as a simple list of OIDs, and everything else
1810 * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
1811 * to be used with the syscache invalidation mechanism, so it identifies a
1812 * system catalog entry by cache ID and hash value.
1813 */
1814typedef struct PlanInvalItem
1815{
1817
1818 NodeTag type;
1819 /* a syscache ID, see utils/syscache.h */
1820 int cacheId;
1821 /* hash value of object's cache lookup key */
1822 uint32 hashValue;
1824
1825/*
1826 * MonotonicFunction
1827 *
1828 * Allows the planner to track monotonic properties of functions. A function
1829 * is monotonically increasing if a subsequent call cannot yield a lower value
1830 * than the previous call. A monotonically decreasing function cannot yield a
1831 * higher value on subsequent calls, and a function which is both must return
1832 * the same value on each call.
1833 */
1834typedef enum MonotonicFunction
1835{
1837 MONOTONICFUNC_INCREASING = (1 << 0),
1838 MONOTONICFUNC_DECREASING = (1 << 1),
1841
1842/*
1843 * SubPlanRTInfo
1844 *
1845 * Information about which range table entries came from which subquery
1846 * planning cycles.
1847 */
1848typedef struct SubPlanRTInfo
1849{
1850 NodeTag type;
1851 char *plan_name;
1852 Index rtoffset;
1853 bool dummy;
1855
1856/*
1857 * ElidedNode
1858 *
1859 * Information about nodes elided from the final plan tree: trivial subquery
1860 * scans, and single-child Append and MergeAppend nodes.
1861 *
1862 * plan_node_id is that of the surviving plan node, the sole child of the
1863 * one which was elided.
1864 */
1865typedef struct ElidedNode
1866{
1867 NodeTag type;
1868 int plan_node_id;
1869 NodeTag elided_type;
1870 Bitmapset *relids;
1871} ElidedNode;
1872
1873#endif /* PLANNODES_H */
Datum sort(PG_FUNCTION_ARGS)
Definition _int_op.c:198
int16 AttrNumber
Definition attnum.h:21
uint64_t uint64
Definition c.h:547
uint32_t uint32
Definition c.h:546
unsigned int Index
Definition c.h:628
LockWaitPolicy
Definition lockoptions.h:38
LockClauseStrength
Definition lockoptions.h:22
SetOpCmd
Definition nodes.h:407
SetOpStrategy
Definition nodes.h:415
#define pg_node_attr(...)
Definition nodes.h:126
double Cost
Definition nodes.h:261
OnConflictAction
Definition nodes.h:427
double Cardinality
Definition nodes.h:262
CmdType
Definition nodes.h:273
AggStrategy
Definition nodes.h:363
NodeTag
Definition nodes.h:27
AggSplit
Definition nodes.h:385
LimitOption
Definition nodes.h:441
JoinType
Definition nodes.h:298
#define plan(x)
Definition pg_regress.c:161
SubqueryScanStatus
Definition plannodes.h:765
@ SUBQUERY_SCAN_NONTRIVIAL
Definition plannodes.h:768
@ SUBQUERY_SCAN_UNKNOWN
Definition plannodes.h:766
@ SUBQUERY_SCAN_TRIVIAL
Definition plannodes.h:767
PartitionPruneCombineOp
Definition plannodes.h:1792
@ PARTPRUNE_COMBINE_INTERSECT
Definition plannodes.h:1794
@ PARTPRUNE_COMBINE_UNION
Definition plannodes.h:1793
ResultType
Definition plannodes.h:276
@ RESULT_TYPE_UPPER
Definition plannodes.h:280
@ RESULT_TYPE_SCAN
Definition plannodes.h:278
@ RESULT_TYPE_GATING
Definition plannodes.h:277
@ RESULT_TYPE_MINMAX
Definition plannodes.h:281
@ RESULT_TYPE_JOIN
Definition plannodes.h:279
RowMarkType
Definition plannodes.h:1554
@ ROW_MARK_COPY
Definition plannodes.h:1560
@ ROW_MARK_REFERENCE
Definition plannodes.h:1559
@ ROW_MARK_SHARE
Definition plannodes.h:1557
@ ROW_MARK_EXCLUSIVE
Definition plannodes.h:1555
@ ROW_MARK_NOKEYEXCLUSIVE
Definition plannodes.h:1556
@ ROW_MARK_KEYSHARE
Definition plannodes.h:1558
MonotonicFunction
Definition plannodes.h:1836
@ MONOTONICFUNC_NONE
Definition plannodes.h:1837
@ MONOTONICFUNC_DECREASING
Definition plannodes.h:1839
@ MONOTONICFUNC_INCREASING
Definition plannodes.h:1838
@ MONOTONICFUNC_BOTH
Definition plannodes.h:1840
unsigned int Oid
static int fb(int x)
static const struct fns functions
Definition regcomp.c:358
ScanDirection
Definition sdir.h:25
uint16 StrategyNumber
Definition stratnum.h:22
int first_partial_plan
Definition plannodes.h:416
int part_prune_index
Definition plannodes.h:423
int nasyncplans
Definition plannodes.h:410
List * child_append_relid_sets
Definition plannodes.h:404
Bitmapset * apprelids
Definition plannodes.h:401
Plan plan
Definition plannodes.h:398
List * appendplans
Definition plannodes.h:407
Plan plan
Definition plannodes.h:510
List * bitmapplans
Definition plannodes.h:511
List * bitmapplans
Definition plannodes.h:526
bool isshared
Definition plannodes.h:525
Plan plan
Definition plannodes.h:524
Definition pg_list.h:54
int part_prune_index
Definition plannodes.h:466
Bitmapset * apprelids
Definition plannodes.h:436
List * mergeplans
Definition plannodes.h:442
List * child_append_relid_sets
Definition plannodes.h:439
List * updateColnosLists
Definition plannodes.h:350
Index nominalRelation
Definition plannodes.h:344
List * arbiterIndexes
Definition plannodes.h:370
List * onConflictCols
Definition plannodes.h:376
List * mergeJoinConditions
Definition plannodes.h:386
char * returningOldAlias
Definition plannodes.h:354
char * returningNewAlias
Definition plannodes.h:356
CmdType operation
Definition plannodes.h:340
List * resultRelations
Definition plannodes.h:348
Bitmapset * fdwDirectModifyPlans
Definition plannodes.h:362
List * onConflictSet
Definition plannodes.h:374
List * exclRelTlist
Definition plannodes.h:382
List * mergeActionLists
Definition plannodes.h:384
bool canSetTag
Definition plannodes.h:342
List * fdwPrivLists
Definition plannodes.h:360
List * returningLists
Definition plannodes.h:358
List * withCheckOptionLists
Definition plannodes.h:352
LockClauseStrength onConflictLockStrength
Definition plannodes.h:372
Index rootRelation
Definition plannodes.h:346
Node * onConflictWhere
Definition plannodes.h:378
List * rowMarks
Definition plannodes.h:364
OnConflictAction onConflictAction
Definition plannodes.h:368
Index exclRelRTI
Definition plannodes.h:380
Definition nodes.h:135
Bitmapset * extParam
Definition plannodes.h:255
struct Plan * lefttree
Definition plannodes.h:239
struct Plan * righttree
Definition plannodes.h:240
Bitmapset * allParam
Definition plannodes.h:256
List * initPlan
Definition plannodes.h:242
Cardinality numGroups
Definition plannodes.h:497
Node * resconstantqual
Definition plannodes.h:305
ResultType result_type
Definition plannodes.h:304
Bitmapset * relids
Definition plannodes.h:306
Plan plan
Definition plannodes.h:303
Index scanrelid
Definition plannodes.h:542
const char * type

◆ innerPlan

#define innerPlan (   node)    (((Plan *)(node))->righttree)

Definition at line 266 of file plannodes.h.

◆ outerPlan

#define outerPlan (   node)    (((Plan *)(node))->lefttree)

Definition at line 267 of file plannodes.h.

◆ RowMarkRequiresRowShareLock

#define RowMarkRequiresRowShareLock (   marktype)    ((marktype) <= ROW_MARK_KEYSHARE)

Definition at line 1563 of file plannodes.h.

Typedef Documentation

◆ Agg

typedef struct Agg Agg

◆ Append

◆ BitmapAnd

◆ BitmapHeapScan

◆ BitmapIndexScan

◆ BitmapOr

◆ CteScan

◆ CustomScan

◆ ElidedNode

◆ ForeignScan

◆ FunctionScan

◆ Gather

◆ GatherMerge

◆ Group

◆ Hash

typedef struct Hash Hash

◆ HashJoin

◆ IncrementalSort

◆ IndexOnlyScan

◆ IndexScan

◆ Join

typedef struct Join Join

◆ Limit

◆ LockRows

◆ Material

◆ Memoize

◆ MergeAppend

◆ MergeJoin

◆ ModifyTable

◆ MonotonicFunction

◆ NamedTuplestoreScan

◆ NestLoop

◆ NestLoopParam

◆ PartitionedRelPruneInfo

◆ PartitionPruneCombineOp

◆ PartitionPruneInfo

◆ PartitionPruneStep

◆ PartitionPruneStepCombine

◆ PartitionPruneStepOp

◆ Plan

typedef struct Plan Plan

◆ PlanInvalItem

◆ PlannedStmt

◆ PlannedStmtOrigin

◆ PlanRowMark

◆ ProjectSet

◆ RecursiveUnion

◆ Result

◆ ResultType

◆ RowMarkType

◆ SampleScan

◆ Scan

typedef struct Scan Scan

◆ SeqScan

◆ SetOp

◆ Sort

typedef struct Sort Sort

◆ SubPlanRTInfo

◆ SubqueryScan

◆ SubqueryScanStatus

◆ TableFuncScan

◆ TidRangeScan

◆ TidScan

◆ Unique

◆ ValuesScan

◆ WindowAgg

◆ WorkTableScan

Enumeration Type Documentation

◆ MonotonicFunction

Enumerator
MONOTONICFUNC_NONE 
MONOTONICFUNC_INCREASING 
MONOTONICFUNC_DECREASING 
MONOTONICFUNC_BOTH 

Definition at line 1835 of file plannodes.h.

◆ PartitionPruneCombineOp

Enumerator
PARTPRUNE_COMBINE_UNION 
PARTPRUNE_COMBINE_INTERSECT 

Definition at line 1791 of file plannodes.h.

◆ PlannedStmtOrigin

Enumerator
PLAN_STMT_UNKNOWN 
PLAN_STMT_INTERNAL 
PLAN_STMT_STANDARD 
PLAN_STMT_CACHE_GENERIC 
PLAN_STMT_CACHE_CUSTOM 

Definition at line 37 of file plannodes.h.

38{
39 PLAN_STMT_UNKNOWN = 0, /* plan origin is not yet known */
40 PLAN_STMT_INTERNAL, /* generated internally by a query */
41 PLAN_STMT_STANDARD, /* standard planned statement */
42 PLAN_STMT_CACHE_GENERIC, /* Generic cached plan */
43 PLAN_STMT_CACHE_CUSTOM, /* Custom cached plan */
PlannedStmtOrigin
Definition plannodes.h:38
@ PLAN_STMT_STANDARD
Definition plannodes.h:41
@ PLAN_STMT_UNKNOWN
Definition plannodes.h:39
@ PLAN_STMT_CACHE_CUSTOM
Definition plannodes.h:43
@ PLAN_STMT_CACHE_GENERIC
Definition plannodes.h:42
@ PLAN_STMT_INTERNAL
Definition plannodes.h:40

◆ ResultType

Enumerator
RESULT_TYPE_GATING 
RESULT_TYPE_SCAN 
RESULT_TYPE_JOIN 
RESULT_TYPE_UPPER 
RESULT_TYPE_MINMAX 

Definition at line 275 of file plannodes.h.

276{
277 RESULT_TYPE_GATING, /* project or one-time-filter outer plan */
278 RESULT_TYPE_SCAN, /* replace empty scan */
279 RESULT_TYPE_JOIN, /* replace empty join */
280 RESULT_TYPE_UPPER, /* replace degenerate upper rel */
281 RESULT_TYPE_MINMAX /* implement minmax aggregate */
282} ResultType;

◆ RowMarkType

Enumerator
ROW_MARK_EXCLUSIVE 
ROW_MARK_NOKEYEXCLUSIVE 
ROW_MARK_SHARE 
ROW_MARK_KEYSHARE 
ROW_MARK_REFERENCE 
ROW_MARK_COPY 

Definition at line 1553 of file plannodes.h.

1554{
1555 ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
1556 ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
1557 ROW_MARK_SHARE, /* obtain shared tuple lock */
1558 ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
1559 ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
1560 ROW_MARK_COPY, /* physically copy the row value */
1561} RowMarkType;

◆ SubqueryScanStatus

Enumerator
SUBQUERY_SCAN_UNKNOWN 
SUBQUERY_SCAN_TRIVIAL 
SUBQUERY_SCAN_NONTRIVIAL 

Definition at line 764 of file plannodes.h.