PostgreSQL Source Code git master
Loading...
Searching...
No Matches
plannodes.h File Reference
#include "access/sdir.h"
#include "access/stratnum.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 173 of file plannodes.h.

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

◆ innerPlan

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

Definition at line 264 of file plannodes.h.

◆ outerPlan

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

Definition at line 265 of file plannodes.h.

◆ RowMarkRequiresRowShareLock

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

Definition at line 1561 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 1833 of file plannodes.h.

◆ PartitionPruneCombineOp

Enumerator
PARTPRUNE_COMBINE_UNION 
PARTPRUNE_COMBINE_INTERSECT 

Definition at line 1789 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 35 of file plannodes.h.

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

◆ ResultType

Enumerator
RESULT_TYPE_GATING 
RESULT_TYPE_SCAN 
RESULT_TYPE_JOIN 
RESULT_TYPE_UPPER 
RESULT_TYPE_MINMAX 

Definition at line 273 of file plannodes.h.

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

◆ RowMarkType

Enumerator
ROW_MARK_EXCLUSIVE 
ROW_MARK_NOKEYEXCLUSIVE 
ROW_MARK_SHARE 
ROW_MARK_KEYSHARE 
ROW_MARK_REFERENCE 
ROW_MARK_COPY 

Definition at line 1551 of file plannodes.h.

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

◆ SubqueryScanStatus

Enumerator
SUBQUERY_SCAN_UNKNOWN 
SUBQUERY_SCAN_TRIVIAL 
SUBQUERY_SCAN_NONTRIVIAL 

Definition at line 762 of file plannodes.h.