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

◆ PartitionPruneCombineOp

Enumerator
PARTPRUNE_COMBINE_UNION 
PARTPRUNE_COMBINE_INTERSECT 

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

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

◆ SubqueryScanStatus

Enumerator
SUBQUERY_SCAN_UNKNOWN 
SUBQUERY_SCAN_TRIVIAL 
SUBQUERY_SCAN_NONTRIVIAL 

Definition at line 766 of file plannodes.h.