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

Go to the source code of this file.

Data Structures

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

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
 

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 169 of file plannodes.h.

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

◆ innerPlan

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

Definition at line 260 of file plannodes.h.

◆ outerPlan

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

Definition at line 261 of file plannodes.h.

◆ RowMarkRequiresRowShareLock

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

Definition at line 1544 of file plannodes.h.

Typedef Documentation

◆ Agg

◆ Append

◆ BitmapAnd

◆ BitmapHeapScan

◆ BitmapIndexScan

◆ BitmapOr

◆ CteScan

◆ CustomScan

◆ ForeignScan

◆ FunctionScan

◆ Gather

◆ GatherMerge

◆ Group

◆ Hash

◆ HashJoin

◆ IncrementalSort

◆ IndexOnlyScan

◆ IndexScan

◆ Join

◆ Limit

◆ LockRows

◆ Material

◆ Memoize

◆ MergeAppend

◆ MergeJoin

◆ ModifyTable

◆ MonotonicFunction

◆ NamedTuplestoreScan

◆ NestLoop

◆ NestLoopParam

◆ PartitionedRelPruneInfo

◆ PartitionPruneCombineOp

◆ PartitionPruneInfo

◆ PartitionPruneStep

◆ PartitionPruneStepCombine

◆ PartitionPruneStepOp

◆ Plan

◆ PlanInvalItem

◆ PlannedStmt

◆ PlannedStmtOrigin

◆ PlanRowMark

◆ ProjectSet

◆ RecursiveUnion

◆ Result

◆ ResultType

◆ RowMarkType

◆ SampleScan

◆ Scan

◆ SeqScan

◆ SetOp

◆ Sort

◆ 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 1816 of file plannodes.h.

◆ PartitionPruneCombineOp

Enumerator
PARTPRUNE_COMBINE_UNION 
PARTPRUNE_COMBINE_INTERSECT 

Definition at line 1772 of file plannodes.h.

◆ PlannedStmtOrigin

Enumerator
PLAN_STMT_UNKNOWN 
PLAN_STMT_INTERNAL 
PLAN_STMT_STANDARD 
PLAN_STMT_CACHE_GENERIC 
PLAN_STMT_CACHE_CUSTOM 

Definition at line 37 of file plannodes.h.

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

◆ ResultType

Enumerator
RESULT_TYPE_GATING 
RESULT_TYPE_SCAN 
RESULT_TYPE_JOIN 
RESULT_TYPE_UPPER 
RESULT_TYPE_MINMAX 

Definition at line 269 of file plannodes.h.

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

◆ RowMarkType

Enumerator
ROW_MARK_EXCLUSIVE 
ROW_MARK_NOKEYEXCLUSIVE 
ROW_MARK_SHARE 
ROW_MARK_KEYSHARE 
ROW_MARK_REFERENCE 
ROW_MARK_COPY 

Definition at line 1534 of file plannodes.h.

1535{
1536 ROW_MARK_EXCLUSIVE, /* obtain exclusive tuple lock */
1537 ROW_MARK_NOKEYEXCLUSIVE, /* obtain no-key exclusive tuple lock */
1538 ROW_MARK_SHARE, /* obtain shared tuple lock */
1539 ROW_MARK_KEYSHARE, /* obtain keyshare tuple lock */
1540 ROW_MARK_REFERENCE, /* just fetch the TID, don't lock it */
1541 ROW_MARK_COPY, /* physically copy the row value */
1542} RowMarkType;

◆ SubqueryScanStatus

Enumerator
SUBQUERY_SCAN_UNKNOWN 
SUBQUERY_SCAN_TRIVIAL 
SUBQUERY_SCAN_NONTRIVIAL 

Definition at line 745 of file plannodes.h.