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 *
969 * When jointype is INNER, joinqual and plan.qual are semantically
970 * interchangeable. For OUTER jointypes, the two are *not* interchangeable;
971 * only joinqual is used to determine whether a match has been found for
972 * the purpose of deciding whether to generate null-extended tuples.
973 * (But plan.qual is still applied before actually returning a tuple.)
974 * For an outer join, only joinquals are allowed to be used as the merge
975 * or hash condition of a merge or hash join.
976 *
977 * inner_unique is set if the joinquals are such that no more than one inner
978 * tuple could match any given outer tuple. This allows the executor to
979 * skip searching for additional matches. (This must be provable from just
980 * the joinquals, ignoring plan.qual, due to where the executor tests it.)
981 * ----------------
982 */
983typedef struct Join
984{
985 pg_node_attr(abstract)
986
987 Plan plan;
988 JoinType jointype;
989 bool inner_unique;
990 /* JOIN quals (in addition to plan.qual) */
991 List *joinqual;
992} Join;
993
994/* ----------------
995 * nest loop join node
996 *
997 * The nestParams list identifies any executor Params that must be passed
998 * into execution of the inner subplan carrying values from the current row
999 * of the outer subplan. Currently we restrict these values to be simple
1000 * Vars, but perhaps someday that'd be worth relaxing. (Note: during plan
1001 * creation, the paramval can actually be a PlaceHolderVar expression; but it
1002 * must be a Var with varno OUTER_VAR by the time it gets to the executor.)
1003 * ----------------
1004 */
1005typedef struct NestLoop
1006{
1007 Join join;
1008 /* list of NestLoopParam nodes */
1009 List *nestParams;
1010} NestLoop;
1011
1012typedef struct NestLoopParam
1013{
1015
1016 NodeTag type;
1017 /* number of the PARAM_EXEC Param to set */
1018 int paramno;
1019 /* outer-relation Var to assign to Param */
1020 Var *paramval;
1022
1023/* ----------------
1024 * merge join node
1025 *
1026 * The expected ordering of each mergeable column is described by a btree
1027 * opfamily OID, a collation OID, a direction (BTLessStrategyNumber or
1028 * BTGreaterStrategyNumber) and a nulls-first flag. Note that the two sides
1029 * of each mergeclause may be of different datatypes, but they are ordered the
1030 * same way according to the common opfamily and collation. The operator in
1031 * each mergeclause must be an equality operator of the indicated opfamily.
1032 * ----------------
1033 */
1034typedef struct MergeJoin
1035{
1036 Join join;
1037
1038 /* Can we skip mark/restore calls? */
1039 bool skip_mark_restore;
1040
1041 /* mergeclauses as expression trees */
1042 List *mergeclauses;
1043
1044 /* these are arrays, but have the same length as the mergeclauses list: */
1045
1046 /* per-clause OIDs of btree opfamilies */
1047 Oid *mergeFamilies pg_node_attr(array_size(mergeclauses));
1048
1049 /* per-clause OIDs of collations */
1051
1052 /* per-clause ordering (ASC or DESC) */
1053 bool *mergeReversals pg_node_attr(array_size(mergeclauses));
1054
1055 /* per-clause nulls ordering */
1056 bool *mergeNullsFirst pg_node_attr(array_size(mergeclauses));
1057} MergeJoin;
1058
1059/* ----------------
1060 * hash join node
1061 * ----------------
1062 */
1063typedef struct HashJoin
1064{
1065 Join join;
1066 List *hashclauses;
1067 List *hashoperators;
1068 List *hashcollations;
1069
1070 /*
1071 * List of expressions to be hashed for tuples from the outer plan, to
1072 * perform lookups in the hashtable over the inner plan.
1073 */
1074 List *hashkeys;
1075} HashJoin;
1076
1077/* ----------------
1078 * materialization node
1079 * ----------------
1080 */
1081typedef struct Material
1082{
1083 Plan plan;
1084} Material;
1085
1086/* ----------------
1087 * memoize node
1088 * ----------------
1089 */
1090typedef struct Memoize
1091{
1092 Plan plan;
1093
1094 /* size of the two arrays below */
1095 int numKeys;
1096
1097 /* hash operators for each key */
1099
1100 /* collations for each key */
1101 Oid *collations pg_node_attr(array_size(numKeys));
1102
1103 /* cache keys in the form of exprs containing parameters */
1104 List *param_exprs;
1105
1106 /*
1107 * true if the cache entry should be marked as complete after we store the
1108 * first tuple in it.
1109 */
1110 bool singlerow;
1111
1112 /*
1113 * true when cache key should be compared bit by bit, false when using
1114 * hash equality ops
1115 */
1116 bool binary_mode;
1117
1118 /*
1119 * The maximum number of entries that the planner expects will fit in the
1120 * cache, or 0 if unknown
1121 */
1122 uint32 est_entries;
1123
1124 /* paramids from param_exprs */
1125 Bitmapset *keyparamids;
1126
1127 /* Estimated number of rescans, for EXPLAIN */
1128 Cardinality est_calls;
1129
1130 /* Estimated number of distinct lookup keys, for EXPLAIN */
1131 Cardinality est_unique_keys;
1132
1133 /* Estimated cache hit ratio, for EXPLAIN */
1134 double est_hit_ratio;
1135
1136} Memoize;
1137
1138/* ----------------
1139 * sort node
1140 * ----------------
1141 */
1142typedef struct Sort
1143{
1144 Plan plan;
1145
1146 /* number of sort-key columns */
1147 int numCols;
1148
1149 /* their indexes in the target list */
1150 AttrNumber *sortColIdx pg_node_attr(array_size(numCols));
1151
1152 /* OIDs of operators to sort them by */
1153 Oid *sortOperators pg_node_attr(array_size(numCols));
1154
1155 /* OIDs of collations */
1156 Oid *collations pg_node_attr(array_size(numCols));
1157
1158 /* NULLS FIRST/LAST directions */
1159 bool *nullsFirst pg_node_attr(array_size(numCols));
1160} Sort;
1161
1162/* ----------------
1163 * incremental sort node
1164 * ----------------
1165 */
1166typedef struct IncrementalSort
1167{
1168 Sort sort;
1169 /* number of presorted columns */
1170 int nPresortedCols;
1172
1173/* ---------------
1174 * group node -
1175 * Used for queries with GROUP BY (but no aggregates) specified.
1176 * The input must be presorted according to the grouping columns.
1177 * ---------------
1178 */
1179typedef struct Group
1180{
1181 Plan plan;
1182
1183 /* number of grouping columns */
1184 int numCols;
1185
1186 /* their indexes in the target list */
1188
1189 /* equality operators to compare with */
1192} Group;
1193
1194/* ---------------
1195 * aggregate node
1196 *
1197 * An Agg node implements plain or grouped aggregation. For grouped
1198 * aggregation, we can work with presorted input or unsorted input;
1199 * the latter strategy uses an internal hashtable.
1200 *
1201 * Notice the lack of any direct info about the aggregate functions to be
1202 * computed. They are found by scanning the node's tlist and quals during
1203 * executor startup. (It is possible that there are no aggregate functions;
1204 * this could happen if they get optimized away by constant-folding, or if
1205 * we are using the Agg node to implement hash-based grouping.)
1206 * ---------------
1207 */
1208typedef struct Agg
1209{
1210 Plan plan;
1211
1212 /* basic strategy, see nodes.h */
1213 AggStrategy aggstrategy;
1214
1215 /* agg-splitting mode, see nodes.h */
1216 AggSplit aggsplit;
1217
1218 /* number of grouping columns */
1219 int numCols;
1220
1221 /* their indexes in the target list */
1223
1224 /* equality operators to compare with */
1227
1228 /* estimated number of groups in input */
1229 Cardinality numGroups;
1230
1231 /* for pass-by-ref transition data */
1232 uint64 transitionSpace;
1233
1234 /* IDs of Params used in Aggref inputs */
1235 Bitmapset *aggParams;
1236
1237 /* Note: planner provides numGroups & aggParams only in HASHED/MIXED case */
1238
1239 /* grouping sets to use */
1240 List *groupingSets;
1241
1242 /* chained Agg/Sort nodes */
1243 List *chain;
1244} Agg;
1245
1246/* ----------------
1247 * window aggregate node
1248 * ----------------
1249 */
1250typedef struct WindowAgg
1251{
1252 Plan plan;
1253
1254 /* name of WindowClause implemented by this node */
1255 char *winname;
1256
1257 /* ID referenced by window functions */
1258 Index winref;
1259
1260 /* number of columns in partition clause */
1261 int partNumCols;
1262
1263 /* their indexes in the target list */
1265
1266 /* equality operators for partition columns */
1268
1269 /* collations for partition columns */
1271
1272 /* number of columns in ordering clause */
1273 int ordNumCols;
1274
1275 /* their indexes in the target list */
1277
1278 /* equality operators for ordering columns */
1280
1281 /* collations for ordering columns */
1283
1284 /* frame_clause options, see WindowDef */
1285 int frameOptions;
1286
1287 /* expression for starting bound, if any */
1288 Node *startOffset;
1289
1290 /* expression for ending bound, if any */
1291 Node *endOffset;
1292
1293 /* qual to help short-circuit execution */
1294 List *runCondition;
1295
1296 /* runCondition for display in EXPLAIN */
1297 List *runConditionOrig;
1298
1299 /* these fields are used with RANGE offset PRECEDING/FOLLOWING: */
1300
1301 /* in_range function for startOffset */
1302 Oid startInRangeFunc;
1303
1304 /* in_range function for endOffset */
1305 Oid endInRangeFunc;
1306
1307 /* collation for in_range tests */
1308 Oid inRangeColl;
1309
1310 /* use ASC sort order for in_range tests? */
1311 bool inRangeAsc;
1312
1313 /* nulls sort first for in_range tests? */
1314 bool inRangeNullsFirst;
1315
1316 /*
1317 * false for all apart from the WindowAgg that's closest to the root of
1318 * the plan
1319 */
1320 bool topWindow;
1321} WindowAgg;
1322
1323/* ----------------
1324 * unique node
1325 * ----------------
1326 */
1327typedef struct Unique
1328{
1329 Plan plan;
1330
1331 /* number of columns to check for uniqueness */
1332 int numCols;
1333
1334 /* their indexes in the target list */
1336
1337 /* equality operators to compare with */
1339
1340 /* collations for equality comparisons */
1342} Unique;
1343
1344/* ------------
1345 * gather node
1346 *
1347 * Note: rescan_param is the ID of a PARAM_EXEC parameter slot. That slot
1348 * will never actually contain a value, but the Gather node must flag it as
1349 * having changed whenever it is rescanned. The child parallel-aware scan
1350 * nodes are marked as depending on that parameter, so that the rescan
1351 * machinery is aware that their output is likely to change across rescans.
1352 * In some cases we don't need a rescan Param, so rescan_param is set to -1.
1353 * ------------
1354 */
1355typedef struct Gather
1356{
1357 Plan plan;
1358 /* planned number of worker processes */
1359 int num_workers;
1360 /* ID of Param that signals a rescan, or -1 */
1361 int rescan_param;
1362 /* don't execute plan more than once */
1363 bool single_copy;
1364 /* suppress EXPLAIN display (for testing)? */
1365 bool invisible;
1366
1367 /*
1368 * param id's of initplans which are referred at gather or one of its
1369 * child nodes
1370 */
1371 Bitmapset *initParam;
1372} Gather;
1373
1374/* ------------
1375 * gather merge node
1376 * ------------
1377 */
1378typedef struct GatherMerge
1379{
1380 Plan plan;
1381
1382 /* planned number of worker processes */
1383 int num_workers;
1384
1385 /* ID of Param that signals a rescan, or -1 */
1386 int rescan_param;
1387
1388 /* remaining fields are just like the sort-key info in struct Sort */
1389
1390 /* number of sort-key columns */
1391 int numCols;
1392
1393 /* their indexes in the target list */
1394 AttrNumber *sortColIdx pg_node_attr(array_size(numCols));
1395
1396 /* OIDs of operators to sort them by */
1397 Oid *sortOperators pg_node_attr(array_size(numCols));
1398
1399 /* OIDs of collations */
1400 Oid *collations pg_node_attr(array_size(numCols));
1401
1402 /* NULLS FIRST/LAST directions */
1403 bool *nullsFirst pg_node_attr(array_size(numCols));
1404
1405 /*
1406 * param id's of initplans which are referred at gather merge or one of
1407 * its child nodes
1408 */
1409 Bitmapset *initParam;
1410} GatherMerge;
1411
1412/* ----------------
1413 * hash build node
1414 *
1415 * If the executor is supposed to try to apply skew join optimization, then
1416 * skewTable/skewColumn/skewInherit identify the outer relation's join key
1417 * column, from which the relevant MCV statistics can be fetched.
1418 * ----------------
1419 */
1420typedef struct Hash
1421{
1422 Plan plan;
1423
1424 /*
1425 * List of expressions to be hashed for tuples from Hash's outer plan,
1426 * needed to put them into the hashtable.
1427 */
1428 /* hash keys for the hashjoin condition */
1429 List *hashkeys;
1430 /* outer join key's table OID, or InvalidOid */
1431 Oid skewTable;
1432 /* outer join key's column #, or zero */
1433 AttrNumber skewColumn;
1434 /* is outer join rel an inheritance tree? */
1435 bool skewInherit;
1436 /* all other info is in the parent HashJoin node */
1437 /* estimate total rows if parallel_aware */
1438 Cardinality rows_total;
1439} Hash;
1440
1441/* ----------------
1442 * setop node
1443 * ----------------
1444 */
1445typedef struct SetOp
1446{
1447 Plan plan;
1448
1449 /* what to do, see nodes.h */
1450 SetOpCmd cmd;
1451
1452 /* how to do it, see nodes.h */
1453 SetOpStrategy strategy;
1454
1455 /* number of columns to compare */
1456 int numCols;
1457
1458 /* their indexes in the target list */
1460
1461 /* comparison operators (either equality operators or sort operators) */
1464
1465 /* nulls-first flags if sorting, otherwise not interesting */
1466 bool *cmpNullsFirst pg_node_attr(array_size(numCols));
1467
1468 /* estimated number of groups in left input */
1469 Cardinality numGroups;
1470} SetOp;
1471
1472/* ----------------
1473 * lock-rows node
1474 *
1475 * rowMarks identifies the rels to be locked by this node; it should be
1476 * a subset of the rowMarks listed in the top-level PlannedStmt.
1477 * epqParam is a Param that all scan nodes below this one must depend on.
1478 * It is used to force re-evaluation of the plan during EvalPlanQual.
1479 * ----------------
1480 */
1481typedef struct LockRows
1482{
1483 Plan plan;
1484 /* a list of PlanRowMark's */
1485 List *rowMarks;
1486 /* ID of Param for EvalPlanQual re-eval */
1487 int epqParam;
1488} LockRows;
1489
1490/* ----------------
1491 * limit node
1492 *
1493 * Note: as of Postgres 8.2, the offset and count expressions are expected
1494 * to yield int8, rather than int4 as before.
1495 * ----------------
1496 */
1497typedef struct Limit
1498{
1499 Plan plan;
1500
1501 /* OFFSET parameter, or NULL if none */
1502 Node *limitOffset;
1503
1504 /* COUNT parameter, or NULL if none */
1505 Node *limitCount;
1506
1507 /* limit type */
1508 LimitOption limitOption;
1509
1510 /* number of columns to check for similarity */
1511 int uniqNumCols;
1512
1513 /* their indexes in the target list */
1515
1516 /* equality operators to compare with */
1518
1519 /* collations for equality comparisons */
1521} Limit;
1522
1523
1524/*
1525 * RowMarkType -
1526 * enums for types of row-marking operations
1527 *
1528 * The first four of these values represent different lock strengths that
1529 * we can take on tuples according to SELECT FOR [KEY] UPDATE/SHARE requests.
1530 * We support these on regular tables, as well as on foreign tables whose FDWs
1531 * report support for late locking. For other foreign tables, any locking
1532 * that might be done for such requests must happen during the initial row
1533 * fetch; their FDWs provide no mechanism for going back to lock a row later.
1534 * This means that the semantics will be a bit different than for a local
1535 * table; in particular we are likely to lock more rows than would be locked
1536 * locally, since remote rows will be locked even if they then fail
1537 * locally-checked restriction or join quals. However, the prospect of
1538 * doing a separate remote query to lock each selected row is usually pretty
1539 * unappealing, so early locking remains a credible design choice for FDWs.
1540 *
1541 * When doing UPDATE/DELETE/MERGE/SELECT FOR UPDATE/SHARE, we have to uniquely
1542 * identify all the source rows, not only those from the target relations, so
1543 * that we can perform EvalPlanQual rechecking at need. For plain tables we
1544 * can just fetch the TID, much as for a target relation; this case is
1545 * represented by ROW_MARK_REFERENCE. Otherwise (for example for VALUES or
1546 * FUNCTION scans) we have to copy the whole row value. ROW_MARK_COPY is
1547 * pretty inefficient, since most of the time we'll never need the data; but
1548 * fortunately the overhead is usually not performance-critical in practice.
1549 * By default we use ROW_MARK_COPY for foreign tables, but if the FDW has
1550 * a concept of rowid it can request to use ROW_MARK_REFERENCE instead.
1551 * (Again, this probably doesn't make sense if a physical remote fetch is
1552 * needed, but for FDWs that map to local storage it might be credible.)
1553 */
1554typedef enum RowMarkType
1555{
1556 ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
1557 ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
1558 ROW_MARK_SHARE, /* obtain shared tuple lock */
1559 ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
1560 ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
1561 ROW_MARK_COPY, /* physically copy the row value */
1562} RowMarkType;
1563
1564#define RowMarkRequiresRowShareLock(marktype) ((marktype) <= ROW_MARK_KEYSHARE)
1565
1566/*
1567 * PlanRowMark -
1568 * plan-time representation of FOR [KEY] UPDATE/SHARE clauses
1569 *
1570 * When doing UPDATE/DELETE/MERGE/SELECT FOR UPDATE/SHARE, we create a separate
1571 * PlanRowMark node for each non-target relation in the query. Relations that
1572 * are not specified as FOR UPDATE/SHARE are marked ROW_MARK_REFERENCE (if
1573 * regular tables or supported foreign tables) or ROW_MARK_COPY (if not).
1574 *
1575 * Initially all PlanRowMarks have rti == prti and isParent == false.
1576 * When the planner discovers that a relation is the root of an inheritance
1577 * tree, it sets isParent true, and adds an additional PlanRowMark to the
1578 * list for each child relation (including the target rel itself in its role
1579 * as a child, if it is not a partitioned table). Any non-leaf partitioned
1580 * child relations will also have entries with isParent = true. The child
1581 * entries have rti == child rel's RT index and prti == top parent's RT index,
1582 * and can therefore be recognized as children by the fact that prti != rti.
1583 * The parent's allMarkTypes field gets the OR of (1<<markType) across all
1584 * its children (this definition allows children to use different markTypes).
1585 *
1586 * The planner also adds resjunk output columns to the plan that carry
1587 * information sufficient to identify the locked or fetched rows. When
1588 * markType != ROW_MARK_COPY, these columns are named
1589 * tableoid%u OID of table
1590 * ctid%u TID of row
1591 * The tableoid column is only present for an inheritance hierarchy.
1592 * When markType == ROW_MARK_COPY, there is instead a single column named
1593 * wholerow%u whole-row value of relation
1594 * (An inheritance hierarchy could have all three resjunk output columns,
1595 * if some children use a different markType than others.)
1596 * In all three cases, %u represents the rowmark ID number (rowmarkId).
1597 * This number is unique within a plan tree, except that child relation
1598 * entries copy their parent's rowmarkId. (Assigning unique numbers
1599 * means we needn't renumber rowmarkIds when flattening subqueries, which
1600 * would require finding and renaming the resjunk columns as well.)
1601 * Note this means that all tables in an inheritance hierarchy share the
1602 * same resjunk column names.
1603 */
1604typedef struct PlanRowMark
1605{
1607
1608 NodeTag type;
1609 /* range table index of markable relation */
1610 Index rti;
1611 /* range table index of parent relation */
1612 Index prti;
1613 /* unique identifier for resjunk columns */
1614 Index rowmarkId;
1615 /* see enum above */
1616 RowMarkType markType;
1617 /* OR of (1<<markType) for all children */
1618 int allMarkTypes;
1619 /* LockingClause's strength, or LCS_NONE */
1620 LockClauseStrength strength;
1621 /* NOWAIT and SKIP LOCKED options */
1622 LockWaitPolicy waitPolicy;
1623 /* true if this is a "dummy" parent entry */
1624 bool isParent;
1625} PlanRowMark;
1626
1627
1628/*
1629 * Node types to represent partition pruning information.
1630 */
1631
1632/*
1633 * PartitionPruneInfo - Details required to allow the executor to prune
1634 * partitions.
1635 *
1636 * Here we store mapping details to allow translation of a partitioned table's
1637 * index as returned by the partition pruning code into subplan indexes for
1638 * plan types which support arbitrary numbers of subplans, such as Append.
1639 * We also store various details to tell the executor when it should be
1640 * performing partition pruning.
1641 *
1642 * Each PartitionedRelPruneInfo describes the partitioning rules for a single
1643 * partitioned table (a/k/a level of partitioning). Since a partitioning
1644 * hierarchy could contain multiple levels, we represent it by a List of
1645 * PartitionedRelPruneInfos, where the first entry represents the topmost
1646 * partitioned table and additional entries represent non-leaf child
1647 * partitions, ordered such that parents appear before their children.
1648 * Then, since an Append-type node could have multiple partitioning
1649 * hierarchies among its children, we have an unordered List of those Lists.
1650 *
1651 * relids RelOptInfo.relids of the parent plan node (e.g. Append
1652 * or MergeAppend) to which this PartitionPruneInfo node
1653 * belongs. The pruning logic ensures that this matches
1654 * the parent plan node's apprelids.
1655 * prune_infos List of Lists containing PartitionedRelPruneInfo nodes,
1656 * one sublist per run-time-prunable partition hierarchy
1657 * appearing in the parent plan node's subplans.
1658 * other_subplans Indexes of any subplans that are not accounted for
1659 * by any of the PartitionedRelPruneInfo nodes in
1660 * "prune_infos". These subplans must not be pruned.
1661 */
1662typedef struct PartitionPruneInfo
1663{
1665
1666 NodeTag type;
1667 Bitmapset *relids;
1668 List *prune_infos;
1669 Bitmapset *other_subplans;
1671
1672/*
1673 * PartitionedRelPruneInfo - Details required to allow the executor to prune
1674 * partitions for a single partitioned table.
1675 *
1676 * subplan_map[], subpart_map[], and leafpart_rti_map[] are indexed by partition
1677 * index of the partitioned table referenced by 'rtindex', the partition index
1678 * being the order that the partitions are defined in the table's
1679 * PartitionDesc. For a leaf partition p, subplan_map[p] contains the
1680 * zero-based index of the partition's subplan in the parent plan's subplan
1681 * list; it is -1 if the partition is non-leaf or has been pruned. For a
1682 * non-leaf partition p, subpart_map[p] contains the zero-based index of that
1683 * sub-partition's PartitionedRelPruneInfo in the hierarchy's
1684 * PartitionedRelPruneInfo list; it is -1 if the partition is a leaf or has
1685 * been pruned. leafpart_rti_map[p] contains the RT index of a leaf partition
1686 * if its subplan is in the parent plan' subplan list; it is 0 either if the
1687 * partition is non-leaf or it is leaf but has been pruned during planning.
1688 * Note that subplan indexes, as stored in 'subplan_map', are global across the
1689 * parent plan node, but partition indexes are valid only within a particular
1690 * hierarchy. relid_map[p] contains the partition's OID, or 0 if the partition
1691 * was pruned.
1692 */
1693typedef struct PartitionedRelPruneInfo
1694{
1696
1697 NodeTag type;
1698
1699 /* RT index of partition rel for this level */
1700 Index rtindex;
1701
1702 /* Indexes of all partitions which subplans or subparts are present for */
1703 Bitmapset *present_parts;
1704
1705 /* Length of the following arrays: */
1706 int nparts;
1707
1708 /* subplan index by partition index, or -1 */
1709 int *subplan_map pg_node_attr(array_size(nparts));
1710
1711 /* subpart index by partition index, or -1 */
1712 int *subpart_map pg_node_attr(array_size(nparts));
1713
1714 /* RT index by partition index, or 0 */
1715 int *leafpart_rti_map pg_node_attr(array_size(nparts));
1716
1717 /* relation OID by partition index, or 0 */
1719
1720 /*
1721 * initial_pruning_steps shows how to prune during executor startup (i.e.,
1722 * without use of any PARAM_EXEC Params); it is NIL if no startup pruning
1723 * is required. exec_pruning_steps shows how to prune with PARAM_EXEC
1724 * Params; it is NIL if no per-scan pruning is required.
1725 */
1726 /* List of PartitionPruneStep */
1727 List *initial_pruning_steps;
1728 /* List of PartitionPruneStep */
1729 List *exec_pruning_steps;
1730
1731 /* All PARAM_EXEC Param IDs in exec_pruning_steps */
1732 Bitmapset *execparamids;
1734
1735/*
1736 * Abstract Node type for partition pruning steps (there are no concrete
1737 * Nodes of this type).
1738 *
1739 * step_id is the global identifier of the step within its pruning context.
1740 */
1741typedef struct PartitionPruneStep
1742{
1744
1745 NodeTag type;
1746 int step_id;
1748
1749/*
1750 * PartitionPruneStepOp - Information to prune using a set of mutually ANDed
1751 * OpExpr clauses
1752 *
1753 * This contains information extracted from up to partnatts OpExpr clauses,
1754 * where partnatts is the number of partition key columns. 'opstrategy' is the
1755 * strategy of the operator in the clause matched to the last partition key.
1756 * 'exprs' contains expressions which comprise the lookup key to be passed to
1757 * the partition bound search function. 'cmpfns' contains the OIDs of
1758 * comparison functions used to compare aforementioned expressions with
1759 * partition bounds. Both 'exprs' and 'cmpfns' contain the same number of
1760 * items, up to partnatts items.
1761 *
1762 * Once we find the offset of a partition bound using the lookup key, we
1763 * determine which partitions to include in the result based on the value of
1764 * 'opstrategy'. For example, if it were equality, we'd return just the
1765 * partition that would contain that key or a set of partitions if the key
1766 * didn't consist of all partitioning columns. For non-equality strategies,
1767 * we'd need to include other partitions as appropriate.
1768 *
1769 * 'nullkeys' is the set containing the offset of the partition keys (0 to
1770 * partnatts - 1) that were matched to an IS NULL clause. This is only
1771 * considered for hash partitioning as we need to pass which keys are null
1772 * to the hash partition bound search function. It is never possible to
1773 * have an expression be present in 'exprs' for a given partition key and
1774 * the corresponding bit set in 'nullkeys'.
1775 */
1776typedef struct PartitionPruneStepOp
1777{
1778 PartitionPruneStep step;
1779
1780 StrategyNumber opstrategy;
1781 List *exprs;
1782 List *cmpfns;
1783 Bitmapset *nullkeys;
1785
1786/*
1787 * PartitionPruneStepCombine - Information to prune using a BoolExpr clause
1788 *
1789 * For BoolExpr clauses, we combine the set of partitions determined for each
1790 * of the argument clauses.
1791 */
1792typedef enum PartitionPruneCombineOp
1793{
1797
1798typedef struct PartitionPruneStepCombine
1799{
1800 PartitionPruneStep step;
1801
1802 PartitionPruneCombineOp combineOp;
1803 List *source_stepids;
1805
1806
1807/*
1808 * Plan invalidation info
1809 *
1810 * We track the objects on which a PlannedStmt depends in two ways:
1811 * relations are recorded as a simple list of OIDs, and everything else
1812 * is represented as a list of PlanInvalItems. A PlanInvalItem is designed
1813 * to be used with the syscache invalidation mechanism, so it identifies a
1814 * system catalog entry by cache ID and hash value.
1815 */
1816typedef struct PlanInvalItem
1817{
1819
1820 NodeTag type;
1821 /* a syscache ID, see utils/syscache.h */
1822 int cacheId;
1823 /* hash value of object's cache lookup key */
1824 uint32 hashValue;
1826
1827/*
1828 * MonotonicFunction
1829 *
1830 * Allows the planner to track monotonic properties of functions. A function
1831 * is monotonically increasing if a subsequent call cannot yield a lower value
1832 * than the previous call. A monotonically decreasing function cannot yield a
1833 * higher value on subsequent calls, and a function which is both must return
1834 * the same value on each call.
1835 */
1836typedef enum MonotonicFunction
1837{
1839 MONOTONICFUNC_INCREASING = (1 << 0),
1840 MONOTONICFUNC_DECREASING = (1 << 1),
1843
1844/*
1845 * SubPlanRTInfo
1846 *
1847 * Information about which range table entries came from which subquery
1848 * planning cycles.
1849 */
1850typedef struct SubPlanRTInfo
1851{
1852 NodeTag type;
1853 char *plan_name;
1854 Index rtoffset;
1855 bool dummy;
1857
1858/*
1859 * ElidedNode
1860 *
1861 * Information about nodes elided from the final plan tree: trivial subquery
1862 * scans, and single-child Append and MergeAppend nodes.
1863 *
1864 * plan_node_id is that of the surviving plan node, the sole child of the
1865 * one which was elided.
1866 */
1867typedef struct ElidedNode
1868{
1869 NodeTag type;
1870 int plan_node_id;
1871 NodeTag elided_type;
1872 Bitmapset *relids;
1873} ElidedNode;
1874
1875#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:625
uint32_t uint32
Definition c.h:624
unsigned int Index
Definition c.h:698
static DataChecksumsWorkerOperation operation
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: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:1794
@ PARTPRUNE_COMBINE_INTERSECT
Definition plannodes.h:1796
@ PARTPRUNE_COMBINE_UNION
Definition plannodes.h:1795
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:1556
@ ROW_MARK_COPY
Definition plannodes.h:1562
@ ROW_MARK_REFERENCE
Definition plannodes.h:1561
@ ROW_MARK_SHARE
Definition plannodes.h:1559
@ ROW_MARK_EXCLUSIVE
Definition plannodes.h:1557
@ ROW_MARK_NOKEYEXCLUSIVE
Definition plannodes.h:1558
@ ROW_MARK_KEYSHARE
Definition plannodes.h:1560
MonotonicFunction
Definition plannodes.h:1838
@ MONOTONICFUNC_NONE
Definition plannodes.h:1839
@ MONOTONICFUNC_DECREASING
Definition plannodes.h:1841
@ MONOTONICFUNC_INCREASING
Definition plannodes.h:1840
@ MONOTONICFUNC_BOTH
Definition plannodes.h:1842
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:135
Bitmapset * extParam
Definition plannodes.h:255
struct Plan * lefttree
Definition plannodes.h:239
struct Plan * righttree
Definition plannodes.h:240
Bitmapset * allParam
Definition plannodes.h:256
List * initPlan
Definition plannodes.h:242
Cardinality numGroups
Definition plannodes.h: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 1565 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 1837 of file plannodes.h.

◆ PartitionPruneCombineOp

Enumerator
PARTPRUNE_COMBINE_UNION 
PARTPRUNE_COMBINE_INTERSECT 

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

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

◆ SubqueryScanStatus

Enumerator
SUBQUERY_SCAN_UNKNOWN 
SUBQUERY_SCAN_TRIVIAL 
SUBQUERY_SCAN_NONTRIVIAL 

Definition at line 766 of file plannodes.h.