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

◆ EC_MUST_BE_REDUNDANT

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

Definition at line 1664 of file pathnodes.h.

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

◆ get_pathtarget_sortgroupref

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

Definition at line 1874 of file pathnodes.h.

1875 : (Index) 0)

◆ GROUPING_CAN_PARTIAL_AGG

#define GROUPING_CAN_PARTIAL_AGG   0x0004

Definition at line 3601 of file pathnodes.h.

◆ GROUPING_CAN_USE_HASH

#define GROUPING_CAN_USE_HASH   0x0002

Definition at line 3600 of file pathnodes.h.

◆ GROUPING_CAN_USE_SORT

#define GROUPING_CAN_USE_SORT   0x0001

Definition at line 3599 of file pathnodes.h.

◆ IS_DUMMY_APPEND

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

Definition at line 2264 of file pathnodes.h.

◆ IS_DUMMY_REL

#define IS_DUMMY_REL (   r)    is_dummy_rel(r)

Definition at line 2272 of file pathnodes.h.

◆ IS_GROUPED_REL

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

Definition at line 1239 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:960
@ RELOPT_OTHER_JOINREL
Definition pathnodes.h:962

Definition at line 976 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:961
@ RELOPT_OTHER_UPPER_REL
Definition pathnodes.h:964

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

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

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

Definition at line 981 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 1995 of file pathnodes.h.

1996 : (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 686 of file pathnodes.h.

687 : \
688 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 271 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 1221 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 1232 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 3027 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

◆ PartitionSchemeData

◆ Path

◆ PathKey

◆ PathTarget

◆ PlaceHolderInfo

◆ PlaceHolderVar

◆ PlannerGlobal

◆ PlannerInfo

Definition at line 294 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 3614 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 957 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 1821 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:2264
#define linitial(l)
Definition pg_list.h:178
List * pathlist
Definition pathnodes.h:1032

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().