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

◆ EC_MUST_BE_REDUNDANT

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

Definition at line 1684 of file pathnodes.h.

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

◆ get_pathtarget_sortgroupref

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

Definition at line 1894 of file pathnodes.h.

1895 : (Index) 0)

◆ GROUPING_CAN_PARTIAL_AGG

#define GROUPING_CAN_PARTIAL_AGG   0x0004

Definition at line 3632 of file pathnodes.h.

◆ GROUPING_CAN_USE_HASH

#define GROUPING_CAN_USE_HASH   0x0002

Definition at line 3631 of file pathnodes.h.

◆ GROUPING_CAN_USE_SORT

#define GROUPING_CAN_USE_SORT   0x0001

Definition at line 3630 of file pathnodes.h.

◆ IS_DUMMY_APPEND

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

Definition at line 2291 of file pathnodes.h.

◆ IS_DUMMY_REL

#define IS_DUMMY_REL (   r)    is_dummy_rel(r)

Definition at line 2299 of file pathnodes.h.

◆ IS_GROUPED_REL

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

Definition at line 1257 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:978
@ RELOPT_OTHER_JOINREL
Definition pathnodes.h:980

Definition at line 994 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:979
@ RELOPT_OTHER_UPPER_REL
Definition pathnodes.h:982

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

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

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

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

2016 : (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 704 of file pathnodes.h.

705 : \
706 rt_fetch(rti, (root)->parse->rtable))

◆ planner_subplan_get_plan

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

Definition at line 277 of file pathnodes.h.

◆ REL_HAS_ALL_PART_PROPS

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

Definition at line 1239 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 1250 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 3058 of file pathnodes.h.

Typedef Documentation

◆ AggClauseCosts

◆ AggClauseInfo

◆ AggInfo

◆ AggPath

◆ AggTransInfo

◆ AppendPath

◆ AppendRelInfo

◆ BitmapAndPath

◆ BitmapHeapPath

◆ BitmapOrPath

◆ CostSelector

◆ CustomPath

◆ EquivalenceClass

◆ EquivalenceMember

◆ ForeignKeyOptInfo

◆ ForeignPath

◆ GatherMergePath

◆ GatherPath

◆ GroupByOrdering

◆ GroupingExprInfo

◆ GroupingSetData

◆ GroupingSetsPath

◆ GroupPath

◆ GroupResultPath

◆ HashPath

◆ IncrementalSortPath

◆ IndexClause

◆ IndexOptInfo

◆ IndexPath

◆ JoinCostWorkspace

◆ JoinDomain

◆ JoinPath

◆ JoinPathExtraData

◆ LimitPath

◆ LockRowsPath

◆ MaterialPath

◆ MemoizePath

◆ MergeAppendPath

◆ MergePath

◆ MergeScanSelCache

◆ MinMaxAggInfo

◆ MinMaxAggPath

◆ ModifyTablePath

◆ NestPath

◆ OuterJoinClauseInfo

◆ ParamPathInfo

◆ PartitionScheme

Definition at line 738 of file pathnodes.h.

◆ PartitionSchemeData

◆ Path

typedef struct Path Path

◆ PathKey

◆ PathTarget

◆ PlaceHolderInfo

◆ PlaceHolderVar

◆ PlannerGlobal

◆ PlannerInfo

Definition at line 300 of file pathnodes.h.

◆ PlannerParamItem

◆ ProjectionPath

◆ ProjectSetPath

◆ QualCost

◆ RecursiveUnionPath

◆ RelAggInfo

◆ Relids

Definition at line 103 of file pathnodes.h.

◆ RelOptInfo

◆ RelOptKind

◆ RestrictInfo

◆ RollupData

◆ RowIdentityVarInfo

◆ SemiAntiJoinFactors

◆ SetOpPath

◆ SortPath

◆ SpecialJoinInfo

◆ StatisticExtInfo

◆ SubqueryScanPath

◆ TidPath

◆ TidRangePath

◆ UniquePath

◆ UniqueRelInfo

◆ UpperRelationKind

◆ VolatileFunctionStatus

◆ WindowAggPath

Enumeration Type Documentation

◆ CostSelector

Enumerator
STARTUP_COST 
TOTAL_COST 

Definition at line 109 of file pathnodes.h.

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

◆ PartitionwiseAggregateType

Enumerator
PARTITIONWISE_AGGREGATE_NONE 
PARTITIONWISE_AGGREGATE_FULL 
PARTITIONWISE_AGGREGATE_PARTIAL 

Definition at line 3645 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 975 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 1841 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:2291
#define linitial(l)
Definition pg_list.h:178
List * pathlist
Definition pathnodes.h:1050

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