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 1672 of file pathnodes.h.

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

◆ get_pathtarget_sortgroupref

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

Definition at line 1882 of file pathnodes.h.

1883 : (Index) 0)

◆ GROUPING_CAN_PARTIAL_AGG

#define GROUPING_CAN_PARTIAL_AGG   0x0004

Definition at line 3619 of file pathnodes.h.

◆ GROUPING_CAN_USE_HASH

#define GROUPING_CAN_USE_HASH   0x0002

Definition at line 3618 of file pathnodes.h.

◆ GROUPING_CAN_USE_SORT

#define GROUPING_CAN_USE_SORT   0x0001

Definition at line 3617 of file pathnodes.h.

◆ IS_DUMMY_APPEND

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

Definition at line 2279 of file pathnodes.h.

◆ IS_DUMMY_REL

#define IS_DUMMY_REL (   r)    is_dummy_rel(r)

Definition at line 2287 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:2287

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 2003 of file pathnodes.h.

2004 : (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 3045 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 3632 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 1829 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:2279
#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().