PostgreSQL Source Code git master
Loading...
Searching...
No Matches
pathnodes.h File Reference
#include "access/sdir.h"
#include "lib/stringinfo.h"
#include "nodes/params.h"
#include "nodes/parsenodes.h"
#include "storage/block.h"
Include dependency graph for pathnodes.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  QualCost
 
struct  AggClauseCosts
 
struct  PlannerGlobal
 
struct  PlannerInfo
 
struct  PartitionSchemeData
 
struct  RelOptInfo
 
struct  RelAggInfo
 
struct  IndexOptInfo
 
struct  ForeignKeyOptInfo
 
struct  StatisticExtInfo
 
struct  JoinDomain
 
struct  EquivalenceClass
 
struct  EquivalenceMember
 
struct  EquivalenceMemberIterator
 
struct  PathKey
 
struct  GroupByOrdering
 
struct  PathTarget
 
struct  ParamPathInfo
 
struct  Path
 
struct  IndexPath
 
struct  IndexClause
 
struct  BitmapHeapPath
 
struct  BitmapAndPath
 
struct  BitmapOrPath
 
struct  TidPath
 
struct  TidRangePath
 
struct  SubqueryScanPath
 
struct  ForeignPath
 
struct  CustomPath
 
struct  AppendPath
 
struct  MergeAppendPath
 
struct  GroupResultPath
 
struct  MaterialPath
 
struct  MemoizePath
 
struct  GatherPath
 
struct  GatherMergePath
 
struct  JoinPath
 
struct  NestPath
 
struct  MergePath
 
struct  HashPath
 
struct  ProjectionPath
 
struct  ProjectSetPath
 
struct  SortPath
 
struct  IncrementalSortPath
 
struct  GroupPath
 
struct  UniquePath
 
struct  AggPath
 
struct  GroupingSetData
 
struct  RollupData
 
struct  GroupingSetsPath
 
struct  MinMaxAggPath
 
struct  WindowAggPath
 
struct  SetOpPath
 
struct  RecursiveUnionPath
 
struct  LockRowsPath
 
struct  ModifyTablePath
 
struct  LimitPath
 
struct  RestrictInfo
 
struct  MergeScanSelCache
 
struct  PlaceHolderVar
 
struct  SpecialJoinInfo
 
struct  OuterJoinClauseInfo
 
struct  AppendRelInfo
 
struct  RowIdentityVarInfo
 
struct  PlaceHolderInfo
 
struct  MinMaxAggInfo
 
struct  AggClauseInfo
 
struct  GroupingExprInfo
 
struct  PlannerParamItem
 
struct  SemiAntiJoinFactors
 
struct  JoinPathExtraData
 
struct  GroupPathExtraData
 
struct  FinalPathExtraData
 
struct  JoinCostWorkspace
 
struct  AggInfo
 
struct  AggTransInfo
 
struct  UniqueRelInfo
 

Macros

#define PGS_SEQSCAN   0x00000001
 
#define PGS_INDEXSCAN   0x00000002
 
#define PGS_INDEXONLYSCAN   0x00000004
 
#define PGS_BITMAPSCAN   0x00000008
 
#define PGS_TIDSCAN   0x00000010
 
#define PGS_FOREIGNJOIN   0x00000020
 
#define PGS_MERGEJOIN_PLAIN   0x00000040
 
#define PGS_MERGEJOIN_MATERIALIZE   0x00000080
 
#define PGS_NESTLOOP_PLAIN   0x00000100
 
#define PGS_NESTLOOP_MATERIALIZE   0x00000200
 
#define PGS_NESTLOOP_MEMOIZE   0x00000400
 
#define PGS_HASHJOIN   0x00000800
 
#define PGS_APPEND   0x00001000
 
#define PGS_MERGE_APPEND   0x00002000
 
#define PGS_GATHER   0x00004000
 
#define PGS_GATHER_MERGE   0x00008000
 
#define PGS_CONSIDER_INDEXONLY   0x00010000
 
#define PGS_CONSIDER_PARTITIONWISE   0x00020000
 
#define PGS_CONSIDER_NONPARTIAL   0x00040000
 
#define PGS_SCAN_ANY
 
#define PGS_MERGEJOIN_ANY    (PGS_MERGEJOIN_PLAIN | PGS_MERGEJOIN_MATERIALIZE)
 
#define PGS_NESTLOOP_ANY    (PGS_NESTLOOP_PLAIN | PGS_NESTLOOP_MATERIALIZE | PGS_NESTLOOP_MEMOIZE)
 
#define PGS_JOIN_ANY    (PGS_FOREIGNJOIN | PGS_MERGEJOIN_ANY | PGS_NESTLOOP_ANY | PGS_HASHJOIN)
 
#define planner_subplan_get_plan(root, subplan)    ((Plan *) list_nth((root)->glob->subplans, (subplan)->plan_id - 1))
 
#define planner_rt_fetch(rti, root)
 
#define AMFLAG_HAS_TID_RANGE   (1 << 0)
 
#define IS_SIMPLE_REL(rel)
 
#define IS_JOIN_REL(rel)
 
#define IS_UPPER_REL(rel)
 
#define IS_OTHER_REL(rel)
 
#define IS_PARTITIONED_REL(rel)
 
#define REL_HAS_ALL_PART_PROPS(rel)
 
#define RELATION_WAS_MADE_UNIQUE(rel, sjinfo, nominal_jointype)
 
#define IS_GROUPED_REL(rel)    ((rel)->agg_info != NULL)
 
#define EC_MUST_BE_REDUNDANT(eclass)    ((eclass)->ec_has_const)
 
#define get_pathtarget_sortgroupref(target, colno)    ((target)->sortgrouprefs ? (target)->sortgrouprefs[colno] : (Index) 0)
 
#define PATH_REQ_OUTER(path)    ((path)->param_info ? (path)->param_info->ppi_req_outer : (Relids) NULL)
 
#define IS_DUMMY_APPEND(p)    (IsA((p), AppendPath) && ((AppendPath *) (p))->subpaths == NIL)
 
#define IS_DUMMY_REL(r)   is_dummy_rel(r)
 
#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids)
 
#define GROUPING_CAN_USE_SORT   0x0001
 
#define GROUPING_CAN_USE_HASH   0x0002
 
#define GROUPING_CAN_PARTIAL_AGG   0x0004
 

Typedefs

typedef BitmapsetRelids
 
typedef enum CostSelector CostSelector
 
typedef struct QualCost QualCost
 
typedef struct AggClauseCosts AggClauseCosts
 
typedef enum UpperRelationKind UpperRelationKind
 
typedef struct PlannerGlobal PlannerGlobal
 
typedef struct PlannerInfo PlannerInfo
 
typedef struct PartitionSchemeData PartitionSchemeData
 
typedef struct PartitionSchemeDataPartitionScheme
 
typedef enum RelOptKind RelOptKind
 
typedef struct RelOptInfo RelOptInfo
 
typedef struct RelAggInfo RelAggInfo
 
typedef struct IndexOptInfo IndexOptInfo
 
typedef struct ForeignKeyOptInfo ForeignKeyOptInfo
 
typedef struct StatisticExtInfo StatisticExtInfo
 
typedef struct JoinDomain JoinDomain
 
typedef struct EquivalenceClass EquivalenceClass
 
typedef struct EquivalenceMember EquivalenceMember
 
typedef struct PathKey PathKey
 
typedef struct GroupByOrdering GroupByOrdering
 
typedef enum VolatileFunctionStatus VolatileFunctionStatus
 
typedef struct PathTarget PathTarget
 
typedef struct ParamPathInfo ParamPathInfo
 
typedef struct Path Path
 
typedef struct IndexPath IndexPath
 
typedef struct IndexClause IndexClause
 
typedef struct BitmapHeapPath BitmapHeapPath
 
typedef struct BitmapAndPath BitmapAndPath
 
typedef struct BitmapOrPath BitmapOrPath
 
typedef struct TidPath TidPath
 
typedef struct TidRangePath TidRangePath
 
typedef struct SubqueryScanPath SubqueryScanPath
 
typedef struct ForeignPath ForeignPath
 
typedef struct CustomPath CustomPath
 
typedef struct AppendPath AppendPath
 
typedef struct MergeAppendPath MergeAppendPath
 
typedef struct GroupResultPath GroupResultPath
 
typedef struct MaterialPath MaterialPath
 
typedef struct MemoizePath MemoizePath
 
typedef struct GatherPath GatherPath
 
typedef struct GatherMergePath GatherMergePath
 
typedef struct JoinPath JoinPath
 
typedef struct NestPath NestPath
 
typedef struct MergePath MergePath
 
typedef struct HashPath HashPath
 
typedef struct ProjectionPath ProjectionPath
 
typedef struct ProjectSetPath ProjectSetPath
 
typedef struct SortPath SortPath
 
typedef struct IncrementalSortPath IncrementalSortPath
 
typedef struct GroupPath GroupPath
 
typedef struct UniquePath UniquePath
 
typedef struct AggPath AggPath
 
typedef struct GroupingSetData GroupingSetData
 
typedef struct RollupData RollupData
 
typedef struct GroupingSetsPath GroupingSetsPath
 
typedef struct MinMaxAggPath MinMaxAggPath
 
typedef struct WindowAggPath WindowAggPath
 
typedef struct SetOpPath SetOpPath
 
typedef struct RecursiveUnionPath RecursiveUnionPath
 
typedef struct LockRowsPath LockRowsPath
 
typedef struct ModifyTablePath ModifyTablePath
 
typedef struct LimitPath LimitPath
 
typedef struct RestrictInfo RestrictInfo
 
typedef struct MergeScanSelCache MergeScanSelCache
 
typedef struct PlaceHolderVar PlaceHolderVar
 
typedef struct SpecialJoinInfo SpecialJoinInfo
 
typedef struct OuterJoinClauseInfo OuterJoinClauseInfo
 
typedef struct AppendRelInfo AppendRelInfo
 
typedef struct RowIdentityVarInfo RowIdentityVarInfo
 
typedef struct PlaceHolderInfo PlaceHolderInfo
 
typedef struct MinMaxAggInfo MinMaxAggInfo
 
typedef struct AggClauseInfo AggClauseInfo
 
typedef struct GroupingExprInfo GroupingExprInfo
 
typedef struct PlannerParamItem PlannerParamItem
 
typedef struct SemiAntiJoinFactors SemiAntiJoinFactors
 
typedef struct JoinPathExtraData JoinPathExtraData
 
typedef struct JoinCostWorkspace JoinCostWorkspace
 
typedef struct AggInfo AggInfo
 
typedef struct AggTransInfo AggTransInfo
 
typedef struct UniqueRelInfo UniqueRelInfo
 

Enumerations

enum  CostSelector { STARTUP_COST , TOTAL_COST }
 
enum  UpperRelationKind {
  UPPERREL_SETOP , UPPERREL_PARTIAL_GROUP_AGG , UPPERREL_GROUP_AGG , UPPERREL_WINDOW ,
  UPPERREL_PARTIAL_DISTINCT , UPPERREL_DISTINCT , UPPERREL_ORDERED , UPPERREL_FINAL
}
 
enum  RelOptKind {
  RELOPT_BASEREL , RELOPT_JOINREL , RELOPT_OTHER_MEMBER_REL , RELOPT_OTHER_JOINREL ,
  RELOPT_UPPER_REL , RELOPT_OTHER_UPPER_REL
}
 
enum  VolatileFunctionStatus { VOLATILITY_UNKNOWN = 0 , VOLATILITY_VOLATILE , VOLATILITY_NOVOLATILE }
 
enum  PartitionwiseAggregateType { PARTITIONWISE_AGGREGATE_NONE , PARTITIONWISE_AGGREGATE_FULL , PARTITIONWISE_AGGREGATE_PARTIAL }
 

Functions

bool is_dummy_rel (RelOptInfo *rel)
 

Macro Definition Documentation

◆ AMFLAG_HAS_TID_RANGE

#define AMFLAG_HAS_TID_RANGE   (1 << 0)

Definition at line 961 of file pathnodes.h.

◆ EC_MUST_BE_REDUNDANT

#define EC_MUST_BE_REDUNDANT (   eclass)     ((eclass)->ec_has_const)

Definition at line 1670 of file pathnodes.h.

1700{
1702
1703 NodeTag type;
1704
1705 Expr *em_expr; /* the expression represented */
1706 Relids em_relids; /* all relids appearing in em_expr */
1707 bool em_is_const; /* expression is pseudoconstant? */
1708 bool em_is_child; /* derived version for a child relation? */
1709 Oid em_datatype; /* the "nominal type" used by the opfamily */
1710 JoinDomain *em_jdomain; /* join domain containing the source clause */
1711 /* if em_is_child is true, this links to corresponding EM for top parent */
1714
1715/*
1716 * EquivalenceMemberIterator
1717 *
1718 * EquivalenceMemberIterator allows efficient access to sets of
1719 * EquivalenceMembers for callers which require access to child members.
1720 * Because partitioning workloads can result in large numbers of child
1721 * members, the child members are not stored in the EquivalenceClass's
1722 * ec_members List. Instead, these are stored in the EquivalenceClass's
1723 * ec_childmembers array of Lists. The functionality provided by
1724 * EquivalenceMemberIterator aims to provide efficient access to parent
1725 * members and child members belonging to specific child relids.
1726 *
1727 * Currently, there is only one way to initialize and iterate over an
1728 * EquivalenceMemberIterator and that is via the setup_eclass_member_iterator
1729 * and eclass_member_iterator_next functions. The iterator object is
1730 * generally a local variable which is passed by address to
1731 * setup_eclass_member_iterator. The calling function defines which
1732 * EquivalenceClass the iterator should be looking at and which child
1733 * relids to also return members for. child_relids can be passed as NULL, but
1734 * the caller may as well just perform a foreach loop over ec_members as only
1735 * parent-level members will be returned in that case.
1736 *
1737 * When calling the next function on an EquivalenceMemberIterator, all
1738 * parent-level EquivalenceMembers are returned first, followed by all child
1739 * members for the specified 'child_relids' for all child members which were
1740 * indexed by any of the specified 'child_relids' in add_child_eq_member().
1741 *
1742 * Code using the iterator method of finding EquivalenceMembers will generally
1743 * always want to ensure the returned member matches their search criteria
1744 * rather than relying on the filtering to be done for them as all parent
1745 * members are returned and for members belonging to RELOPT_OTHER_JOINREL
1746 * rels, the member's em_relids may be a superset of the specified
1747 * 'child_relids', which might not be what the caller wants.
1748 *
1749 * The most common way to use this iterator is as follows:
1750 * -----
1751 * EquivalenceMemberIterator it;
1752 * EquivalenceMember *em;
1753 *
1754 * setup_eclass_member_iterator(&it, ec, child_relids);
1755 * while ((em = eclass_member_iterator_next(&it)) != NULL)
1756 * {
1757 * ...
1758 * }
1759 * -----
1760 * It is not valid to call eclass_member_iterator_next() after it has returned
1761 * NULL for any given EquivalenceMemberIterator. Individual fields within
1762 * the EquivalenceMemberIterator struct must not be accessed by callers.
1763 */
1764typedef struct
1765{
1766 EquivalenceClass *ec; /* The EquivalenceClass to iterate over */
1767 int current_relid; /* Current relid position within 'relids'. -1
1768 * when still looping over ec_members and -2
1769 * at the end of iteration */
1770 Relids child_relids; /* Relids of child relations of interest.
1771 * Non-child rels are ignored */
1772 ListCell *current_cell; /* Next cell to return within current_list */
1773 List *current_list; /* Current list of members being returned */
1775
1776/*
1777 * PathKeys
1778 *
1779 * The sort ordering of a path is represented by a list of PathKey nodes.
1780 * An empty list implies no known ordering. Otherwise the first item
1781 * represents the primary sort key, the second the first secondary sort key,
1782 * etc. The value being sorted is represented by linking to an
1783 * EquivalenceClass containing that value and including pk_opfamily among its
1784 * ec_opfamilies. The EquivalenceClass tells which collation to use, too.
1785 * This is a convenient method because it makes it trivial to detect
1786 * equivalent and closely-related orderings. (See optimizer/README for more
1787 * information.)
1788 *
1789 * Note: pk_cmptype is either COMPARE_LT (for ASC) or COMPARE_GT (for DESC).
1790 */
1791typedef struct PathKey
1792{
1794
1795 NodeTag type;
1796
1797 /* the value that is ordered */
1799 Oid pk_opfamily; /* index opfamily defining the ordering */
1800 CompareType pk_cmptype; /* sort direction (ASC or DESC) */
1801 bool pk_nulls_first; /* do NULLs come before normal values? */
1802} PathKey;
1803
1804/*
1805 * Contains an order of group-by clauses and the corresponding list of
1806 * pathkeys.
1807 *
1808 * The elements of 'clauses' list should have the same order as the head of
1809 * 'pathkeys' list. The tleSortGroupRef of the clause should be equal to
1810 * ec_sortref of the pathkey equivalence class. If there are redundant
1811 * clauses with the same tleSortGroupRef, they must be grouped together.
1812 */
1813typedef struct GroupByOrdering
1814{
1815 NodeTag type;
1816
1817 List *pathkeys;
1818 List *clauses;
1820
1821/*
1822 * VolatileFunctionStatus -- allows nodes to cache their
1823 * contain_volatile_functions properties. VOLATILITY_UNKNOWN means not yet
1824 * determined.
1825 */
1826typedef enum VolatileFunctionStatus
1827{
1832
1833/*
1834 * PathTarget
1835 *
1836 * This struct contains what we need to know during planning about the
1837 * targetlist (output columns) that a Path will compute. Each RelOptInfo
1838 * includes a default PathTarget, which its individual Paths may simply
1839 * reference. However, in some cases a Path may compute outputs different
1840 * from other Paths, and in that case we make a custom PathTarget for it.
1841 * For example, an indexscan might return index expressions that would
1842 * otherwise need to be explicitly calculated. (Note also that "upper"
1843 * relations generally don't have useful default PathTargets.)
1844 *
1845 * exprs contains bare expressions; they do not have TargetEntry nodes on top,
1846 * though those will appear in finished Plans.
1847 *
1848 * sortgrouprefs[] is an array of the same length as exprs, containing the
1849 * corresponding sort/group refnos, or zeroes for expressions not referenced
1850 * by sort/group clauses. If sortgrouprefs is NULL (which it generally is in
1851 * RelOptInfo.reltarget targets; only upper-level Paths contain this info),
1852 * we have not identified sort/group columns in this tlist. This allows us to
1853 * deal with sort/group refnos when needed with less expense than including
1854 * TargetEntry nodes in the exprs list.
1855 */
1856typedef struct PathTarget
1857{
1859
1860 NodeTag type;
1861
1862 /* list of expressions to be computed */
1863 List *exprs;
1864
1865 /* corresponding sort/group refnos, or 0 */
1867
1868 /* cost of evaluating the expressions */
1869 QualCost cost;
1870
1871 /* estimated avg width of result tuples */
1872 int width;
1873
1874 /* indicates if exprs contain any volatile functions */
1876} PathTarget;
1877
1878/* Convenience macro to get a sort/group refno from a PathTarget */
1879#define get_pathtarget_sortgroupref(target, colno) \
1880 ((target)->sortgrouprefs ? (target)->sortgrouprefs[colno] : (Index) 0)
1881
1882
1883/*
1884 * ParamPathInfo
1885 *
1886 * All parameterized paths for a given relation with given required outer rels
1887 * link to a single ParamPathInfo, which stores common information such as
1888 * the estimated rowcount for this parameterization. We do this partly to
1889 * avoid recalculations, but mostly to ensure that the estimated rowcount
1890 * is in fact the same for every such path.
1891 *
1892 * Note: ppi_clauses is only used in ParamPathInfos for base relation paths;
1893 * in join cases it's NIL because the set of relevant clauses varies depending
1894 * on how the join is formed. The relevant clauses will appear in each
1895 * parameterized join path's joinrestrictinfo list, instead. ParamPathInfos
1896 * for append relations don't bother with this, either.
1897 *
1898 * ppi_serials is the set of rinfo_serial numbers for quals that are enforced
1899 * by this path. As with ppi_clauses, it's only maintained for baserels.
1900 * (We could construct it on-the-fly from ppi_clauses, but it seems better
1901 * to materialize a copy.)
1902 */
1903typedef struct ParamPathInfo
1904{
1906
1907 NodeTag type;
1908
1909 Relids ppi_req_outer; /* rels supplying parameters used by path */
1910 Cardinality ppi_rows; /* estimated number of result tuples */
1911 List *ppi_clauses; /* join clauses available from outer rels */
1912 Bitmapset *ppi_serials; /* set of rinfo_serial for enforced quals */
1914
1915
1916/*
1917 * Type "Path" is used as-is for sequential-scan paths, as well as some other
1918 * simple plan types that we don't need any extra information in the path for.
1919 * For other path types it is the first component of a larger struct.
1920 *
1921 * "pathtype" is the NodeTag of the Plan node we could build from this Path.
1922 * It is partially redundant with the Path's NodeTag, but allows us to use
1923 * the same Path type for multiple Plan types when there is no need to
1924 * distinguish the Plan type during path processing.
1925 *
1926 * "parent" identifies the relation this Path scans, and "pathtarget"
1927 * describes the precise set of output columns the Path would compute.
1928 * In simple cases all Paths for a given rel share the same targetlist,
1929 * which we represent by having path->pathtarget equal to parent->reltarget.
1930 *
1931 * "param_info", if not NULL, links to a ParamPathInfo that identifies outer
1932 * relation(s) that provide parameter values to each scan of this path.
1933 * That means this path can only be joined to those rels by means of nestloop
1934 * joins with this path on the inside. Also note that a parameterized path
1935 * is responsible for testing all "movable" joinclauses involving this rel
1936 * and the specified outer rel(s).
1937 *
1938 * "rows" is the same as parent->rows in simple paths, but in parameterized
1939 * paths it can be less than parent->rows, reflecting the fact that we've
1940 * filtered by extra join conditions.
1941 *
1942 * "pathkeys" is a List of PathKey nodes (see above), describing the sort
1943 * ordering of the path's output rows.
1944 *
1945 * We do not support copying Path trees, mainly because the circular linkages
1946 * between RelOptInfo and Path nodes can't be handled easily in a simple
1947 * depth-first traversal. We also don't have read support at the moment.
1948 */
1949typedef struct Path
1950{
1952
1953 NodeTag type;
1954
1955 /* tag identifying scan/join method */
1957
1958 /*
1959 * the relation this path can build
1960 *
1961 * We do NOT print the parent, else we'd be in infinite recursion. We can
1962 * print the parent's relids for identification purposes, though.
1963 */
1965
1966 /*
1967 * list of Vars/Exprs, cost, width
1968 *
1969 * We print the pathtarget only if it's not the default one for the rel.
1970 */
1972
1973 /*
1974 * parameterization info, or NULL if none
1975 *
1976 * We do not print the whole of param_info, since it's printed via
1977 * RelOptInfo; it's sufficient and less cluttering to print just the
1978 * required outer relids.
1979 */
1981
1982 /* engage parallel-aware logic? */
1983 bool parallel_aware;
1984 /* OK to use as part of parallel plan? */
1985 bool parallel_safe;
1986 /* desired # of workers; 0 = not parallel */
1987 int parallel_workers;
1988
1989 /* estimated size/costs for path (see costsize.c for more info) */
1990 Cardinality rows; /* estimated number of result tuples */
1991 int disabled_nodes; /* count of disabled nodes */
1992 Cost startup_cost; /* cost expended before fetching any tuples */
1993 Cost total_cost; /* total cost (assuming all tuples fetched) */
1994
1995 /* sort ordering of path's output; a List of PathKey nodes; see above */
1996 List *pathkeys;
1997} Path;
1998
1999/* Macro for extracting a path's parameterization relids; beware double eval */
2000#define PATH_REQ_OUTER(path) \
2001 ((path)->param_info ? (path)->param_info->ppi_req_outer : (Relids) NULL)
2002
2003/*----------
2004 * IndexPath represents an index scan over a single index.
2005 *
2006 * This struct is used for both regular indexscans and index-only scans;
2007 * path.pathtype is T_IndexScan or T_IndexOnlyScan to show which is meant.
2008 *
2009 * 'indexinfo' is the index to be scanned.
2010 *
2011 * 'indexclauses' is a list of IndexClause nodes, each representing one
2012 * index-checkable restriction, with implicit AND semantics across the list.
2013 * An empty list implies a full index scan.
2014 *
2015 * 'indexorderbys', if not NIL, is a list of ORDER BY expressions that have
2016 * been found to be usable as ordering operators for an amcanorderbyop index.
2017 * The list must match the path's pathkeys, ie, one expression per pathkey
2018 * in the same order. These are not RestrictInfos, just bare expressions,
2019 * since they generally won't yield booleans. It's guaranteed that each
2020 * expression has the index key on the left side of the operator.
2021 *
2022 * 'indexorderbycols' is an integer list of index column numbers (zero-based)
2023 * of the same length as 'indexorderbys', showing which index column each
2024 * ORDER BY expression is meant to be used with. (There is no restriction
2025 * on which index column each ORDER BY can be used with.)
2026 *
2027 * 'indexscandir' is one of:
2028 * ForwardScanDirection: forward scan of an index
2029 * BackwardScanDirection: backward scan of an ordered index
2030 * Unordered indexes will always have an indexscandir of ForwardScanDirection.
2031 *
2032 * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that
2033 * we need not recompute them when considering using the same index in a
2034 * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath
2035 * itself represent the costs of an IndexScan or IndexOnlyScan plan type.
2036 *----------
2037 */
2038typedef struct IndexPath
2039{
2040 Path path;
2048} IndexPath;
2049
2050/*
2051 * Each IndexClause references a RestrictInfo node from the query's WHERE
2052 * or JOIN conditions, and shows how that restriction can be applied to
2053 * the particular index. We support both indexclauses that are directly
2054 * usable by the index machinery, which are typically of the form
2055 * "indexcol OP pseudoconstant", and those from which an indexable qual
2056 * can be derived. The simplest such transformation is that a clause
2057 * of the form "pseudoconstant OP indexcol" can be commuted to produce an
2058 * indexable qual (the index machinery expects the indexcol to be on the
2059 * left always). Another example is that we might be able to extract an
2060 * indexable range condition from a LIKE condition, as in "x LIKE 'foo%bar'"
2061 * giving rise to "x >= 'foo' AND x < 'fop'". Derivation of such lossy
2062 * conditions is done by a planner support function attached to the
2063 * indexclause's top-level function or operator.
2064 *
2065 * indexquals is a list of RestrictInfos for the directly-usable index
2066 * conditions associated with this IndexClause. In the simplest case
2067 * it's a one-element list whose member is iclause->rinfo. Otherwise,
2068 * it contains one or more directly-usable indexqual conditions extracted
2069 * from the given clause. The 'lossy' flag indicates whether the
2070 * indexquals are semantically equivalent to the original clause, or
2071 * represent a weaker condition.
2072 *
2073 * Normally, indexcol is the index of the single index column the clause
2074 * works on, and indexcols is NIL. But if the clause is a RowCompareExpr,
2075 * indexcol is the index of the leading column, and indexcols is a list of
2076 * all the affected columns. (Note that indexcols matches up with the
2077 * columns of the actual indexable RowCompareExpr in indexquals, which
2078 * might be different from the original in rinfo.)
2079 *
2080 * An IndexPath's IndexClause list is required to be ordered by index
2081 * column, i.e. the indexcol values must form a nondecreasing sequence.
2082 * (The order of multiple clauses for the same index column is unspecified.)
2083 */
2084typedef struct IndexClause
2085{
2087
2088 NodeTag type;
2089 struct RestrictInfo *rinfo; /* original restriction or join clause */
2090 List *indexquals; /* indexqual(s) derived from it */
2091 bool lossy; /* are indexquals a lossy version of clause? */
2092 AttrNumber indexcol; /* index column the clause uses (zero-based) */
2093 List *indexcols; /* multiple index columns, if RowCompare */
2094} IndexClause;
2095
2096/*
2097 * BitmapHeapPath represents one or more indexscans that generate TID bitmaps
2098 * instead of directly accessing the heap, followed by AND/OR combinations
2099 * to produce a single bitmap, followed by a heap scan that uses the bitmap.
2100 * Note that the output is always considered unordered, since it will come
2101 * out in physical heap order no matter what the underlying indexes did.
2102 *
2103 * The individual indexscans are represented by IndexPath nodes, and any
2104 * logic on top of them is represented by a tree of BitmapAndPath and
2105 * BitmapOrPath nodes. Notice that we can use the same IndexPath node both
2106 * to represent a regular (or index-only) index scan plan, and as the child
2107 * of a BitmapHeapPath that represents scanning the same index using a
2108 * BitmapIndexScan. The startup_cost and total_cost figures of an IndexPath
2109 * always represent the costs to use it as a regular (or index-only)
2110 * IndexScan. The costs of a BitmapIndexScan can be computed using the
2111 * IndexPath's indextotalcost and indexselectivity.
2112 */
2113typedef struct BitmapHeapPath
2114{
2115 Path path;
2116 Path *bitmapqual; /* IndexPath, BitmapAndPath, BitmapOrPath */
2118
2119/*
2120 * BitmapAndPath represents a BitmapAnd plan node; it can only appear as
2121 * part of the substructure of a BitmapHeapPath. The Path structure is
2122 * a bit more heavyweight than we really need for this, but for simplicity
2123 * we make it a derivative of Path anyway.
2124 */
2125typedef struct BitmapAndPath
2126{
2127 Path path;
2128 List *bitmapquals; /* IndexPaths and BitmapOrPaths */
2131
2132/*
2133 * BitmapOrPath represents a BitmapOr plan node; it can only appear as
2134 * part of the substructure of a BitmapHeapPath. The Path structure is
2135 * a bit more heavyweight than we really need for this, but for simplicity
2136 * we make it a derivative of Path anyway.
2137 */
2138typedef struct BitmapOrPath
2139{
2140 Path path;
2141 List *bitmapquals; /* IndexPaths and BitmapAndPaths */
2143} BitmapOrPath;
2144
2145/*
2146 * TidPath represents a scan by TID
2147 *
2148 * tidquals is an implicitly OR'ed list of qual expressions of the form
2149 * "CTID = pseudoconstant", or "CTID = ANY(pseudoconstant_array)",
2150 * or a CurrentOfExpr for the relation.
2151 */
2152typedef struct TidPath
2153{
2154 Path path;
2155 List *tidquals; /* qual(s) involving CTID = something */
2156} TidPath;
2157
2158/*
2159 * TidRangePath represents a scan by a contiguous range of TIDs
2160 *
2161 * tidrangequals is an implicitly AND'ed list of qual expressions of the form
2162 * "CTID relop pseudoconstant", where relop is one of >,>=,<,<=.
2163 */
2164typedef struct TidRangePath
2165{
2166 Path path;
2168} TidRangePath;
2169
2170/*
2171 * SubqueryScanPath represents a scan of an unflattened subquery-in-FROM
2172 *
2173 * Note that the subpath comes from a different planning domain; for example
2174 * RTE indexes within it mean something different from those known to the
2175 * SubqueryScanPath. path.parent->subroot is the planning context needed to
2176 * interpret the subpath.
2177 */
2178typedef struct SubqueryScanPath
2179{
2180 Path path;
2181 Path *subpath; /* path representing subquery execution */
2183
2184/*
2185 * ForeignPath represents a potential scan of a foreign table, foreign join
2186 * or foreign upper-relation.
2187 *
2188 * In the case of a foreign join, fdw_restrictinfo stores the RestrictInfos to
2189 * apply to the join, which are used by createplan.c to get pseudoconstant
2190 * clauses evaluated as one-time quals in a gating Result plan node.
2191 *
2192 * fdw_private stores FDW private data about the scan. While fdw_private is
2193 * not actually touched by the core code during normal operations, it's
2194 * generally a good idea to use a representation that can be dumped by
2195 * nodeToString(), so that you can examine the structure during debugging
2196 * with tools like pprint().
2197 */
2198typedef struct ForeignPath
2199{
2200 Path path;
2204} ForeignPath;
2205
2206/*
2207 * CustomPath represents a table scan or a table join done by some out-of-core
2208 * extension.
2209 *
2210 * We provide a set of hooks here - which the provider must take care to set
2211 * up correctly - to allow extensions to supply their own methods of scanning
2212 * a relation or join relations. For example, a provider might provide GPU
2213 * acceleration, a cache-based scan, or some other kind of logic we haven't
2214 * dreamed up yet.
2215 *
2216 * CustomPaths can be injected into the planning process for a base or join
2217 * relation by set_rel_pathlist_hook or set_join_pathlist_hook functions,
2218 * respectively.
2219 *
2220 * In the case of a table join, custom_restrictinfo stores the RestrictInfos
2221 * to apply to the join, which are used by createplan.c to get pseudoconstant
2222 * clauses evaluated as one-time quals in a gating Result plan node.
2223 *
2224 * Core code must avoid assuming that the CustomPath is only as large as
2225 * the structure declared here; providers are allowed to make it the first
2226 * element in a larger structure. (Since the planner never copies Paths,
2227 * this doesn't add any complication.) However, for consistency with the
2228 * FDW case, we provide a "custom_private" field in CustomPath; providers
2229 * may prefer to use that rather than define another struct type.
2230 */
2231
2232struct CustomPathMethods;
2233
2234typedef struct CustomPath
2235{
2236 Path path;
2237 uint32 flags; /* mask of CUSTOMPATH_* flags, see
2238 * nodes/extensible.h */
2239 List *custom_paths; /* list of child Path nodes, if any */
2242 const struct CustomPathMethods *methods;
2243} CustomPath;
2244
2245/*
2246 * AppendPath represents an Append plan, ie, successive execution of
2247 * several member plans.
2248 *
2249 * For partial Append, 'subpaths' contains non-partial subpaths followed by
2250 * partial subpaths.
2251 *
2252 * Whenever accumulate_append_subpath() allows us to consolidate multiple
2253 * levels of Append paths down to one, we store the RTI sets for the omitted
2254 * paths in child_append_relid_sets. This is not necessary for planning or
2255 * execution; we do it for the benefit of code that wants to inspect the
2256 * final plan and understand how it came to be.
2257 *
2258 * Note: it is possible for "subpaths" to contain only one, or even no,
2259 * elements. These cases are optimized during create_append_plan.
2260 * In particular, an AppendPath with no subpaths is a "dummy" path that
2261 * is created to represent the case that a relation is provably empty.
2262 * (This is a convenient representation because it means that when we build
2263 * an appendrel and find that all its children have been excluded, no extra
2264 * action is needed to recognize the relation as dummy.)
2265 */
2266typedef struct AppendPath
2267{
2268 Path path;
2269 List *subpaths; /* list of component Paths */
2270 /* Index of first partial path in subpaths; list_length(subpaths) if none */
2272 Cardinality limit_tuples; /* hard limit on output tuples, or -1 */
2274} AppendPath;
2275
2276#define IS_DUMMY_APPEND(p) \
2277 (IsA((p), AppendPath) && ((AppendPath *) (p))->subpaths == NIL)
2278
2279/*
2280 * A relation that's been proven empty will have one path that is dummy
2281 * (but might have projection paths on top). For historical reasons,
2282 * this is provided as a macro that wraps is_dummy_rel().
2283 */
2284#define IS_DUMMY_REL(r) is_dummy_rel(r)
2285extern bool is_dummy_rel(RelOptInfo *rel);
2286
2287/*
2288 * MergeAppendPath represents a MergeAppend plan, ie, the merging of sorted
2289 * results from several member plans to produce similarly-sorted output.
2290 *
2291 * child_append_relid_sets has the same meaning here as for AppendPath.
2292 */
2293typedef struct MergeAppendPath
2294{
2295 Path path;
2296 List *subpaths; /* list of component Paths */
2297 Cardinality limit_tuples; /* hard limit on output tuples, or -1 */
2300
2301/*
2302 * GroupResultPath represents use of a Result plan node to compute the
2303 * output of a degenerate GROUP BY case, wherein we know we should produce
2304 * exactly one row, which might then be filtered by a HAVING qual.
2305 *
2306 * Note that quals is a list of bare clauses, not RestrictInfos.
2307 */
2308typedef struct GroupResultPath
2309{
2310 Path path;
2311 List *quals;
2313
2314/*
2315 * MaterialPath represents use of a Material plan node, i.e., caching of
2316 * the output of its subpath. This is used when the subpath is expensive
2317 * and needs to be scanned repeatedly, or when we need mark/restore ability
2318 * and the subpath doesn't have it.
2319 */
2320typedef struct MaterialPath
2321{
2322 Path path;
2323 Path *subpath;
2324} MaterialPath;
2325
2326/*
2327 * MemoizePath represents a Memoize plan node, i.e., a cache that caches
2328 * tuples from parameterized paths to save the underlying node from having to
2329 * be rescanned for parameter values which are already cached.
2330 */
2331typedef struct MemoizePath
2332{
2333 Path path;
2334 Path *subpath; /* outerpath to cache tuples from */
2335 List *hash_operators; /* OIDs of hash equality ops for cache keys */
2336 List *param_exprs; /* expressions that are cache keys */
2337 bool singlerow; /* true if the cache entry is to be marked as
2338 * complete after caching the first record. */
2339 bool binary_mode; /* true when cache key should be compared bit
2340 * by bit, false when using hash equality ops */
2341 uint32 est_entries; /* The maximum number of entries that the
2342 * planner expects will fit in the cache, or 0
2343 * if unknown */
2344 Cardinality est_calls; /* expected number of rescans */
2345 Cardinality est_unique_keys; /* estimated unique keys, for EXPLAIN */
2346 double est_hit_ratio; /* estimated cache hit ratio, for EXPLAIN */
2347} MemoizePath;
2348
2349/*
2350 * GatherPath runs several copies of a plan in parallel and collects the
2351 * results. The parallel leader may also execute the plan, unless the
2352 * single_copy flag is set.
2353 */
2354typedef struct GatherPath
2355{
2356 Path path;
2357 Path *subpath; /* path for each worker */
2358 bool single_copy; /* don't execute path more than once */
2359 int num_workers; /* number of workers sought to help */
2360} GatherPath;
2361
2362/*
2363 * GatherMergePath runs several copies of a plan in parallel and collects
2364 * the results, preserving their common sort order.
2365 */
2366typedef struct GatherMergePath
2367{
2368 Path path;
2369 Path *subpath; /* path for each worker */
2370 int num_workers; /* number of workers sought to help */
2372
2373
2374/*
2375 * All join-type paths share these fields.
2376 */
2377
2378typedef struct JoinPath
2379{
2380 pg_node_attr(abstract)
2381
2382 Path path;
2383
2385
2386 bool inner_unique; /* each outer tuple provably matches no more
2387 * than one inner tuple */
2388
2389 Path *outerjoinpath; /* path for the outer side of the join */
2390 Path *innerjoinpath; /* path for the inner side of the join */
2391
2392 List *joinrestrictinfo; /* RestrictInfos to apply to join */
2393
2394 /*
2395 * See the notes for RelOptInfo and ParamPathInfo to understand why
2396 * joinrestrictinfo is needed in JoinPath, and can't be merged into the
2397 * parent RelOptInfo.
2398 */
2399} JoinPath;
2400
2401/*
2402 * A nested-loop path needs no special fields.
2403 */
2404
2405typedef struct NestPath
2406{
2407 JoinPath jpath;
2408} NestPath;
2409
2410/*
2411 * A mergejoin path has these fields.
2412 *
2413 * Unlike other path types, a MergePath node doesn't represent just a single
2414 * run-time plan node: it can represent up to four. Aside from the MergeJoin
2415 * node itself, there can be a Sort node for the outer input, a Sort node
2416 * for the inner input, and/or a Material node for the inner input. We could
2417 * represent these nodes by separate path nodes, but considering how many
2418 * different merge paths are investigated during a complex join problem,
2419 * it seems better to avoid unnecessary palloc overhead.
2420 *
2421 * path_mergeclauses lists the clauses (in the form of RestrictInfos)
2422 * that will be used in the merge.
2423 *
2424 * Note that the mergeclauses are a subset of the parent relation's
2425 * restriction-clause list. Any join clauses that are not mergejoinable
2426 * appear only in the parent's restrict list, and must be checked by a
2427 * qpqual at execution time.
2428 *
2429 * outersortkeys (resp. innersortkeys) is NIL if the outer path
2430 * (resp. inner path) is already ordered appropriately for the
2431 * mergejoin. If it is not NIL then it is a PathKeys list describing
2432 * the ordering that must be created by an explicit Sort node.
2433 *
2434 * outer_presorted_keys is the number of presorted keys of the outer
2435 * path that match outersortkeys. It is used to determine whether
2436 * explicit incremental sort can be applied when outersortkeys is not
2437 * NIL. We do not track the number of presorted keys of the inner
2438 * path, as incremental sort currently does not support mark/restore.
2439 *
2440 * skip_mark_restore is true if the executor need not do mark/restore calls.
2441 * Mark/restore overhead is usually required, but can be skipped if we know
2442 * that the executor need find only one match per outer tuple, and that the
2443 * mergeclauses are sufficient to identify a match. In such cases the
2444 * executor can immediately advance the outer relation after processing a
2445 * match, and therefore it need never back up the inner relation.
2446 *
2447 * materialize_inner is true if a Material node should be placed atop the
2448 * inner input. This may appear with or without an inner Sort step.
2449 */
2450
2451typedef struct MergePath
2452{
2453 JoinPath jpath;
2454 List *path_mergeclauses; /* join clauses to be used for merge */
2455 List *outersortkeys; /* keys for explicit sort, if any */
2456 List *innersortkeys; /* keys for explicit sort, if any */
2457 int outer_presorted_keys; /* number of presorted keys of the
2458 * outer path */
2459 bool skip_mark_restore; /* can executor skip mark/restore? */
2460 bool materialize_inner; /* add Materialize to inner? */
2461} MergePath;
2462
2463/*
2464 * A hashjoin path has these fields.
2465 *
2466 * The remarks above for mergeclauses apply for hashclauses as well.
2467 *
2468 * Hashjoin does not care what order its inputs appear in, so we have
2469 * no need for sortkeys.
2470 */
2471
2472typedef struct HashPath
2473{
2474 JoinPath jpath;
2475 List *path_hashclauses; /* join clauses used for hashing */
2476 int num_batches; /* number of batches expected */
2477 Cardinality inner_rows_total; /* total inner rows expected */
2478} HashPath;
2479
2480/*
2481 * ProjectionPath represents a projection (that is, targetlist computation)
2482 *
2483 * Nominally, this path node represents using a Result plan node to do a
2484 * projection step. However, if the input plan node supports projection,
2485 * we can just modify its output targetlist to do the required calculations
2486 * directly, and not need a Result. In some places in the planner we can just
2487 * jam the desired PathTarget into the input path node (and adjust its cost
2488 * accordingly), so we don't need a ProjectionPath. But in other places
2489 * it's necessary to not modify the input path node, so we need a separate
2490 * ProjectionPath node, which is marked dummy to indicate that we intend to
2491 * assign the work to the input plan node. The estimated cost for the
2492 * ProjectionPath node will account for whether a Result will be used or not.
2493 */
2494typedef struct ProjectionPath
2495{
2496 Path path;
2497 Path *subpath; /* path representing input source */
2498 bool dummypp; /* true if no separate Result is needed */
2500
2501/*
2502 * ProjectSetPath represents evaluation of a targetlist that includes
2503 * set-returning function(s), which will need to be implemented by a
2504 * ProjectSet plan node.
2505 */
2506typedef struct ProjectSetPath
2507{
2508 Path path;
2509 Path *subpath; /* path representing input source */
2511
2512/*
2513 * SortPath represents an explicit sort step
2514 *
2515 * The sort keys are, by definition, the same as path.pathkeys.
2516 *
2517 * Note: the Sort plan node cannot project, so path.pathtarget must be the
2518 * same as the input's pathtarget.
2519 */
2520typedef struct SortPath
2521{
2522 Path path;
2523 Path *subpath; /* path representing input source */
2524} SortPath;
2525
2526/*
2527 * IncrementalSortPath represents an incremental sort step
2528 *
2529 * This is like a regular sort, except some leading key columns are assumed
2530 * to be ordered already.
2531 */
2532typedef struct IncrementalSortPath
2533{
2534 SortPath spath;
2535 int nPresortedCols; /* number of presorted columns */
2537
2538/*
2539 * GroupPath represents grouping (of presorted input)
2540 *
2541 * groupClause represents the columns to be grouped on; the input path
2542 * must be at least that well sorted.
2543 *
2544 * We can also apply a qual to the grouped rows (equivalent of HAVING)
2545 */
2546typedef struct GroupPath
2547{
2548 Path path;
2549 Path *subpath; /* path representing input source */
2550 List *groupClause; /* a list of SortGroupClause's */
2551 List *qual; /* quals (HAVING quals), if any */
2552} GroupPath;
2553
2554/*
2555 * UniquePath represents adjacent-duplicate removal (in presorted input)
2556 *
2557 * The columns to be compared are the first numkeys columns of the path's
2558 * pathkeys. The input is presumed already sorted that way.
2559 */
2560typedef struct UniquePath
2561{
2562 Path path;
2563 Path *subpath; /* path representing input source */
2564 int numkeys; /* number of pathkey columns to compare */
2565} UniquePath;
2566
2567/*
2568 * AggPath represents generic computation of aggregate functions
2569 *
2570 * This may involve plain grouping (but not grouping sets), using either
2571 * sorted or hashed grouping; for the AGG_SORTED case, the input must be
2572 * appropriately presorted.
2573 */
2574typedef struct AggPath
2575{
2576 Path path;
2577 Path *subpath; /* path representing input source */
2578 AggStrategy aggstrategy; /* basic strategy, see nodes.h */
2579 AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
2580 Cardinality numGroups; /* estimated number of groups in input */
2581 uint64 transitionSpace; /* for pass-by-ref transition data */
2582 List *groupClause; /* a list of SortGroupClause's */
2583 List *qual; /* quals (HAVING quals), if any */
2584} AggPath;
2585
2586/*
2587 * Various annotations used for grouping sets in the planner.
2588 */
2589
2590typedef struct GroupingSetData
2591{
2593
2594 NodeTag type;
2595 List *set; /* grouping set as list of sortgrouprefs */
2596 Cardinality numGroups; /* est. number of result groups */
2598
2599typedef struct RollupData
2600{
2602
2603 NodeTag type;
2604 List *groupClause; /* applicable subset of parse->groupClause */
2605 List *gsets; /* lists of integer indexes into groupClause */
2606 List *gsets_data; /* list of GroupingSetData */
2607 Cardinality numGroups; /* est. number of result groups */
2608 bool hashable; /* can be hashed */
2609 bool is_hashed; /* to be implemented as a hashagg */
2610} RollupData;
2611
2612/*
2613 * GroupingSetsPath represents a GROUPING SETS aggregation
2614 */
2615
2616typedef struct GroupingSetsPath
2617{
2618 Path path;
2619 Path *subpath; /* path representing input source */
2620 AggStrategy aggstrategy; /* basic strategy */
2621 List *rollups; /* list of RollupData */
2622 List *qual; /* quals (HAVING quals), if any */
2623 uint64 transitionSpace; /* for pass-by-ref transition data */
2625
2626/*
2627 * MinMaxAggPath represents computation of MIN/MAX aggregates from indexes
2628 */
2629typedef struct MinMaxAggPath
2630{
2631 Path path;
2632 List *mmaggregates; /* list of MinMaxAggInfo */
2633 List *quals; /* HAVING quals, if any */
2635
2636/*
2637 * WindowAggPath represents generic computation of window functions
2638 */
2639typedef struct WindowAggPath
2640{
2641 Path path;
2642 Path *subpath; /* path representing input source */
2643 WindowClause *winclause; /* WindowClause we'll be using */
2644 List *qual; /* lower-level WindowAgg runconditions */
2645 List *runCondition; /* OpExpr List to short-circuit execution */
2646 bool topwindow; /* false for all apart from the WindowAgg
2647 * that's closest to the root of the plan */
2649
2650/*
2651 * SetOpPath represents a set-operation, that is INTERSECT or EXCEPT
2652 */
2653typedef struct SetOpPath
2654{
2655 Path path;
2656 Path *leftpath; /* paths representing input sources */
2657 Path *rightpath;
2658 SetOpCmd cmd; /* what to do, see nodes.h */
2659 SetOpStrategy strategy; /* how to do it, see nodes.h */
2660 List *groupList; /* SortGroupClauses identifying target cols */
2661 Cardinality numGroups; /* estimated number of groups in left input */
2662} SetOpPath;
2663
2664/*
2665 * RecursiveUnionPath represents a recursive UNION node
2666 */
2667typedef struct RecursiveUnionPath
2668{
2669 Path path;
2670 Path *leftpath; /* paths representing input sources */
2671 Path *rightpath;
2672 List *distinctList; /* SortGroupClauses identifying target cols */
2673 int wtParam; /* ID of Param representing work table */
2674 Cardinality numGroups; /* estimated number of groups in input */
2676
2677/*
2678 * LockRowsPath represents acquiring row locks for SELECT FOR UPDATE/SHARE
2679 */
2680typedef struct LockRowsPath
2681{
2682 Path path;
2683 Path *subpath; /* path representing input source */
2684 List *rowMarks; /* a list of PlanRowMark's */
2685 int epqParam; /* ID of Param for EvalPlanQual re-eval */
2686} LockRowsPath;
2687
2688/*
2689 * ModifyTablePath represents performing INSERT/UPDATE/DELETE/MERGE
2690 *
2691 * We represent most things that will be in the ModifyTable plan node
2692 * literally, except we have a child Path not Plan. But analysis of the
2693 * OnConflictExpr is deferred to createplan.c, as is collection of FDW data.
2694 */
2695typedef struct ModifyTablePath
2696{
2697 Path path;
2698 Path *subpath; /* Path producing source data */
2699 CmdType operation; /* INSERT, UPDATE, DELETE, or MERGE */
2700 bool canSetTag; /* do we set the command tag/es_processed? */
2701 Index nominalRelation; /* Parent RT index for use of EXPLAIN */
2702 Index rootRelation; /* Root RT index, if partitioned/inherited */
2703 List *resultRelations; /* integer list of RT indexes */
2704 List *updateColnosLists; /* per-target-table update_colnos lists */
2705 List *withCheckOptionLists; /* per-target-table WCO lists */
2706 List *returningLists; /* per-target-table RETURNING tlists */
2707 List *rowMarks; /* PlanRowMarks (non-locking only) */
2708 OnConflictExpr *onconflict; /* ON CONFLICT clause, or NULL */
2709 int epqParam; /* ID of Param for EvalPlanQual re-eval */
2710 List *mergeActionLists; /* per-target-table lists of actions for
2711 * MERGE */
2712 List *mergeJoinConditions; /* per-target-table join conditions
2713 * for MERGE */
2715
2716/*
2717 * LimitPath represents applying LIMIT/OFFSET restrictions
2718 */
2719typedef struct LimitPath
2720{
2721 Path path;
2722 Path *subpath; /* path representing input source */
2723 Node *limitOffset; /* OFFSET parameter, or NULL if none */
2724 Node *limitCount; /* COUNT parameter, or NULL if none */
2725 LimitOption limitOption; /* FETCH FIRST with ties or exact number */
2726} LimitPath;
2727
2728
2729/*
2730 * Restriction clause info.
2731 *
2732 * We create one of these for each AND sub-clause of a restriction condition
2733 * (WHERE or JOIN/ON clause). Since the restriction clauses are logically
2734 * ANDed, we can use any one of them or any subset of them to filter out
2735 * tuples, without having to evaluate the rest. The RestrictInfo node itself
2736 * stores data used by the optimizer while choosing the best query plan.
2737 *
2738 * If a restriction clause references a single base relation, it will appear
2739 * in the baserestrictinfo list of the RelOptInfo for that base rel.
2740 *
2741 * If a restriction clause references more than one base+OJ relation, it will
2742 * appear in the joininfo list of every RelOptInfo that describes a strict
2743 * subset of the relations mentioned in the clause. The joininfo lists are
2744 * used to drive join tree building by selecting plausible join candidates.
2745 * The clause cannot actually be applied until we have built a join rel
2746 * containing all the relations it references, however.
2747 *
2748 * When we construct a join rel that includes all the relations referenced
2749 * in a multi-relation restriction clause, we place that clause into the
2750 * joinrestrictinfo lists of paths for the join rel, if neither left nor
2751 * right sub-path includes all relations referenced in the clause. The clause
2752 * will be applied at that join level, and will not propagate any further up
2753 * the join tree. (Note: the "predicate migration" code was once intended to
2754 * push restriction clauses up and down the plan tree based on evaluation
2755 * costs, but it's dead code and is unlikely to be resurrected in the
2756 * foreseeable future.)
2757 *
2758 * Note that in the presence of more than two rels, a multi-rel restriction
2759 * might reach different heights in the join tree depending on the join
2760 * sequence we use. So, these clauses cannot be associated directly with
2761 * the join RelOptInfo, but must be kept track of on a per-join-path basis.
2762 *
2763 * RestrictInfos that represent equivalence conditions (i.e., mergejoinable
2764 * equalities that are not outerjoin-delayed) are handled a bit differently.
2765 * Initially we attach them to the EquivalenceClasses that are derived from
2766 * them. When we construct a scan or join path, we look through all the
2767 * EquivalenceClasses and generate derived RestrictInfos representing the
2768 * minimal set of conditions that need to be checked for this particular scan
2769 * or join to enforce that all members of each EquivalenceClass are in fact
2770 * equal in all rows emitted by the scan or join.
2771 *
2772 * The clause_relids field lists the base plus outer-join RT indexes that
2773 * actually appear in the clause. required_relids lists the minimum set of
2774 * relids needed to evaluate the clause; while this is often equal to
2775 * clause_relids, it can be more. We will add relids to required_relids when
2776 * we need to force an outer join ON clause to be evaluated exactly at the
2777 * level of the outer join, which is true except when it is a "degenerate"
2778 * condition that references only Vars from the nullable side of the join.
2779 *
2780 * RestrictInfo nodes contain a flag to indicate whether a qual has been
2781 * pushed down to a lower level than its original syntactic placement in the
2782 * join tree would suggest. If an outer join prevents us from pushing a qual
2783 * down to its "natural" semantic level (the level associated with just the
2784 * base rels used in the qual) then we mark the qual with a "required_relids"
2785 * value including more than just the base rels it actually uses. By
2786 * pretending that the qual references all the rels required to form the outer
2787 * join, we prevent it from being evaluated below the outer join's joinrel.
2788 * When we do form the outer join's joinrel, we still need to distinguish
2789 * those quals that are actually in that join's JOIN/ON condition from those
2790 * that appeared elsewhere in the tree and were pushed down to the join rel
2791 * because they used no other rels. That's what the is_pushed_down flag is
2792 * for; it tells us that a qual is not an OUTER JOIN qual for the set of base
2793 * rels listed in required_relids. A clause that originally came from WHERE
2794 * or an INNER JOIN condition will *always* have its is_pushed_down flag set.
2795 * It's possible for an OUTER JOIN clause to be marked is_pushed_down too,
2796 * if we decide that it can be pushed down into the nullable side of the join.
2797 * In that case it acts as a plain filter qual for wherever it gets evaluated.
2798 * (In short, is_pushed_down is only false for non-degenerate outer join
2799 * conditions. Possibly we should rename it to reflect that meaning? But
2800 * see also the comments for RINFO_IS_PUSHED_DOWN, below.)
2801 *
2802 * There is also an incompatible_relids field, which is a set of outer-join
2803 * relids above which we cannot evaluate the clause (because they might null
2804 * Vars it uses that should not be nulled yet). In principle this could be
2805 * filled in any RestrictInfo as the set of OJ relids that appear above the
2806 * clause and null Vars that it uses. In practice we only bother to populate
2807 * it for "clone" clauses, as it's currently only needed to prevent multiple
2808 * clones of the same clause from being accepted for evaluation at the same
2809 * join level.
2810 *
2811 * There is also an outer_relids field, which is NULL except for outer join
2812 * clauses; for those, it is the set of relids on the outer side of the
2813 * clause's outer join. (These are rels that the clause cannot be applied to
2814 * in parameterized scans, since pushing it into the join's outer side would
2815 * lead to wrong answers.)
2816 *
2817 * To handle security-barrier conditions efficiently, we mark RestrictInfo
2818 * nodes with a security_level field, in which higher values identify clauses
2819 * coming from less-trusted sources. The exact semantics are that a clause
2820 * cannot be evaluated before another clause with a lower security_level value
2821 * unless the first clause is leakproof. As with outer-join clauses, this
2822 * creates a reason for clauses to sometimes need to be evaluated higher in
2823 * the join tree than their contents would suggest; and even at a single plan
2824 * node, this rule constrains the order of application of clauses.
2825 *
2826 * In general, the referenced clause might be arbitrarily complex. The
2827 * kinds of clauses we can handle as indexscan quals, mergejoin clauses,
2828 * or hashjoin clauses are limited (e.g., no volatile functions). The code
2829 * for each kind of path is responsible for identifying the restrict clauses
2830 * it can use and ignoring the rest. Clauses not implemented by an indexscan,
2831 * mergejoin, or hashjoin will be placed in the plan qual or joinqual field
2832 * of the finished Plan node, where they will be enforced by general-purpose
2833 * qual-expression-evaluation code. (But we are still entitled to count
2834 * their selectivity when estimating the result tuple count, if we
2835 * can guess what it is...)
2836 *
2837 * When the referenced clause is an OR clause, we generate a modified copy
2838 * in which additional RestrictInfo nodes are inserted below the top-level
2839 * OR/AND structure. This is a convenience for OR indexscan processing:
2840 * indexquals taken from either the top level or an OR subclause will have
2841 * associated RestrictInfo nodes.
2842 *
2843 * The can_join flag is set true if the clause looks potentially useful as
2844 * a merge or hash join clause, that is if it is a binary opclause with
2845 * nonoverlapping sets of relids referenced in the left and right sides.
2846 * (Whether the operator is actually merge or hash joinable isn't checked,
2847 * however.)
2848 *
2849 * The pseudoconstant flag is set true if the clause contains no Vars of
2850 * the current query level and no volatile functions. Such a clause can be
2851 * pulled out and used as a one-time qual in a gating Result node. We keep
2852 * pseudoconstant clauses in the same lists as other RestrictInfos so that
2853 * the regular clause-pushing machinery can assign them to the correct join
2854 * level, but they need to be treated specially for cost and selectivity
2855 * estimates. Note that a pseudoconstant clause can never be an indexqual
2856 * or merge or hash join clause, so it's of no interest to large parts of
2857 * the planner.
2858 *
2859 * When we generate multiple versions of a clause so as to have versions
2860 * that will work after commuting some left joins per outer join identity 3,
2861 * we mark the one with the fewest nullingrels bits with has_clone = true,
2862 * and the rest with is_clone = true. This allows proper filtering of
2863 * these redundant clauses, so that we apply only one version of them.
2864 *
2865 * When join clauses are generated from EquivalenceClasses, there may be
2866 * several equally valid ways to enforce join equivalence, of which we need
2867 * apply only one. We mark clauses of this kind by setting parent_ec to
2868 * point to the generating EquivalenceClass. Multiple clauses with the same
2869 * parent_ec in the same join are redundant.
2870 *
2871 * Most fields are ignored for equality, since they may not be set yet, and
2872 * should be derivable from the clause anyway.
2873 *
2874 * parent_ec, left_ec, right_ec are not printed, lest it lead to infinite
2875 * recursion in plan tree dump.
2876 */
2877
2878typedef struct RestrictInfo
2879{
2881
2882 NodeTag type;
2883
2884 /* the represented clause of WHERE or JOIN */
2885 Expr *clause;
2886
2887 /* true if clause was pushed down in level */
2888 bool is_pushed_down;
2889
2890 /* see comment above */
2892
2893 /* see comment above */
2895
2896 /* see comment above */
2897 bool has_clone;
2898 bool is_clone;
2899
2900 /* true if known to contain no leaked Vars */
2902
2903 /* indicates if clause contains any volatile functions */
2905
2906 /* see comment above */
2907 Index security_level;
2908
2909 /* number of base rels in clause_relids */
2911
2912 /* The relids (varnos+varnullingrels) actually referenced in the clause: */
2914
2915 /* The set of relids required to evaluate the clause: */
2916 Relids required_relids;
2917
2918 /* Relids above which we cannot evaluate the clause (see comment above) */
2919 Relids incompatible_relids;
2920
2921 /* If an outer-join clause, the outer-side relations, else NULL: */
2922 Relids outer_relids;
2923
2924 /*
2925 * Relids in the left/right side of the clause. These fields are set for
2926 * any binary opclause.
2927 */
2930
2931 /*
2932 * Modified clause with RestrictInfos. This field is NULL unless clause
2933 * is an OR clause.
2934 */
2936
2937 /*----------
2938 * Serial number of this RestrictInfo. This is unique within the current
2939 * PlannerInfo context, with a few critical exceptions:
2940 * 1. When we generate multiple clones of the same qual condition to
2941 * cope with outer join identity 3, all the clones get the same serial
2942 * number. This reflects that we only want to apply one of them in any
2943 * given plan.
2944 * 2. If we manufacture a commuted version of a qual to use as an index
2945 * condition, it copies the original's rinfo_serial, since it is in
2946 * practice the same condition.
2947 * 3. If we reduce a qual to constant-FALSE, the new constant-FALSE qual
2948 * copies the original's rinfo_serial, since it is in practice the same
2949 * condition.
2950 * 4. RestrictInfos made for a child relation copy their parent's
2951 * rinfo_serial. Likewise, when an EquivalenceClass makes a derived
2952 * equality clause for a child relation, it copies the rinfo_serial of
2953 * the matching equality clause for the parent. This allows detection
2954 * of redundant pushed-down equality clauses.
2955 *----------
2956 */
2957 int rinfo_serial;
2958
2959 /*
2960 * Generating EquivalenceClass. This field is NULL unless clause is
2961 * potentially redundant.
2962 */
2964
2965 /*
2966 * cache space for cost and selectivity
2967 */
2968
2969 /* eval cost of clause; -1 if not yet set */
2971
2972 /* selectivity for "normal" (JOIN_INNER) semantics; -1 if not yet set */
2974 /* selectivity for outer join semantics; -1 if not yet set */
2976
2977 /*
2978 * opfamilies containing clause operator; valid if clause is
2979 * mergejoinable, else NIL
2980 */
2982
2983 /*
2984 * cache space for mergeclause processing; NULL if not yet set
2985 */
2986
2987 /* EquivalenceClass containing lefthand */
2989 /* EquivalenceClass containing righthand */
2991 /* EquivalenceMember for lefthand */
2993 /* EquivalenceMember for righthand */
2995
2996 /*
2997 * List of MergeScanSelCache structs. Those aren't Nodes, so hard to
2998 * copy; instead replace with NIL. That has the effect that copying will
2999 * just reset the cache. Likewise, can't compare or print them.
3000 */
3002
3003 /*
3004 * transient workspace for use while considering a specific join path; T =
3005 * outer var on left, F = on right
3006 */
3008
3009 /*
3010 * copy of clause operator; valid if clause is hashjoinable, else
3011 * InvalidOid
3012 */
3014
3015 /*
3016 * cache space for hashclause processing; -1 if not yet set
3017 */
3018 /* avg bucketsize of left side */
3020 /* avg bucketsize of right side */
3022 /* left side's most common val's freq */
3024 /* right side's most common val's freq */
3026
3027 /* hash equality operators used for memoize nodes, else InvalidOid */
3030} RestrictInfo;
3031
3032/*
3033 * This macro embodies the correct way to test whether a RestrictInfo is
3034 * "pushed down" to a given outer join, that is, should be treated as a filter
3035 * clause rather than a join clause at that outer join. This is certainly so
3036 * if is_pushed_down is true; but examining that is not sufficient anymore,
3037 * because outer-join clauses will get pushed down to lower outer joins when
3038 * we generate a path for the lower outer join that is parameterized by the
3039 * LHS of the upper one. We can detect such a clause by noting that its
3040 * required_relids exceed the scope of the join.
3041 */
3042#define RINFO_IS_PUSHED_DOWN(rinfo, joinrelids) \
3043 ((rinfo)->is_pushed_down || \
3044 !bms_is_subset((rinfo)->required_relids, joinrelids))
3045
3046/*
3047 * Since mergejoinscansel() is a relatively expensive function, and would
3048 * otherwise be invoked many times while planning a large join tree,
3049 * we go out of our way to cache its results. Each mergejoinable
3050 * RestrictInfo carries a list of the specific sort orderings that have
3051 * been considered for use with it, and the resulting selectivities.
3052 */
3053typedef struct MergeScanSelCache
3054{
3055 /* Ordering details (cache lookup key) */
3056 Oid opfamily; /* index opfamily defining the ordering */
3057 Oid collation; /* collation for the ordering */
3058 CompareType cmptype; /* sort direction (ASC or DESC) */
3059 bool nulls_first; /* do NULLs come before normal values? */
3060 /* Results */
3061 Selectivity leftstartsel; /* first-join fraction for clause left side */
3062 Selectivity leftendsel; /* last-join fraction for clause left side */
3063 Selectivity rightstartsel; /* first-join fraction for clause right side */
3064 Selectivity rightendsel; /* last-join fraction for clause right side */
3066
3067/*
3068 * Placeholder node for an expression to be evaluated below the top level
3069 * of a plan tree. This is used during planning to represent the contained
3070 * expression. At the end of the planning process it is replaced by either
3071 * the contained expression or a Var referring to a lower-level evaluation of
3072 * the contained expression. Generally the evaluation occurs below an outer
3073 * join, and Var references above the outer join might thereby yield NULL
3074 * instead of the expression value.
3075 *
3076 * phrels and phlevelsup correspond to the varno/varlevelsup fields of a
3077 * plain Var, except that phrels has to be a relid set since the evaluation
3078 * level of a PlaceHolderVar might be a join rather than a base relation.
3079 * Likewise, phnullingrels corresponds to varnullingrels.
3080 *
3081 * Although the planner treats this as an expression node type, it is not
3082 * recognized by the parser or executor, so we declare it here rather than
3083 * in primnodes.h.
3084 *
3085 * We intentionally do not compare phexpr. Two PlaceHolderVars with the
3086 * same ID and levelsup should be considered equal even if the contained
3087 * expressions have managed to mutate to different states. This will
3088 * happen during final plan construction when there are nested PHVs, since
3089 * the inner PHV will get replaced by a Param in some copies of the outer
3090 * PHV. Another way in which it can happen is that initplan sublinks
3091 * could get replaced by differently-numbered Params when sublink folding
3092 * is done. (The end result of such a situation would be some
3093 * unreferenced initplans, which is annoying but not really a problem.)
3094 * On the same reasoning, there is no need to examine phrels. But we do
3095 * need to compare phnullingrels, as that represents effects that are
3096 * external to the original value of the PHV.
3097 */
3098
3099typedef struct PlaceHolderVar
3100{
3102
3103 Expr xpr;
3104
3105 /* the represented expression */
3107
3108 /* base+OJ relids syntactically within expr src */
3110
3111 /* RT indexes of outer joins that can null PHV's value */
3112 Relids phnullingrels;
3113
3114 /* ID for PHV (unique within planner run) */
3115 Index phid;
3116
3117 /* > 0 if PHV belongs to outer query */
3118 Index phlevelsup;
3120
3121/*
3122 * "Special join" info.
3123 *
3124 * One-sided outer joins constrain the order of joining partially but not
3125 * completely. We flatten such joins into the planner's top-level list of
3126 * relations to join, but record information about each outer join in a
3127 * SpecialJoinInfo struct. These structs are kept in the PlannerInfo node's
3128 * join_info_list.
3129 *
3130 * Similarly, semijoins and antijoins created by flattening IN (subselect)
3131 * and EXISTS(subselect) clauses create partial constraints on join order.
3132 * These are likewise recorded in SpecialJoinInfo structs.
3133 *
3134 * We make SpecialJoinInfos for FULL JOINs even though there is no flexibility
3135 * of planning for them, because this simplifies make_join_rel()'s API.
3136 *
3137 * min_lefthand and min_righthand are the sets of base+OJ relids that must be
3138 * available on each side when performing the special join.
3139 * It is not valid for either min_lefthand or min_righthand to be empty sets;
3140 * if they were, this would break the logic that enforces join order.
3141 *
3142 * syn_lefthand and syn_righthand are the sets of base+OJ relids that are
3143 * syntactically below this special join. (These are needed to help compute
3144 * min_lefthand and min_righthand for higher joins.)
3145 *
3146 * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching
3147 * the inputs to make it a LEFT JOIN. It's never JOIN_RIGHT_SEMI or
3148 * JOIN_RIGHT_ANTI either. So the allowed values of jointype in a
3149 * join_info_list member are only LEFT, FULL, SEMI, or ANTI.
3150 *
3151 * ojrelid is the RT index of the join RTE representing this outer join,
3152 * if there is one. It is zero when jointype is INNER or SEMI, and can be
3153 * zero for jointype ANTI (if the join was transformed from a SEMI join).
3154 * One use for this field is that when constructing the output targetlist of a
3155 * join relation that implements this OJ, we add ojrelid to the varnullingrels
3156 * and phnullingrels fields of nullable (RHS) output columns, so that the
3157 * output Vars and PlaceHolderVars correctly reflect the nulling that has
3158 * potentially happened to them.
3159 *
3160 * commute_above_l is filled with the relids of syntactically-higher outer
3161 * joins that have been found to commute with this one per outer join identity
3162 * 3 (see optimizer/README), when this join is in the LHS of the upper join
3163 * (so, this is the lower join in the first form of the identity).
3164 *
3165 * commute_above_r is filled with the relids of syntactically-higher outer
3166 * joins that have been found to commute with this one per outer join identity
3167 * 3, when this join is in the RHS of the upper join (so, this is the lower
3168 * join in the second form of the identity).
3169 *
3170 * commute_below_l is filled with the relids of syntactically-lower outer
3171 * joins that have been found to commute with this one per outer join identity
3172 * 3 and are in the LHS of this join (so, this is the upper join in the first
3173 * form of the identity).
3174 *
3175 * commute_below_r is filled with the relids of syntactically-lower outer
3176 * joins that have been found to commute with this one per outer join identity
3177 * 3 and are in the RHS of this join (so, this is the upper join in the second
3178 * form of the identity).
3179 *
3180 * lhs_strict is true if the special join's condition cannot succeed when the
3181 * LHS variables are all NULL (this means that an outer join can commute with
3182 * upper-level outer joins even if it appears in their RHS). We don't bother
3183 * to set lhs_strict for FULL JOINs, however.
3184 *
3185 * For a semijoin, we also extract the join operators and their RHS arguments
3186 * and set semi_operators, semi_rhs_exprs, semi_can_btree, and semi_can_hash.
3187 * This is done in support of possibly unique-ifying the RHS, so we don't
3188 * bother unless at least one of semi_can_btree and semi_can_hash can be set
3189 * true. (You might expect that this information would be computed during
3190 * join planning; but it's helpful to have it available during planning of
3191 * parameterized table scans, so we store it in the SpecialJoinInfo structs.)
3192 *
3193 * For purposes of join selectivity estimation, we create transient
3194 * SpecialJoinInfo structures for regular inner joins; so it is possible
3195 * to have jointype == JOIN_INNER in such a structure, even though this is
3196 * not allowed within join_info_list. We also create transient
3197 * SpecialJoinInfos with jointype == JOIN_INNER for outer joins, since for
3198 * cost estimation purposes it is sometimes useful to know the join size under
3199 * plain innerjoin semantics. Note that lhs_strict and the semi_xxx fields
3200 * are not set meaningfully within such structs.
3201 *
3202 * We also create transient SpecialJoinInfos for child joins during
3203 * partitionwise join planning, which are also not present in join_info_list.
3204 */
3205typedef struct SpecialJoinInfo
3206{
3208
3209 NodeTag type;
3210 Relids min_lefthand; /* base+OJ relids in minimum LHS for join */
3211 Relids min_righthand; /* base+OJ relids in minimum RHS for join */
3212 Relids syn_lefthand; /* base+OJ relids syntactically within LHS */
3213 Relids syn_righthand; /* base+OJ relids syntactically within RHS */
3214 JoinType jointype; /* always INNER, LEFT, FULL, SEMI, or ANTI */
3215 Index ojrelid; /* outer join's RT index; 0 if none */
3216 Relids commute_above_l; /* commuting OJs above this one, if LHS */
3217 Relids commute_above_r; /* commuting OJs above this one, if RHS */
3218 Relids commute_below_l; /* commuting OJs in this one's LHS */
3219 Relids commute_below_r; /* commuting OJs in this one's RHS */
3220 bool lhs_strict; /* joinclause is strict for some LHS rel */
3221 /* Remaining fields are set only for JOIN_SEMI jointype: */
3222 bool semi_can_btree; /* true if semi_operators are all btree */
3223 bool semi_can_hash; /* true if semi_operators are all hash */
3224 List *semi_operators; /* OIDs of equality join operators */
3225 List *semi_rhs_exprs; /* righthand-side expressions of these ops */
3227
3228/*
3229 * Transient outer-join clause info.
3230 *
3231 * We set aside every outer join ON clause that looks mergejoinable,
3232 * and process it specially at the end of qual distribution.
3233 */
3234typedef struct OuterJoinClauseInfo
3235{
3237
3238 NodeTag type;
3239 RestrictInfo *rinfo; /* a mergejoinable outer-join clause */
3240 SpecialJoinInfo *sjinfo; /* the outer join's SpecialJoinInfo */
3242
3243/*
3244 * Append-relation info.
3245 *
3246 * When we expand an inheritable table or a UNION-ALL subselect into an
3247 * "append relation" (essentially, a list of child RTEs), we build an
3248 * AppendRelInfo for each child RTE. The list of AppendRelInfos indicates
3249 * which child RTEs must be included when expanding the parent, and each node
3250 * carries information needed to translate between columns of the parent and
3251 * columns of the child.
3252 *
3253 * These structs are kept in the PlannerInfo node's append_rel_list, with
3254 * append_rel_array[] providing a convenient lookup method for the struct
3255 * associated with a particular child relid (there can be only one, though
3256 * parent rels may have many entries in append_rel_list).
3257 *
3258 * Note: after completion of the planner prep phase, any given RTE is an
3259 * append parent having entries in append_rel_list if and only if its
3260 * "inh" flag is set. We clear "inh" for plain tables that turn out not
3261 * to have inheritance children, and (in an abuse of the original meaning
3262 * of the flag) we set "inh" for subquery RTEs that turn out to be
3263 * flattenable UNION ALL queries. This lets us avoid useless searches
3264 * of append_rel_list.
3265 *
3266 * Note: the data structure assumes that append-rel members are single
3267 * baserels. This is OK for inheritance, but it prevents us from pulling
3268 * up a UNION ALL member subquery if it contains a join. While that could
3269 * be fixed with a more complex data structure, at present there's not much
3270 * point because no improvement in the plan could result.
3271 */
3272
3273typedef struct AppendRelInfo
3274{
3276
3277 NodeTag type;
3278
3279 /*
3280 * These fields uniquely identify this append relationship. There can be
3281 * (in fact, always should be) multiple AppendRelInfos for the same
3282 * parent_relid, but never more than one per child_relid, since a given
3283 * RTE cannot be a child of more than one append parent.
3284 */
3285 Index parent_relid; /* RT index of append parent rel */
3286 Index child_relid; /* RT index of append child rel */
3287
3288 /*
3289 * For an inheritance appendrel, the parent and child are both regular
3290 * relations, and we store their rowtype OIDs here for use in translating
3291 * whole-row Vars. For a UNION-ALL appendrel, the parent and child are
3292 * both subqueries with no named rowtype, and we store InvalidOid here.
3293 */
3294 Oid parent_reltype; /* OID of parent's composite type */
3295 Oid child_reltype; /* OID of child's composite type */
3296
3297 /*
3298 * The N'th element of this list is a Var or expression representing the
3299 * child column corresponding to the N'th column of the parent. This is
3300 * used to translate Vars referencing the parent rel into references to
3301 * the child. A list element is NULL if it corresponds to a dropped
3302 * column of the parent (this is only possible for inheritance cases, not
3303 * UNION ALL). The list elements are always simple Vars for inheritance
3304 * cases, but can be arbitrary expressions in UNION ALL cases.
3305 *
3306 * Notice we only store entries for user columns (attno > 0). Whole-row
3307 * Vars are special-cased, and system columns (attno < 0) need no special
3308 * translation since their attnos are the same for all tables.
3309 *
3310 * Caution: the Vars have varlevelsup = 0. Be careful to adjust as needed
3311 * when copying into a subquery.
3312 */
3313 List *translated_vars; /* Expressions in the child's Vars */
3314
3315 /*
3316 * This array simplifies translations in the reverse direction, from
3317 * child's column numbers to parent's. The entry at [ccolno - 1] is the
3318 * 1-based parent column number for child column ccolno, or zero if that
3319 * child column is dropped or doesn't exist in the parent.
3320 */
3321 int num_child_cols; /* length of array */
3323
3324 /*
3325 * We store the parent table's OID here for inheritance, or InvalidOid for
3326 * UNION ALL. This is only needed to help in generating error messages if
3327 * an attempt is made to reference a dropped parent column.
3328 */
3329 Oid parent_reloid; /* OID of parent relation */
3331
3332/*
3333 * Information about a row-identity "resjunk" column in UPDATE/DELETE/MERGE.
3334 *
3335 * In partitioned UPDATE/DELETE/MERGE it's important for child partitions to
3336 * share row-identity columns whenever possible, so as not to chew up too many
3337 * targetlist columns. We use these structs to track which identity columns
3338 * have been requested. In the finished plan, each of these will give rise
3339 * to one resjunk entry in the targetlist of the ModifyTable's subplan node.
3340 *
3341 * All the Vars stored in RowIdentityVarInfos must have varno ROWID_VAR, for
3342 * convenience of detecting duplicate requests. We'll replace that, in the
3343 * final plan, with the varno of the generating rel.
3344 *
3345 * Outside this list, a Var with varno ROWID_VAR and varattno k is a reference
3346 * to the k-th element of the row_identity_vars list (k counting from 1).
3347 * We add such a reference to root->processed_tlist when creating the entry,
3348 * and it propagates into the plan tree from there.
3349 */
3350typedef struct RowIdentityVarInfo
3351{
3353
3354 NodeTag type;
3355
3356 Var *rowidvar; /* Var to be evaluated (but varno=ROWID_VAR) */
3357 int32 rowidwidth; /* estimated average width */
3358 char *rowidname; /* name of the resjunk column */
3359 Relids rowidrels; /* RTE indexes of target rels using this */
3361
3362/*
3363 * For each distinct placeholder expression generated during planning, we
3364 * store a PlaceHolderInfo node in the PlannerInfo node's placeholder_list.
3365 * This stores info that is needed centrally rather than in each copy of the
3366 * PlaceHolderVar. The phid fields identify which PlaceHolderInfo goes with
3367 * each PlaceHolderVar. Note that phid is unique throughout a planner run,
3368 * not just within a query level --- this is so that we need not reassign ID's
3369 * when pulling a subquery into its parent.
3370 *
3371 * The idea is to evaluate the expression at (only) the ph_eval_at join level,
3372 * then allow it to bubble up like a Var until the ph_needed join level.
3373 * ph_needed has the same definition as attr_needed for a regular Var.
3374 *
3375 * The PlaceHolderVar's expression might contain LATERAL references to vars
3376 * coming from outside its syntactic scope. If so, those rels are *not*
3377 * included in ph_eval_at, but they are recorded in ph_lateral.
3378 *
3379 * Notice that when ph_eval_at is a join rather than a single baserel, the
3380 * PlaceHolderInfo may create constraints on join order: the ph_eval_at join
3381 * has to be formed below any outer joins that should null the PlaceHolderVar.
3382 *
3383 * We create a PlaceHolderInfo only after determining that the PlaceHolderVar
3384 * is actually referenced in the plan tree, so that unreferenced placeholders
3385 * don't result in unnecessary constraints on join order.
3386 */
3387
3388typedef struct PlaceHolderInfo
3389{
3391
3392 NodeTag type;
3393
3394 /* ID for PH (unique within planner run) */
3395 Index phid;
3396
3397 /*
3398 * copy of PlaceHolderVar tree (should be redundant for comparison, could
3399 * be ignored)
3400 */
3401 PlaceHolderVar *ph_var;
3402
3403 /* lowest level we can evaluate value at */
3404 Relids ph_eval_at;
3405
3406 /* relids of contained lateral refs, if any */
3407 Relids ph_lateral;
3408
3409 /* highest level the value is needed at */
3410 Relids ph_needed;
3411
3412 /* estimated attribute width */
3413 int32 ph_width;
3415
3416/*
3417 * This struct describes one potentially index-optimizable MIN/MAX aggregate
3418 * function. MinMaxAggPath contains a list of these, and if we accept that
3419 * path, the list is stored into root->minmax_aggs for use during setrefs.c.
3420 */
3421typedef struct MinMaxAggInfo
3422{
3424
3425 NodeTag type;
3426
3427 /* pg_proc Oid of the aggregate */
3428 Oid aggfnoid;
3429
3430 /* Oid of its sort operator */
3431 Oid aggsortop;
3432
3433 /* expression we are aggregating on */
3434 Expr *target;
3435
3436 /*
3437 * modified "root" for planning the subquery; not printed, too large, not
3438 * interesting enough
3439 */
3441
3442 /* access path for subquery */
3443 Path *path;
3444
3445 /* estimated cost to fetch first row */
3446 Cost pathcost;
3447
3448 /* param for subplan's output */
3449 Param *param;
3451
3452/*
3453 * For each distinct Aggref node that appears in the targetlist and HAVING
3454 * clauses, we store an AggClauseInfo node in the PlannerInfo node's
3455 * agg_clause_list. Each AggClauseInfo records the set of relations referenced
3456 * by the aggregate expression. This information is used to determine how far
3457 * the aggregate can be safely pushed down in the join tree.
3458 */
3459typedef struct AggClauseInfo
3460{
3462
3463 NodeTag type;
3464
3465 /* the Aggref expr */
3466 Aggref *aggref;
3467
3468 /* lowest level we can evaluate this aggregate at */
3469 Relids agg_eval_at;
3471
3472/*
3473 * For each grouping expression that appears in grouping clauses, we store a
3474 * GroupingExprInfo node in the PlannerInfo node's group_expr_list. Each
3475 * GroupingExprInfo records the expression being grouped on, its sortgroupref,
3476 * and the EquivalenceClass it belongs to. This information is necessary to
3477 * reproduce correct grouping semantics at different levels of the join tree.
3478 */
3479typedef struct GroupingExprInfo
3480{
3482
3483 NodeTag type;
3484
3485 /* the represented expression */
3486 Expr *expr;
3487
3488 /* the tleSortGroupRef of the corresponding SortGroupClause */
3489 Index sortgroupref;
3490
3491 /* the equivalence class the expression belongs to */
3494
3495/*
3496 * At runtime, PARAM_EXEC slots are used to pass values around from one plan
3497 * node to another. They can be used to pass values down into subqueries (for
3498 * outer references in subqueries), or up out of subqueries (for the results
3499 * of a subplan), or from a NestLoop plan node into its inner relation (when
3500 * the inner scan is parameterized with values from the outer relation).
3501 * The planner is responsible for assigning nonconflicting PARAM_EXEC IDs to
3502 * the PARAM_EXEC Params it generates.
3503 *
3504 * Outer references are managed via root->plan_params, which is a list of
3505 * PlannerParamItems. While planning a subquery, each parent query level's
3506 * plan_params contains the values required from it by the current subquery.
3507 * During create_plan(), we use plan_params to track values that must be
3508 * passed from outer to inner sides of NestLoop plan nodes.
3509 *
3510 * The item a PlannerParamItem represents can be one of three kinds:
3511 *
3512 * A Var: the slot represents a variable of this level that must be passed
3513 * down because subqueries have outer references to it, or must be passed
3514 * from a NestLoop node to its inner scan. The varlevelsup value in the Var
3515 * will always be zero.
3516 *
3517 * A PlaceHolderVar: this works much like the Var case, except that the
3518 * entry is a PlaceHolderVar node with a contained expression. The PHV
3519 * will have phlevelsup = 0, and the contained expression is adjusted
3520 * to match in level.
3521 *
3522 * An Aggref (with an expression tree representing its argument): the slot
3523 * represents an aggregate expression that is an outer reference for some
3524 * subquery. The Aggref itself has agglevelsup = 0, and its argument tree
3525 * is adjusted to match in level.
3526 *
3527 * Note: we detect duplicate Var and PlaceHolderVar parameters and coalesce
3528 * them into one slot, but we do not bother to do that for Aggrefs.
3529 * The scope of duplicate-elimination only extends across the set of
3530 * parameters passed from one query level into a single subquery, or for
3531 * nestloop parameters across the set of nestloop parameters used in a single
3532 * query level. So there is no possibility of a PARAM_EXEC slot being used
3533 * for conflicting purposes.
3534 *
3535 * In addition, PARAM_EXEC slots are assigned for Params representing outputs
3536 * from subplans (values that are setParam items for those subplans). These
3537 * IDs need not be tracked via PlannerParamItems, since we do not need any
3538 * duplicate-elimination nor later processing of the represented expressions.
3539 * Instead, we just record the assignment of the slot number by appending to
3540 * root->glob->paramExecTypes.
3541 */
3542typedef struct PlannerParamItem
3543{
3545
3546 NodeTag type;
3547
3548 Node *item; /* the Var, PlaceHolderVar, or Aggref */
3549 int paramId; /* its assigned PARAM_EXEC slot number */
3551
3552/*
3553 * When making cost estimates for a SEMI/ANTI/inner_unique join, there are
3554 * some correction factors that are needed in both nestloop and hash joins
3555 * to account for the fact that the executor can stop scanning inner rows
3556 * as soon as it finds a match to the current outer row. These numbers
3557 * depend only on the selected outer and inner join relations, not on the
3558 * particular paths used for them, so it's worthwhile to calculate them
3559 * just once per relation pair not once per considered path. This struct
3560 * is filled by compute_semi_anti_join_factors and must be passed along
3561 * to the join cost estimation functions.
3562 *
3563 * outer_match_frac is the fraction of the outer tuples that are
3564 * expected to have at least one match.
3565 * match_count is the average number of matches expected for
3566 * outer tuples that have at least one match.
3567 */
3568typedef struct SemiAntiJoinFactors
3569{
3570 Selectivity outer_match_frac;
3571 Selectivity match_count;
3573
3574/*
3575 * Struct for extra information passed to subroutines of add_paths_to_joinrel
3576 *
3577 * restrictlist contains all of the RestrictInfo nodes for restriction
3578 * clauses that apply to this join
3579 * mergeclause_list is a list of RestrictInfo nodes for available
3580 * mergejoin clauses in this join
3581 * inner_unique is true if each outer tuple provably matches no more
3582 * than one inner tuple
3583 * sjinfo is extra info about special joins for selectivity estimation
3584 * semifactors is as shown above (only valid for SEMI/ANTI/inner_unique joins)
3585 * param_source_rels are OK targets for parameterization of result paths
3586 * pgs_mask is a bitmask of PGS_* constants to limit the join strategy
3587 */
3588typedef struct JoinPathExtraData
3589{
3590 List *restrictlist;
3591 List *mergeclause_list;
3592 bool inner_unique;
3593 SpecialJoinInfo *sjinfo;
3594 SemiAntiJoinFactors semifactors;
3595 Relids param_source_rels;
3596 uint64 pgs_mask;
3598
3599/*
3600 * Various flags indicating what kinds of grouping are possible.
3601 *
3602 * GROUPING_CAN_USE_SORT should be set if it's possible to perform
3603 * sort-based implementations of grouping. When grouping sets are in use,
3604 * this will be true if sorting is potentially usable for any of the grouping
3605 * sets, even if it's not usable for all of them.
3606 *
3607 * GROUPING_CAN_USE_HASH should be set if it's possible to perform
3608 * hash-based implementations of grouping.
3609 *
3610 * GROUPING_CAN_PARTIAL_AGG should be set if the aggregation is of a type
3611 * for which we support partial aggregation (not, for example, grouping sets).
3612 * It says nothing about parallel-safety or the availability of suitable paths.
3613 */
3614#define GROUPING_CAN_USE_SORT 0x0001
3615#define GROUPING_CAN_USE_HASH 0x0002
3616#define GROUPING_CAN_PARTIAL_AGG 0x0004
3617
3618/*
3619 * What kind of partitionwise aggregation is in use?
3620 *
3621 * PARTITIONWISE_AGGREGATE_NONE: Not used.
3622 *
3623 * PARTITIONWISE_AGGREGATE_FULL: Aggregate each partition separately, and
3624 * append the results.
3625 *
3626 * PARTITIONWISE_AGGREGATE_PARTIAL: Partially aggregate each partition
3627 * separately, append the results, and then finalize aggregation.
3628 */
3629typedef enum
3630{
3635
3636/*
3637 * Struct for extra information passed to subroutines of create_grouping_paths
3638 *
3639 * flags indicating what kinds of grouping are possible.
3640 * partial_costs_set is true if the agg_partial_costs and agg_final_costs
3641 * have been initialized.
3642 * agg_partial_costs gives partial aggregation costs.
3643 * agg_final_costs gives finalization costs.
3644 * target_parallel_safe is true if target is parallel safe.
3645 * havingQual gives list of quals to be applied after aggregation.
3646 * targetList gives list of columns to be projected.
3647 * patype is the type of partitionwise aggregation that is being performed.
3648 */
3649typedef struct
3650{
3651 /* Data which remains constant once set. */
3652 int flags;
3653 bool partial_costs_set;
3654 AggClauseCosts agg_partial_costs;
3655 AggClauseCosts agg_final_costs;
3656
3657 /* Data which may differ across partitions. */
3658 bool target_parallel_safe;
3659 Node *havingQual;
3660 List *targetList;
3663
3664/*
3665 * Struct for extra information passed to subroutines of grouping_planner
3666 *
3667 * limit_needed is true if we actually need a Limit plan node.
3668 * limit_tuples is an estimated bound on the number of output tuples,
3669 * or -1 if no LIMIT or couldn't estimate.
3670 * count_est and offset_est are the estimated values of the LIMIT and OFFSET
3671 * expressions computed by preprocess_limit() (see comments for
3672 * preprocess_limit() for more information).
3673 */
3674typedef struct
3675{
3676 bool limit_needed;
3677 Cardinality limit_tuples;
3678 int64 count_est;
3679 int64 offset_est;
3681
3682/*
3683 * For speed reasons, cost estimation for join paths is performed in two
3684 * phases: the first phase tries to quickly derive a lower bound for the
3685 * join cost, and then we check if that's sufficient to reject the path.
3686 * If not, we come back for a more refined cost estimate. The first phase
3687 * fills a JoinCostWorkspace struct with its preliminary cost estimates
3688 * and possibly additional intermediate values. The second phase takes
3689 * these values as inputs to avoid repeating work.
3690 *
3691 * (Ideally we'd declare this in cost.h, but it's also needed in pathnode.h,
3692 * so seems best to put it here.)
3693 */
3694typedef struct JoinCostWorkspace
3695{
3696 /* Preliminary cost estimates --- must not be larger than final ones! */
3697 int disabled_nodes;
3698 Cost startup_cost; /* cost expended before fetching any tuples */
3699 Cost total_cost; /* total cost (assuming all tuples fetched) */
3700
3701 /* Fields below here should be treated as private to costsize.c */
3702 Cost run_cost; /* non-startup cost components */
3703
3704 /* private for cost_nestloop code */
3705 Cost inner_run_cost; /* also used by cost_mergejoin code */
3706 Cost inner_rescan_run_cost;
3707
3708 /* private for cost_mergejoin code */
3709 Cardinality outer_rows;
3710 Cardinality inner_rows;
3711 Cardinality outer_skip_rows;
3712 Cardinality inner_skip_rows;
3713
3714 /* private for cost_hashjoin code */
3715 int numbuckets;
3716 int numbatches;
3717 Cardinality inner_rows_total;
3719
3720/*
3721 * AggInfo holds information about an aggregate that needs to be computed.
3722 * Multiple Aggrefs in a query can refer to the same AggInfo by having the
3723 * same 'aggno' value, so that the aggregate is computed only once.
3724 */
3725typedef struct AggInfo
3726{
3728
3729 NodeTag type;
3730
3731 /*
3732 * List of Aggref exprs that this state value is for.
3733 *
3734 * There will always be at least one, but there can be multiple identical
3735 * Aggref's sharing the same per-agg.
3736 */
3737 List *aggrefs;
3738
3739 /* Transition state number for this aggregate */
3740 int transno;
3741
3742 /*
3743 * "shareable" is false if this agg cannot share state values with other
3744 * aggregates because the final function is read-write.
3745 */
3746 bool shareable;
3747
3748 /* Oid of the final function, or InvalidOid if none */
3749 Oid finalfn_oid;
3750} AggInfo;
3751
3752/*
3753 * AggTransInfo holds information about transition state that is used by one
3754 * or more aggregates in the query. Multiple aggregates can share the same
3755 * transition state, if they have the same inputs and the same transition
3756 * function. Aggrefs that share the same transition info have the same
3757 * 'aggtransno' value.
3758 */
3759typedef struct AggTransInfo
3760{
3762
3763 NodeTag type;
3764
3765 /* Inputs for this transition state */
3766 List *args;
3767 Expr *aggfilter;
3768
3769 /* Oid of the state transition function */
3770 Oid transfn_oid;
3771
3772 /* Oid of the serialization function, or InvalidOid if none */
3773 Oid serialfn_oid;
3774
3775 /* Oid of the deserialization function, or InvalidOid if none */
3776 Oid deserialfn_oid;
3777
3778 /* Oid of the combine function, or InvalidOid if none */
3779 Oid combinefn_oid;
3780
3781 /* Oid of state value's datatype */
3782 Oid aggtranstype;
3783
3784 /* Additional data about transtype */
3785 int32 aggtranstypmod;
3786 int transtypeLen;
3787 bool transtypeByVal;
3788
3789 /* Space-consumption estimate */
3790 int32 aggtransspace;
3791
3792 /* Initial value from pg_aggregate entry */
3794 bool initValueIsNull;
3795} AggTransInfo;
3796
3797/*
3798 * UniqueRelInfo caches a fact that a relation is unique when being joined
3799 * to other relation(s).
3800 */
3801typedef struct UniqueRelInfo
3802{
3804
3805 NodeTag type;
3806
3807 /*
3808 * The relation in consideration is unique when being joined with this set
3809 * of other relation(s).
3810 */
3811 Relids outerrelids;
3812
3813 /*
3814 * The relation in consideration is unique when considering only clauses
3815 * suitable for self-join (passed split_selfjoin_quals()).
3816 */
3817 bool self_join;
3818
3819 /*
3820 * Additional clauses from a baserestrictinfo list that were used to prove
3821 * the uniqueness. We cache it for the self-join checking procedure: a
3822 * self-join can be removed if the outer relation contains strictly the
3823 * same set of clauses.
3824 */
3825 List *extra_clauses;
3827
3828#endif /* PATHNODES_H */
int16 AttrNumber
Definition attnum.h:21
int64_t int64
Definition c.h:555
int32_t int32
Definition c.h:554
uint64_t uint64
Definition c.h:559
uint32_t uint32
Definition c.h:558
unsigned int Index
Definition c.h:640
CompareType
Definition cmptype.h:32
static int initValue(long lng_val)
Definition informix.c:702
Datum subpath(PG_FUNCTION_ARGS)
Definition ltree_op.c:311
SetOpCmd
Definition nodes.h:407
SetOpStrategy
Definition nodes.h:415
#define pg_node_attr(...)
Definition nodes.h:126
double Cost
Definition nodes.h:261
double Cardinality
Definition nodes.h:262
CmdType
Definition nodes.h:273
AggStrategy
Definition nodes.h:363
NodeTag
Definition nodes.h:27
double Selectivity
Definition nodes.h:260
AggSplit
Definition nodes.h:385
LimitOption
Definition nodes.h:441
JoinType
Definition nodes.h:298
bool is_dummy_rel(RelOptInfo *rel)
Definition joinrels.c:1464
PartitionwiseAggregateType
Definition pathnodes.h:3631
@ PARTITIONWISE_AGGREGATE_PARTIAL
Definition pathnodes.h:3634
@ PARTITIONWISE_AGGREGATE_FULL
Definition pathnodes.h:3633
@ PARTITIONWISE_AGGREGATE_NONE
Definition pathnodes.h:3632
VolatileFunctionStatus
Definition pathnodes.h:1828
@ VOLATILITY_NOVOLATILE
Definition pathnodes.h:1831
@ VOLATILITY_UNKNOWN
Definition pathnodes.h:1829
@ VOLATILITY_VOLATILE
Definition pathnodes.h:1830
#define NIL
Definition pg_list.h:68
bool limit_needed(Query *parse)
Definition planner.c:2841
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
ScanDirection
Definition sdir.h:25
int first_partial_path
Definition pathnodes.h:2272
Cardinality limit_tuples
Definition pathnodes.h:2273
List * child_append_relid_sets
Definition pathnodes.h:2274
List * subpaths
Definition pathnodes.h:2270
Selectivity bitmapselectivity
Definition pathnodes.h:2130
List * bitmapquals
Definition pathnodes.h:2129
Path * bitmapqual
Definition pathnodes.h:2117
Selectivity bitmapselectivity
Definition pathnodes.h:2143
List * bitmapquals
Definition pathnodes.h:2142
const struct CustomPathMethods * methods
Definition pathnodes.h:2243
List * custom_paths
Definition pathnodes.h:2240
uint32 flags
Definition pathnodes.h:2238
List * custom_private
Definition pathnodes.h:2242
List * custom_restrictinfo
Definition pathnodes.h:2241
Path * fdw_outerpath
Definition pathnodes.h:2202
List * fdw_restrictinfo
Definition pathnodes.h:2203
List * fdw_private
Definition pathnodes.h:2204
bool single_copy
Definition pathnodes.h:2359
Path * subpath
Definition pathnodes.h:2358
int num_workers
Definition pathnodes.h:2360
AttrNumber indexcol
Definition pathnodes.h:2093
List * indexcols
Definition pathnodes.h:2094
List * indexquals
Definition pathnodes.h:2091
struct RestrictInfo * rinfo
Definition pathnodes.h:2090
List * indexclauses
Definition pathnodes.h:2043
ScanDirection indexscandir
Definition pathnodes.h:2046
List * indexorderbycols
Definition pathnodes.h:2045
List * indexorderbys
Definition pathnodes.h:2044
Selectivity indexselectivity
Definition pathnodes.h:2048
Cost indextotalcost
Definition pathnodes.h:2047
IndexOptInfo * indexinfo
Definition pathnodes.h:2042
Path * outerjoinpath
Definition pathnodes.h:2390
Path * innerjoinpath
Definition pathnodes.h:2391
JoinType jointype
Definition pathnodes.h:2385
bool inner_unique
Definition pathnodes.h:2387
List * joinrestrictinfo
Definition pathnodes.h:2393
Definition pg_list.h:54
Path * subpath
Definition pathnodes.h:2324
Cardinality est_calls
Definition pathnodes.h:2345
List * hash_operators
Definition pathnodes.h:2336
uint32 est_entries
Definition pathnodes.h:2342
bool binary_mode
Definition pathnodes.h:2340
double est_hit_ratio
Definition pathnodes.h:2347
Cardinality est_unique_keys
Definition pathnodes.h:2346
Path * subpath
Definition pathnodes.h:2335
List * param_exprs
Definition pathnodes.h:2337
List * child_append_relid_sets
Definition pathnodes.h:2299
Cardinality limit_tuples
Definition pathnodes.h:2298
Definition nodes.h:135
Cardinality ppi_rows
Definition pathnodes.h:1911
List * ppi_clauses
Definition pathnodes.h:1912
Bitmapset * ppi_serials
Definition pathnodes.h:1913
Relids ppi_req_outer
Definition pathnodes.h:1910
CompareType pk_cmptype
Definition pathnodes.h:1801
bool pk_nulls_first
Definition pathnodes.h:1802
Oid pk_opfamily
Definition pathnodes.h:1800
VolatileFunctionStatus has_volatile_expr
Definition pathnodes.h:1876
List * exprs
Definition pathnodes.h:1864
QualCost cost
Definition pathnodes.h:1870
List * pathkeys
Definition pathnodes.h:1997
NodeTag pathtype
Definition pathnodes.h:1957
Cardinality rows
Definition pathnodes.h:1991
Cost startup_cost
Definition pathnodes.h:1993
int parallel_workers
Definition pathnodes.h:1988
int disabled_nodes
Definition pathnodes.h:1992
Cost total_cost
Definition pathnodes.h:1994
bool parallel_aware
Definition pathnodes.h:1984
bool parallel_safe
Definition pathnodes.h:1986
List * tidquals
Definition pathnodes.h:2156
Path path
Definition pathnodes.h:2155
List * tidrangequals
Definition pathnodes.h:2168
const char * type

◆ get_pathtarget_sortgroupref

#define get_pathtarget_sortgroupref (   target,
  colno 
)     ((target)->sortgrouprefs ? (target)->sortgrouprefs[colno] : (Index) 0)

Definition at line 1880 of file pathnodes.h.

1881 : (Index) 0)

◆ GROUPING_CAN_PARTIAL_AGG

#define GROUPING_CAN_PARTIAL_AGG   0x0004

Definition at line 3617 of file pathnodes.h.

◆ GROUPING_CAN_USE_HASH

#define GROUPING_CAN_USE_HASH   0x0002

Definition at line 3616 of file pathnodes.h.

◆ GROUPING_CAN_USE_SORT

#define GROUPING_CAN_USE_SORT   0x0001

Definition at line 3615 of file pathnodes.h.

◆ IS_DUMMY_APPEND

#define IS_DUMMY_APPEND (   p)     (IsA((p), AppendPath) && ((AppendPath *) (p))->subpaths == NIL)

Definition at line 2277 of file pathnodes.h.

◆ IS_DUMMY_REL

#define IS_DUMMY_REL (   r)    is_dummy_rel(r)

Definition at line 2285 of file pathnodes.h.

◆ IS_GROUPED_REL

#define IS_GROUPED_REL (   rel)     ((rel)->agg_info != NULL)

Definition at line 1245 of file pathnodes.h.

◆ IS_JOIN_REL

#define IS_JOIN_REL (   rel)
Value:
((rel)->reloptkind == RELOPT_JOINREL || \
(rel)->reloptkind == RELOPT_OTHER_JOINREL)
@ RELOPT_JOINREL
Definition pathnodes.h:966
@ RELOPT_OTHER_JOINREL
Definition pathnodes.h:968

Definition at line 982 of file pathnodes.h.

◆ IS_OTHER_REL

#define IS_OTHER_REL (   rel)
Value:
((rel)->reloptkind == RELOPT_OTHER_MEMBER_REL || \
(rel)->reloptkind == RELOPT_OTHER_JOINREL || \
(rel)->reloptkind == RELOPT_OTHER_UPPER_REL)
@ RELOPT_OTHER_MEMBER_REL
Definition pathnodes.h:967
@ RELOPT_OTHER_UPPER_REL
Definition pathnodes.h:970

Definition at line 992 of file pathnodes.h.

◆ IS_PARTITIONED_REL

#define IS_PARTITIONED_REL (   rel)
Value:
((rel)->part_scheme && (rel)->boundinfo && (rel)->nparts > 0 && \
(rel)->part_rels && !IS_DUMMY_REL(rel))
#define IS_DUMMY_REL(r)
Definition pathnodes.h:2285

Definition at line 1219 of file pathnodes.h.

◆ IS_SIMPLE_REL

#define IS_SIMPLE_REL (   rel)
Value:
((rel)->reloptkind == RELOPT_BASEREL || \
(rel)->reloptkind == RELOPT_OTHER_MEMBER_REL)
@ RELOPT_BASEREL
Definition pathnodes.h:965

Definition at line 977 of file pathnodes.h.

◆ IS_UPPER_REL

#define IS_UPPER_REL (   rel)
Value:
((rel)->reloptkind == RELOPT_UPPER_REL || \
(rel)->reloptkind == RELOPT_OTHER_UPPER_REL)
@ RELOPT_UPPER_REL
Definition pathnodes.h:969

Definition at line 987 of file pathnodes.h.

◆ PATH_REQ_OUTER

#define PATH_REQ_OUTER (   path)     ((path)->param_info ? (path)->param_info->ppi_req_outer : (Relids) NULL)

Definition at line 2001 of file pathnodes.h.

2002 : (Relids) NULL)
Bitmapset * Relids
Definition pathnodes.h:103

◆ PGS_APPEND

#define PGS_APPEND   0x00001000

Definition at line 78 of file pathnodes.h.

◆ PGS_BITMAPSCAN

#define PGS_BITMAPSCAN   0x00000008

Definition at line 69 of file pathnodes.h.

◆ PGS_CONSIDER_INDEXONLY

#define PGS_CONSIDER_INDEXONLY   0x00010000

Definition at line 82 of file pathnodes.h.

◆ PGS_CONSIDER_NONPARTIAL

#define PGS_CONSIDER_NONPARTIAL   0x00040000

Definition at line 84 of file pathnodes.h.

◆ PGS_CONSIDER_PARTITIONWISE

#define PGS_CONSIDER_PARTITIONWISE   0x00020000

Definition at line 83 of file pathnodes.h.

◆ PGS_FOREIGNJOIN

#define PGS_FOREIGNJOIN   0x00000020

Definition at line 71 of file pathnodes.h.

◆ PGS_GATHER

#define PGS_GATHER   0x00004000

Definition at line 80 of file pathnodes.h.

◆ PGS_GATHER_MERGE

#define PGS_GATHER_MERGE   0x00008000

Definition at line 81 of file pathnodes.h.

◆ PGS_HASHJOIN

#define PGS_HASHJOIN   0x00000800

Definition at line 77 of file pathnodes.h.

◆ PGS_INDEXONLYSCAN

#define PGS_INDEXONLYSCAN   0x00000004

Definition at line 68 of file pathnodes.h.

◆ PGS_INDEXSCAN

#define PGS_INDEXSCAN   0x00000002

Definition at line 67 of file pathnodes.h.

◆ PGS_JOIN_ANY

Definition at line 96 of file pathnodes.h.

◆ PGS_MERGE_APPEND

#define PGS_MERGE_APPEND   0x00002000

Definition at line 79 of file pathnodes.h.

◆ PGS_MERGEJOIN_ANY

Definition at line 92 of file pathnodes.h.

◆ PGS_MERGEJOIN_MATERIALIZE

#define PGS_MERGEJOIN_MATERIALIZE   0x00000080

Definition at line 73 of file pathnodes.h.

◆ PGS_MERGEJOIN_PLAIN

#define PGS_MERGEJOIN_PLAIN   0x00000040

Definition at line 72 of file pathnodes.h.

◆ PGS_NESTLOOP_ANY

Definition at line 94 of file pathnodes.h.

◆ PGS_NESTLOOP_MATERIALIZE

#define PGS_NESTLOOP_MATERIALIZE   0x00000200

Definition at line 75 of file pathnodes.h.

◆ PGS_NESTLOOP_MEMOIZE

#define PGS_NESTLOOP_MEMOIZE   0x00000400

Definition at line 76 of file pathnodes.h.

◆ PGS_NESTLOOP_PLAIN

#define PGS_NESTLOOP_PLAIN   0x00000100

Definition at line 74 of file pathnodes.h.

◆ PGS_SCAN_ANY

#define PGS_SCAN_ANY
Value:
#define PGS_TIDSCAN
Definition pathnodes.h:70
#define PGS_SEQSCAN
Definition pathnodes.h:66
#define PGS_BITMAPSCAN
Definition pathnodes.h:69
#define PGS_INDEXONLYSCAN
Definition pathnodes.h:68
#define PGS_INDEXSCAN
Definition pathnodes.h:67

Definition at line 89 of file pathnodes.h.

◆ PGS_SEQSCAN

#define PGS_SEQSCAN   0x00000001

Definition at line 66 of file pathnodes.h.

◆ PGS_TIDSCAN

#define PGS_TIDSCAN   0x00000010

Definition at line 70 of file pathnodes.h.

◆ planner_rt_fetch

#define planner_rt_fetch (   rti,
  root 
)
Value:
((root)->simple_rte_array ? (root)->simple_rte_array[rti] : \
rt_fetch(rti, (root)->parse->rtable))
void parse(int)
Definition parse.c:49
tree ctl root
Definition radixtree.h:1857

Definition at line 692 of file pathnodes.h.

693 : \
694 rt_fetch(rti, (root)->parse->rtable))

◆ planner_subplan_get_plan

#define planner_subplan_get_plan (   root,
  subplan 
)     ((Plan *) list_nth((root)->glob->subplans, (subplan)->plan_id - 1))

Definition at line 277 of file pathnodes.h.

◆ REL_HAS_ALL_PART_PROPS

#define REL_HAS_ALL_PART_PROPS (   rel)
Value:
((rel)->part_scheme && (rel)->boundinfo && (rel)->nparts > 0 && \
(rel)->part_rels && (rel)->partexprs && (rel)->nullable_partexprs)

Definition at line 1227 of file pathnodes.h.

◆ RELATION_WAS_MADE_UNIQUE

#define RELATION_WAS_MADE_UNIQUE (   rel,
  sjinfo,
  nominal_jointype 
)
Value:
((nominal_jointype) == JOIN_INNER && (sjinfo)->jointype == JOIN_SEMI && \
bms_equal((sjinfo)->syn_righthand, (rel)->relids))
@ JOIN_SEMI
Definition nodes.h:317
@ JOIN_INNER
Definition nodes.h:303

Definition at line 1238 of file pathnodes.h.

◆ RINFO_IS_PUSHED_DOWN

#define RINFO_IS_PUSHED_DOWN (   rinfo,
  joinrelids 
)
Value:
((rinfo)->is_pushed_down || \
!bms_is_subset((rinfo)->required_relids, joinrelids))
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:412

Definition at line 3043 of file pathnodes.h.

Typedef Documentation

◆ AggClauseCosts

◆ AggClauseInfo

◆ AggInfo

◆ AggPath

◆ AggTransInfo

◆ AppendPath

◆ AppendRelInfo

◆ BitmapAndPath

◆ BitmapHeapPath

◆ BitmapOrPath

◆ CostSelector

◆ CustomPath

◆ EquivalenceClass

◆ EquivalenceMember

◆ ForeignKeyOptInfo

◆ ForeignPath

◆ GatherMergePath

◆ GatherPath

◆ GroupByOrdering

◆ GroupingExprInfo

◆ GroupingSetData

◆ GroupingSetsPath

◆ GroupPath

◆ GroupResultPath

◆ HashPath

◆ IncrementalSortPath

◆ IndexClause

◆ IndexOptInfo

◆ IndexPath

◆ JoinCostWorkspace

◆ JoinDomain

◆ JoinPath

◆ JoinPathExtraData

◆ LimitPath

◆ LockRowsPath

◆ MaterialPath

◆ MemoizePath

◆ MergeAppendPath

◆ MergePath

◆ MergeScanSelCache

◆ MinMaxAggInfo

◆ MinMaxAggPath

◆ ModifyTablePath

◆ NestPath

◆ OuterJoinClauseInfo

◆ ParamPathInfo

◆ PartitionScheme

Definition at line 726 of file pathnodes.h.

◆ PartitionSchemeData

◆ Path

typedef struct Path Path

◆ PathKey

◆ PathTarget

◆ PlaceHolderInfo

◆ PlaceHolderVar

◆ PlannerGlobal

◆ PlannerInfo

Definition at line 300 of file pathnodes.h.

◆ PlannerParamItem

◆ ProjectionPath

◆ ProjectSetPath

◆ QualCost

◆ RecursiveUnionPath

◆ RelAggInfo

◆ Relids

Definition at line 103 of file pathnodes.h.

◆ RelOptInfo

◆ RelOptKind

◆ RestrictInfo

◆ RollupData

◆ RowIdentityVarInfo

◆ SemiAntiJoinFactors

◆ SetOpPath

◆ SortPath

◆ SpecialJoinInfo

◆ StatisticExtInfo

◆ SubqueryScanPath

◆ TidPath

◆ TidRangePath

◆ UniquePath

◆ UniqueRelInfo

◆ UpperRelationKind

◆ VolatileFunctionStatus

◆ WindowAggPath

Enumeration Type Documentation

◆ CostSelector

Enumerator
STARTUP_COST 
TOTAL_COST 

Definition at line 109 of file pathnodes.h.

110{
CostSelector
Definition pathnodes.h:110
@ TOTAL_COST
Definition pathnodes.h:111
@ STARTUP_COST
Definition pathnodes.h:111

◆ PartitionwiseAggregateType

Enumerator
PARTITIONWISE_AGGREGATE_NONE 
PARTITIONWISE_AGGREGATE_FULL 
PARTITIONWISE_AGGREGATE_PARTIAL 

Definition at line 3630 of file pathnodes.h.

◆ RelOptKind

Enumerator
RELOPT_BASEREL 
RELOPT_JOINREL 
RELOPT_OTHER_MEMBER_REL 
RELOPT_OTHER_JOINREL 
RELOPT_UPPER_REL 
RELOPT_OTHER_UPPER_REL 

Definition at line 963 of file pathnodes.h.

◆ UpperRelationKind

Enumerator
UPPERREL_SETOP 
UPPERREL_PARTIAL_GROUP_AGG 
UPPERREL_GROUP_AGG 
UPPERREL_WINDOW 
UPPERREL_PARTIAL_DISTINCT 
UPPERREL_DISTINCT 
UPPERREL_ORDERED 
UPPERREL_FINAL 

Definition at line 142 of file pathnodes.h.

143{
144 UPPERREL_SETOP, /* result of UNION/INTERSECT/EXCEPT, if any */
145 UPPERREL_PARTIAL_GROUP_AGG, /* result of partial grouping/aggregation, if
146 * any */
147 UPPERREL_GROUP_AGG, /* result of grouping/aggregation, if any */
148 UPPERREL_WINDOW, /* result of window functions, if any */
149 UPPERREL_PARTIAL_DISTINCT, /* result of partial "SELECT DISTINCT", if any */
150 UPPERREL_DISTINCT, /* result of "SELECT DISTINCT", if any */
151 UPPERREL_ORDERED, /* result of ORDER BY, if any */
152 UPPERREL_FINAL, /* result of any remaining top-level actions */
153 /* NB: UPPERREL_FINAL must be last enum entry; it's used to size arrays */
UpperRelationKind
Definition pathnodes.h:143
@ UPPERREL_SETOP
Definition pathnodes.h:144
@ UPPERREL_GROUP_AGG
Definition pathnodes.h:147
@ UPPERREL_FINAL
Definition pathnodes.h:152
@ UPPERREL_DISTINCT
Definition pathnodes.h:150
@ UPPERREL_PARTIAL_GROUP_AGG
Definition pathnodes.h:145
@ UPPERREL_ORDERED
Definition pathnodes.h:151
@ UPPERREL_WINDOW
Definition pathnodes.h:148
@ UPPERREL_PARTIAL_DISTINCT
Definition pathnodes.h:149

◆ VolatileFunctionStatus

Enumerator
VOLATILITY_UNKNOWN 
VOLATILITY_VOLATILE 
VOLATILITY_NOVOLATILE 

Definition at line 1827 of file pathnodes.h.

Function Documentation

◆ is_dummy_rel()

bool is_dummy_rel ( RelOptInfo rel)
extern

Definition at line 1464 of file joinrels.c.

1465{
1466 Path *path;
1467
1468 /*
1469 * A rel that is known dummy will have just one path that is a childless
1470 * Append. (Even if somehow it has more paths, a childless Append will
1471 * have cost zero and hence should be at the front of the pathlist.)
1472 */
1473 if (rel->pathlist == NIL)
1474 return false;
1475 path = (Path *) linitial(rel->pathlist);
1476
1477 /*
1478 * Initially, a dummy path will just be a childless Append. But in later
1479 * planning stages we might stick a ProjectSetPath and/or ProjectionPath
1480 * on top, since Append can't project. Rather than make assumptions about
1481 * which combinations can occur, just descend through whatever we find.
1482 */
1483 for (;;)
1484 {
1485 if (IsA(path, ProjectionPath))
1486 path = ((ProjectionPath *) path)->subpath;
1487 else if (IsA(path, ProjectSetPath))
1488 path = ((ProjectSetPath *) path)->subpath;
1489 else
1490 break;
1491 }
1492 if (IS_DUMMY_APPEND(path))
1493 return true;
1494 return false;
1495}
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define IS_DUMMY_APPEND(p)
Definition pathnodes.h:2277
#define linitial(l)
Definition pg_list.h:178
List * pathlist
Definition pathnodes.h:1038

References IS_DUMMY_APPEND, IsA, linitial, NIL, RelOptInfo::pathlist, and subpath().

Referenced by build_setop_child_paths(), generate_nonunion_paths(), generate_union_paths(), make_join_rel(), mark_dummy_rel(), and populate_joinrel_with_paths().