PostgreSQL Source Code  git master
plancat.c File Reference
#include "postgres.h"
#include <math.h>
#include "access/genam.h"
#include "access/htup_details.h"
#include "access/nbtree.h"
#include "access/sysattr.h"
#include "access/table.h"
#include "access/tableam.h"
#include "access/transam.h"
#include "access/xlog.h"
#include "catalog/catalog.h"
#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/pg_am.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_statistic_ext.h"
#include "foreign/fdwapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/supportnodes.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/optimizer.h"
#include "optimizer/plancat.h"
#include "optimizer/prep.h"
#include "parser/parse_relation.h"
#include "parser/parsetree.h"
#include "partitioning/partdesc.h"
#include "rewrite/rewriteManip.h"
#include "statistics/statistics.h"
#include "storage/bufmgr.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Include dependency graph for plancat.c:

Go to the source code of this file.

Functions

static void get_relation_foreign_keys (PlannerInfo *root, RelOptInfo *rel, Relation relation, bool inhparent)
 
static bool infer_collation_opclass_match (InferenceElem *elem, Relation idxRel, List *idxExprs)
 
static Listget_relation_constraints (PlannerInfo *root, Oid relationObjectId, RelOptInfo *rel, bool include_noinherit, bool include_notnull, bool include_partition)
 
static Listbuild_index_tlist (PlannerInfo *root, IndexOptInfo *index, Relation heapRelation)
 
static Listget_relation_statistics (RelOptInfo *rel, Relation relation)
 
static void set_relation_partition_info (PlannerInfo *root, RelOptInfo *rel, Relation relation)
 
static PartitionScheme find_partition_scheme (PlannerInfo *root, Relation rel)
 
static void set_baserel_partition_key_exprs (Relation relation, RelOptInfo *rel)
 
static void set_baserel_partition_constraint (Relation relation, RelOptInfo *rel)
 
void get_relation_info (PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
 
Listinfer_arbiter_indexes (PlannerInfo *root)
 
void estimate_rel_size (Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
 
int32 get_rel_data_width (Relation rel, int32 *attr_widths)
 
int32 get_relation_data_width (Oid relid, int32 *attr_widths)
 
bool relation_excluded_by_constraints (PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
 
Listbuild_physical_tlist (PlannerInfo *root, RelOptInfo *rel)
 
Selectivity restriction_selectivity (PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, int varRelid)
 
Selectivity join_selectivity (PlannerInfo *root, Oid operatorid, List *args, Oid inputcollid, JoinType jointype, SpecialJoinInfo *sjinfo)
 
Selectivity function_selectivity (PlannerInfo *root, Oid funcid, List *args, Oid inputcollid, bool is_join, int varRelid, JoinType jointype, SpecialJoinInfo *sjinfo)
 
void add_function_cost (PlannerInfo *root, Oid funcid, Node *node, QualCost *cost)
 
double get_function_rows (PlannerInfo *root, Oid funcid, Node *node)
 
bool has_unique_index (RelOptInfo *rel, AttrNumber attno)
 
bool has_row_triggers (PlannerInfo *root, Index rti, CmdType event)
 
bool has_stored_generated_columns (PlannerInfo *root, Index rti)
 

Variables

int constraint_exclusion = CONSTRAINT_EXCLUSION_PARTITION
 
get_relation_info_hook_type get_relation_info_hook = NULL
 

Function Documentation

◆ add_function_cost()

void add_function_cost ( PlannerInfo root,
Oid  funcid,
Node node,
QualCost cost 
)

Definition at line 1917 of file plancat.c.

References cpu_operator_cost, DatumGetPointer, elog, ERROR, SupportRequestCost::funcid, GETSTRUCT, HeapTupleIsValid, SupportRequestCost::node, ObjectIdGetDatum, OidFunctionCall1, OidIsValid, QualCost::per_tuple, SupportRequestCost::per_tuple, PointerGetDatum, PROCOID, ReleaseSysCache(), SupportRequestCost::root, SearchSysCache1(), QualCost::startup, SupportRequestCost::startup, T_SupportRequestCost, and SupportRequestCost::type.

Referenced by cost_qual_eval_walker(), cost_windowagg(), and get_agg_clause_costs().

1919 {
1920  HeapTuple proctup;
1921  Form_pg_proc procform;
1922 
1923  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
1924  if (!HeapTupleIsValid(proctup))
1925  elog(ERROR, "cache lookup failed for function %u", funcid);
1926  procform = (Form_pg_proc) GETSTRUCT(proctup);
1927 
1928  if (OidIsValid(procform->prosupport))
1929  {
1930  SupportRequestCost req;
1931  SupportRequestCost *sresult;
1932 
1933  req.type = T_SupportRequestCost;
1934  req.root = root;
1935  req.funcid = funcid;
1936  req.node = node;
1937 
1938  /* Initialize cost fields so that support function doesn't have to */
1939  req.startup = 0;
1940  req.per_tuple = 0;
1941 
1942  sresult = (SupportRequestCost *)
1943  DatumGetPointer(OidFunctionCall1(procform->prosupport,
1944  PointerGetDatum(&req)));
1945 
1946  if (sresult == &req)
1947  {
1948  /* Success, so accumulate support function's estimate into *cost */
1949  cost->startup += req.startup;
1950  cost->per_tuple += req.per_tuple;
1951  ReleaseSysCache(proctup);
1952  return;
1953  }
1954  }
1955 
1956  /* No support function, or it failed, so rely on procost */
1957  cost->per_tuple += procform->procost * cpu_operator_cost;
1958 
1959  ReleaseSysCache(proctup);
1960 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define PointerGetDatum(X)
Definition: postgres.h:556
#define OidIsValid(objectId)
Definition: c.h:698
Cost startup
Definition: pathnodes.h:45
Cost per_tuple
Definition: pathnodes.h:46
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:664
double cpu_operator_cost
Definition: costsize.c:122
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
struct PlannerInfo * root
Definition: supportnodes.h:136
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:228

◆ build_index_tlist()

static List * build_index_tlist ( PlannerInfo root,
IndexOptInfo index,
Relation  heapRelation 
)
static

Definition at line 1713 of file plancat.c.

References elog, ERROR, FormData_pg_attribute, i, IndexOptInfo::indexkeys, IndexOptInfo::indexprs, lappend(), lfirst, list_head(), lnext(), makeTargetEntry(), makeVar(), IndexOptInfo::ncolumns, NIL, RelationData::rd_att, IndexOptInfo::rel, RelOptInfo::relid, SystemAttributeDefinition(), and TupleDescAttr.

Referenced by get_relation_info().

1715 {
1716  List *tlist = NIL;
1717  Index varno = index->rel->relid;
1718  ListCell *indexpr_item;
1719  int i;
1720 
1721  indexpr_item = list_head(index->indexprs);
1722  for (i = 0; i < index->ncolumns; i++)
1723  {
1724  int indexkey = index->indexkeys[i];
1725  Expr *indexvar;
1726 
1727  if (indexkey != 0)
1728  {
1729  /* simple column */
1730  const FormData_pg_attribute *att_tup;
1731 
1732  if (indexkey < 0)
1733  att_tup = SystemAttributeDefinition(indexkey);
1734  else
1735  att_tup = TupleDescAttr(heapRelation->rd_att, indexkey - 1);
1736 
1737  indexvar = (Expr *) makeVar(varno,
1738  indexkey,
1739  att_tup->atttypid,
1740  att_tup->atttypmod,
1741  att_tup->attcollation,
1742  0);
1743  }
1744  else
1745  {
1746  /* expression column */
1747  if (indexpr_item == NULL)
1748  elog(ERROR, "wrong number of index expressions");
1749  indexvar = (Expr *) lfirst(indexpr_item);
1750  indexpr_item = lnext(index->indexprs, indexpr_item);
1751  }
1752 
1753  tlist = lappend(tlist,
1754  makeTargetEntry(indexvar,
1755  i + 1,
1756  NULL,
1757  false));
1758  }
1759  if (indexpr_item != NULL)
1760  elog(ERROR, "wrong number of index expressions");
1761 
1762  return tlist;
1763 }
#define NIL
Definition: pg_list.h:65
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:322
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
const FormData_pg_attribute * SystemAttributeDefinition(AttrNumber attno)
Definition: heap.c:249
RelOptInfo * rel
Definition: pathnodes.h:820
#define ERROR
Definition: elog.h:45
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:238
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Index relid
Definition: pathnodes.h:694
List * lappend(List *list, void *datum)
Definition: list.c:336
unsigned int Index
Definition: c.h:537
TupleDesc rd_att
Definition: rel.h:111
FormData_pg_attribute
Definition: pg_attribute.h:177
#define lfirst(lc)
Definition: pg_list.h:169
#define elog(elevel,...)
Definition: elog.h:228
int i
int * indexkeys
Definition: pathnodes.h:830
Definition: pg_list.h:50
List * indexprs
Definition: pathnodes.h:843

◆ build_physical_tlist()

List* build_physical_tlist ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 1592 of file plancat.c.

References elog, ERROR, expandRTE(), IsA, lappend(), lfirst, makeTargetEntry(), makeVar(), makeVarFromTargetEntry(), NIL, NoLock, planner_rt_fetch, RelationData::rd_att, RelationGetNumberOfAttributes, RelOptInfo::relid, RangeTblEntry::relid, TargetEntry::resjunk, TargetEntry::resno, RTE_CTE, RTE_FUNCTION, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RangeTblEntry::rtekind, RangeTblEntry::subquery, table_close(), table_open(), Query::targetList, and TupleDescAttr.

Referenced by create_scan_plan().

1593 {
1594  List *tlist = NIL;
1595  Index varno = rel->relid;
1596  RangeTblEntry *rte = planner_rt_fetch(varno, root);
1597  Relation relation;
1598  Query *subquery;
1599  Var *var;
1600  ListCell *l;
1601  int attrno,
1602  numattrs;
1603  List *colvars;
1604 
1605  switch (rte->rtekind)
1606  {
1607  case RTE_RELATION:
1608  /* Assume we already have adequate lock */
1609  relation = table_open(rte->relid, NoLock);
1610 
1611  numattrs = RelationGetNumberOfAttributes(relation);
1612  for (attrno = 1; attrno <= numattrs; attrno++)
1613  {
1614  Form_pg_attribute att_tup = TupleDescAttr(relation->rd_att,
1615  attrno - 1);
1616 
1617  if (att_tup->attisdropped || att_tup->atthasmissing)
1618  {
1619  /* found a dropped or missing col, so punt */
1620  tlist = NIL;
1621  break;
1622  }
1623 
1624  var = makeVar(varno,
1625  attrno,
1626  att_tup->atttypid,
1627  att_tup->atttypmod,
1628  att_tup->attcollation,
1629  0);
1630 
1631  tlist = lappend(tlist,
1632  makeTargetEntry((Expr *) var,
1633  attrno,
1634  NULL,
1635  false));
1636  }
1637 
1638  table_close(relation, NoLock);
1639  break;
1640 
1641  case RTE_SUBQUERY:
1642  subquery = rte->subquery;
1643  foreach(l, subquery->targetList)
1644  {
1645  TargetEntry *tle = (TargetEntry *) lfirst(l);
1646 
1647  /*
1648  * A resjunk column of the subquery can be reflected as
1649  * resjunk in the physical tlist; we need not punt.
1650  */
1651  var = makeVarFromTargetEntry(varno, tle);
1652 
1653  tlist = lappend(tlist,
1654  makeTargetEntry((Expr *) var,
1655  tle->resno,
1656  NULL,
1657  tle->resjunk));
1658  }
1659  break;
1660 
1661  case RTE_FUNCTION:
1662  case RTE_TABLEFUNC:
1663  case RTE_VALUES:
1664  case RTE_CTE:
1665  case RTE_NAMEDTUPLESTORE:
1666  case RTE_RESULT:
1667  /* Not all of these can have dropped cols, but share code anyway */
1668  expandRTE(rte, varno, 0, -1, true /* include dropped */ ,
1669  NULL, &colvars);
1670  foreach(l, colvars)
1671  {
1672  var = (Var *) lfirst(l);
1673 
1674  /*
1675  * A non-Var in expandRTE's output means a dropped column;
1676  * must punt.
1677  */
1678  if (!IsA(var, Var))
1679  {
1680  tlist = NIL;
1681  break;
1682  }
1683 
1684  tlist = lappend(tlist,
1685  makeTargetEntry((Expr *) var,
1686  var->varattno,
1687  NULL,
1688  false));
1689  }
1690  break;
1691 
1692  default:
1693  /* caller error */
1694  elog(ERROR, "unsupported RTE kind %d in build_physical_tlist",
1695  (int) rte->rtekind);
1696  break;
1697  }
1698 
1699  return tlist;
1700 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:463
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Var * makeVarFromTargetEntry(Index varno, TargetEntry *tle)
Definition: makefuncs.c:103
Definition: primnodes.h:181
List * targetList
Definition: parsenodes.h:140
bool resjunk
Definition: primnodes.h:1438
#define ERROR
Definition: elog.h:45
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:377
#define NoLock
Definition: lockdefs.h:34
AttrNumber resno
Definition: primnodes.h:1432
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:238
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Index relid
Definition: pathnodes.h:694
List * lappend(List *list, void *datum)
Definition: list.c:336
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
unsigned int Index
Definition: c.h:537
TupleDesc rd_att
Definition: rel.h:111
#define lfirst(lc)
Definition: pg_list.h:169
RTEKind rtekind
Definition: parsenodes.h:981
Query * subquery
Definition: parsenodes.h:1016
#define elog(elevel,...)
Definition: elog.h:228
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50

◆ estimate_rel_size()

void estimate_rel_size ( Relation  rel,
int32 attr_widths,
BlockNumber pages,
double *  tuples,
double *  allvisfrac 
)

Definition at line 961 of file plancat.c.

References get_rel_data_width(), MAXALIGN, RelationData::rd_rel, RelationGetNumberOfBlocks, SizeofHeapTupleHeader, SizeOfPageHeaderData, and table_relation_estimate_size().

Referenced by get_relation_info(), hashbuild(), and plan_create_index_workers().

963 {
964  BlockNumber curpages;
965  BlockNumber relpages;
966  double reltuples;
967  BlockNumber relallvisible;
968  double density;
969 
970  switch (rel->rd_rel->relkind)
971  {
972  case RELKIND_RELATION:
973  case RELKIND_MATVIEW:
974  case RELKIND_TOASTVALUE:
975  table_relation_estimate_size(rel, attr_widths, pages, tuples,
976  allvisfrac);
977  break;
978 
979  case RELKIND_INDEX:
980 
981  /*
982  * XXX: It'd probably be good to move this into a callback,
983  * individual index types e.g. know if they have a metapage.
984  */
985 
986  /* it has storage, ok to call the smgr */
987  curpages = RelationGetNumberOfBlocks(rel);
988 
989  /* report estimated # pages */
990  *pages = curpages;
991  /* quick exit if rel is clearly empty */
992  if (curpages == 0)
993  {
994  *tuples = 0;
995  *allvisfrac = 0;
996  break;
997  }
998 
999  /* coerce values in pg_class to more desirable types */
1000  relpages = (BlockNumber) rel->rd_rel->relpages;
1001  reltuples = (double) rel->rd_rel->reltuples;
1002  relallvisible = (BlockNumber) rel->rd_rel->relallvisible;
1003 
1004  /*
1005  * Discount the metapage while estimating the number of tuples.
1006  * This is a kluge because it assumes more than it ought to about
1007  * index structure. Currently it's OK for btree, hash, and GIN
1008  * indexes but suspect for GiST indexes.
1009  */
1010  if (relpages > 0)
1011  {
1012  curpages--;
1013  relpages--;
1014  }
1015 
1016  /* estimate number of tuples from previous tuple density */
1017  if (reltuples >= 0 && relpages > 0)
1018  density = reltuples / (double) relpages;
1019  else
1020  {
1021  /*
1022  * If we have no data because the relation was never vacuumed,
1023  * estimate tuple width from attribute datatypes. We assume
1024  * here that the pages are completely full, which is OK for
1025  * tables (since they've presumably not been VACUUMed yet) but
1026  * is probably an overestimate for indexes. Fortunately
1027  * get_relation_info() can clamp the overestimate to the
1028  * parent table's size.
1029  *
1030  * Note: this code intentionally disregards alignment
1031  * considerations, because (a) that would be gilding the lily
1032  * considering how crude the estimate is, and (b) it creates
1033  * platform dependencies in the default plans which are kind
1034  * of a headache for regression testing.
1035  *
1036  * XXX: Should this logic be more index specific?
1037  */
1038  int32 tuple_width;
1039 
1040  tuple_width = get_rel_data_width(rel, attr_widths);
1041  tuple_width += MAXALIGN(SizeofHeapTupleHeader);
1042  tuple_width += sizeof(ItemIdData);
1043  /* note: integer division is intentional here */
1044  density = (BLCKSZ - SizeOfPageHeaderData) / tuple_width;
1045  }
1046  *tuples = rint(density * (double) curpages);
1047 
1048  /*
1049  * We use relallvisible as-is, rather than scaling it up like we
1050  * do for the pages and tuples counts, on the theory that any
1051  * pages added since the last VACUUM are most likely not marked
1052  * all-visible. But costsize.c wants it converted to a fraction.
1053  */
1054  if (relallvisible == 0 || curpages <= 0)
1055  *allvisfrac = 0;
1056  else if ((double) relallvisible >= curpages)
1057  *allvisfrac = 1;
1058  else
1059  *allvisfrac = (double) relallvisible / curpages;
1060  break;
1061 
1062  case RELKIND_SEQUENCE:
1063  /* Sequences always have a known size */
1064  *pages = 1;
1065  *tuples = 1;
1066  *allvisfrac = 0;
1067  break;
1068  case RELKIND_FOREIGN_TABLE:
1069  /* Just use whatever's in pg_class */
1070  /* Note that FDW must cope if reltuples is -1! */
1071  *pages = rel->rd_rel->relpages;
1072  *tuples = rel->rd_rel->reltuples;
1073  *allvisfrac = 0;
1074  break;
1075  default:
1076  /* else it has no disk storage; probably shouldn't get here? */
1077  *pages = 0;
1078  *tuples = 0;
1079  *allvisfrac = 0;
1080  break;
1081  }
1082 }
static void table_relation_estimate_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: tableam.h:1820
#define SizeofHeapTupleHeader
Definition: htup_details.h:184
uint32 BlockNumber
Definition: block.h:31
#define SizeOfPageHeaderData
Definition: bufpage.h:216
Form_pg_class rd_rel
Definition: rel.h:110
signed int int32
Definition: c.h:417
struct ItemIdData ItemIdData
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:211
#define MAXALIGN(LEN)
Definition: c.h:745
int32 get_rel_data_width(Relation rel, int32 *attr_widths)
Definition: plancat.c:1099

◆ find_partition_scheme()

static PartitionScheme find_partition_scheme ( PlannerInfo root,
Relation  rel 
)
static

Definition at line 2159 of file plancat.c.

References Assert, CurrentMemoryContext, fmgr_info_copy(), FmgrInfo::fn_oid, i, lappend(), lfirst, palloc(), palloc0(), PlannerInfo::part_schemes, PartitionKeyData::partcollation, PartitionSchemeData::partcollation, PartitionKeyData::partnatts, PartitionSchemeData::partnatts, PartitionKeyData::partopcintype, PartitionSchemeData::partopcintype, PartitionKeyData::partopfamily, PartitionSchemeData::partopfamily, PartitionKeyData::partsupfunc, PartitionSchemeData::partsupfunc, PartitionKeyData::parttypbyval, PartitionSchemeData::parttypbyval, PartitionKeyData::parttyplen, PartitionSchemeData::parttyplen, RelationGetPartitionKey(), PartitionKeyData::strategy, and PartitionSchemeData::strategy.

Referenced by set_relation_partition_info().

2160 {
2161  PartitionKey partkey = RelationGetPartitionKey(relation);
2162  ListCell *lc;
2163  int partnatts,
2164  i;
2165  PartitionScheme part_scheme;
2166 
2167  /* A partitioned table should have a partition key. */
2168  Assert(partkey != NULL);
2169 
2170  partnatts = partkey->partnatts;
2171 
2172  /* Search for a matching partition scheme and return if found one. */
2173  foreach(lc, root->part_schemes)
2174  {
2175  part_scheme = lfirst(lc);
2176 
2177  /* Match partitioning strategy and number of keys. */
2178  if (partkey->strategy != part_scheme->strategy ||
2179  partnatts != part_scheme->partnatts)
2180  continue;
2181 
2182  /* Match partition key type properties. */
2183  if (memcmp(partkey->partopfamily, part_scheme->partopfamily,
2184  sizeof(Oid) * partnatts) != 0 ||
2185  memcmp(partkey->partopcintype, part_scheme->partopcintype,
2186  sizeof(Oid) * partnatts) != 0 ||
2187  memcmp(partkey->partcollation, part_scheme->partcollation,
2188  sizeof(Oid) * partnatts) != 0)
2189  continue;
2190 
2191  /*
2192  * Length and byval information should match when partopcintype
2193  * matches.
2194  */
2195  Assert(memcmp(partkey->parttyplen, part_scheme->parttyplen,
2196  sizeof(int16) * partnatts) == 0);
2197  Assert(memcmp(partkey->parttypbyval, part_scheme->parttypbyval,
2198  sizeof(bool) * partnatts) == 0);
2199 
2200  /*
2201  * If partopfamily and partopcintype matched, must have the same
2202  * partition comparison functions. Note that we cannot reliably
2203  * Assert the equality of function structs themselves for they might
2204  * be different across PartitionKey's, so just Assert for the function
2205  * OIDs.
2206  */
2207 #ifdef USE_ASSERT_CHECKING
2208  for (i = 0; i < partkey->partnatts; i++)
2209  Assert(partkey->partsupfunc[i].fn_oid ==
2210  part_scheme->partsupfunc[i].fn_oid);
2211 #endif
2212 
2213  /* Found matching partition scheme. */
2214  return part_scheme;
2215  }
2216 
2217  /*
2218  * Did not find matching partition scheme. Create one copying relevant
2219  * information from the relcache. We need to copy the contents of the
2220  * array since the relcache entry may not survive after we have closed the
2221  * relation.
2222  */
2223  part_scheme = (PartitionScheme) palloc0(sizeof(PartitionSchemeData));
2224  part_scheme->strategy = partkey->strategy;
2225  part_scheme->partnatts = partkey->partnatts;
2226 
2227  part_scheme->partopfamily = (Oid *) palloc(sizeof(Oid) * partnatts);
2228  memcpy(part_scheme->partopfamily, partkey->partopfamily,
2229  sizeof(Oid) * partnatts);
2230 
2231  part_scheme->partopcintype = (Oid *) palloc(sizeof(Oid) * partnatts);
2232  memcpy(part_scheme->partopcintype, partkey->partopcintype,
2233  sizeof(Oid) * partnatts);
2234 
2235  part_scheme->partcollation = (Oid *) palloc(sizeof(Oid) * partnatts);
2236  memcpy(part_scheme->partcollation, partkey->partcollation,
2237  sizeof(Oid) * partnatts);
2238 
2239  part_scheme->parttyplen = (int16 *) palloc(sizeof(int16) * partnatts);
2240  memcpy(part_scheme->parttyplen, partkey->parttyplen,
2241  sizeof(int16) * partnatts);
2242 
2243  part_scheme->parttypbyval = (bool *) palloc(sizeof(bool) * partnatts);
2244  memcpy(part_scheme->parttypbyval, partkey->parttypbyval,
2245  sizeof(bool) * partnatts);
2246 
2247  part_scheme->partsupfunc = (FmgrInfo *)
2248  palloc(sizeof(FmgrInfo) * partnatts);
2249  for (i = 0; i < partnatts; i++)
2250  fmgr_info_copy(&part_scheme->partsupfunc[i], &partkey->partsupfunc[i],
2252 
2253  /* Add the partitioning scheme to PlannerInfo. */
2254  root->part_schemes = lappend(root->part_schemes, part_scheme);
2255 
2256  return part_scheme;
2257 }
signed short int16
Definition: c.h:416
Definition: fmgr.h:56
Oid * partopfamily
Definition: partcache.h:33
FmgrInfo * partsupfunc
Definition: partcache.h:35
List * part_schemes
Definition: pathnodes.h:299
PartitionKey RelationGetPartitionKey(Relation rel)
Definition: partcache.c:54
unsigned int Oid
Definition: postgres_ext.h:31
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
Definition: fmgr.c:611
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
struct PartitionSchemeData * PartitionScheme
Definition: pathnodes.h:411
List * lappend(List *list, void *datum)
Definition: list.c:336
Oid * partcollation
Definition: partcache.h:38
void * palloc0(Size size)
Definition: mcxt.c:981
Oid fn_oid
Definition: fmgr.h:59
bool * parttypbyval
Definition: partcache.h:44
#define Assert(condition)
Definition: c.h:792
#define lfirst(lc)
Definition: pg_list.h:169
int16 * parttyplen
Definition: partcache.h:43
struct FmgrInfo * partsupfunc
Definition: pathnodes.h:408
void * palloc(Size size)
Definition: mcxt.c:950
Oid * partopcintype
Definition: partcache.h:34
int i

◆ function_selectivity()

Selectivity function_selectivity ( PlannerInfo root,
Oid  funcid,
List args,
Oid  inputcollid,
bool  is_join,
int  varRelid,
JoinType  jointype,
SpecialJoinInfo sjinfo 
)

Definition at line 1855 of file plancat.c.

References SupportRequestSelectivity::args, generate_unaccent_rules::args, DatumGetPointer, elog, ERROR, SupportRequestSelectivity::funcid, get_func_support(), SupportRequestSelectivity::inputcollid, SupportRequestSelectivity::is_join, SupportRequestSelectivity::jointype, OidFunctionCall1, PointerGetDatum, SupportRequestSelectivity::root, SupportRequestSelectivity::selectivity, SupportRequestSelectivity::sjinfo, T_SupportRequestSelectivity, SupportRequestSelectivity::type, and SupportRequestSelectivity::varRelid.

Referenced by clause_selectivity_ext().

1863 {
1864  RegProcedure prosupport = get_func_support(funcid);
1866  SupportRequestSelectivity *sresult;
1867 
1868  /*
1869  * If no support function is provided, use our historical default
1870  * estimate, 0.3333333. This seems a pretty unprincipled choice, but
1871  * Postgres has been using that estimate for function calls since 1992.
1872  * The hoariness of this behavior suggests that we should not be in too
1873  * much hurry to use another value.
1874  */
1875  if (!prosupport)
1876  return (Selectivity) 0.3333333;
1877 
1879  req.root = root;
1880  req.funcid = funcid;
1881  req.args = args;
1882  req.inputcollid = inputcollid;
1883  req.is_join = is_join;
1884  req.varRelid = varRelid;
1885  req.jointype = jointype;
1886  req.sjinfo = sjinfo;
1887  req.selectivity = -1; /* to catch failure to set the value */
1888 
1889  sresult = (SupportRequestSelectivity *)
1890  DatumGetPointer(OidFunctionCall1(prosupport,
1891  PointerGetDatum(&req)));
1892 
1893  /* If support function fails, use default */
1894  if (sresult != &req)
1895  return (Selectivity) 0.3333333;
1896 
1897  if (req.selectivity < 0.0 || req.selectivity > 1.0)
1898  elog(ERROR, "invalid function selectivity: %f", req.selectivity);
1899 
1900  return (Selectivity) req.selectivity;
1901 }
#define PointerGetDatum(X)
Definition: postgres.h:556
regproc RegProcedure
Definition: c.h:573
double Selectivity
Definition: nodes.h:661
#define ERROR
Definition: elog.h:45
struct PlannerInfo * root
Definition: supportnodes.h:96
struct SpecialJoinInfo * sjinfo
Definition: supportnodes.h:103
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:664
RegProcedure get_func_support(Oid funcid)
Definition: lsyscache.c:1802
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:228

◆ get_function_rows()

double get_function_rows ( PlannerInfo root,
Oid  funcid,
Node node 
)

Definition at line 1978 of file plancat.c.

References Assert, DatumGetPointer, elog, ERROR, SupportRequestRows::funcid, GETSTRUCT, HeapTupleIsValid, SupportRequestRows::node, ObjectIdGetDatum, OidFunctionCall1, OidIsValid, PointerGetDatum, PROCOID, ReleaseSysCache(), SupportRequestRows::root, SupportRequestRows::rows, SearchSysCache1(), T_SupportRequestRows, and SupportRequestRows::type.

Referenced by expression_returns_set_rows().

1979 {
1980  HeapTuple proctup;
1981  Form_pg_proc procform;
1982  double result;
1983 
1984  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
1985  if (!HeapTupleIsValid(proctup))
1986  elog(ERROR, "cache lookup failed for function %u", funcid);
1987  procform = (Form_pg_proc) GETSTRUCT(proctup);
1988 
1989  Assert(procform->proretset); /* else caller error */
1990 
1991  if (OidIsValid(procform->prosupport))
1992  {
1993  SupportRequestRows req;
1994  SupportRequestRows *sresult;
1995 
1996  req.type = T_SupportRequestRows;
1997  req.root = root;
1998  req.funcid = funcid;
1999  req.node = node;
2000 
2001  req.rows = 0; /* just for sanity */
2002 
2003  sresult = (SupportRequestRows *)
2004  DatumGetPointer(OidFunctionCall1(procform->prosupport,
2005  PointerGetDatum(&req)));
2006 
2007  if (sresult == &req)
2008  {
2009  /* Success */
2010  ReleaseSysCache(proctup);
2011  return req.rows;
2012  }
2013  }
2014 
2015  /* No support function, or it failed, so rely on prorows */
2016  result = procform->prorows;
2017 
2018  ReleaseSysCache(proctup);
2019 
2020  return result;
2021 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define PointerGetDatum(X)
Definition: postgres.h:556
#define OidIsValid(objectId)
Definition: c.h:698
struct PlannerInfo * root
Definition: supportnodes.h:163
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:664
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:133
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:792
#define DatumGetPointer(X)
Definition: postgres.h:549
#define elog(elevel,...)
Definition: elog.h:228

◆ get_rel_data_width()

int32 get_rel_data_width ( Relation  rel,
int32 attr_widths 
)

Definition at line 1099 of file plancat.c.

References Assert, get_attavgwidth(), get_typavgwidth(), i, RelationData::rd_att, RelationGetNumberOfAttributes, RelationGetRelid, and TupleDescAttr.

Referenced by estimate_rel_size(), get_relation_data_width(), and table_block_relation_estimate_size().

1100 {
1101  int32 tuple_width = 0;
1102  int i;
1103 
1104  for (i = 1; i <= RelationGetNumberOfAttributes(rel); i++)
1105  {
1106  Form_pg_attribute att = TupleDescAttr(rel->rd_att, i - 1);
1107  int32 item_width;
1108 
1109  if (att->attisdropped)
1110  continue;
1111 
1112  /* use previously cached data, if any */
1113  if (attr_widths != NULL && attr_widths[i] > 0)
1114  {
1115  tuple_width += attr_widths[i];
1116  continue;
1117  }
1118 
1119  /* This should match set_rel_width() in costsize.c */
1120  item_width = get_attavgwidth(RelationGetRelid(rel), i);
1121  if (item_width <= 0)
1122  {
1123  item_width = get_typavgwidth(att->atttypid, att->atttypmod);
1124  Assert(item_width > 0);
1125  }
1126  if (attr_widths != NULL)
1127  attr_widths[i] = item_width;
1128  tuple_width += item_width;
1129  }
1130 
1131  return tuple_width;
1132 }
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:463
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
signed int int32
Definition: c.h:417
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
TupleDesc rd_att
Definition: rel.h:111
int32 get_typavgwidth(Oid typid, int32 typmod)
Definition: lsyscache.c:2498
#define Assert(condition)
Definition: c.h:792
int i
int32 get_attavgwidth(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:3078
#define RelationGetRelid(relation)
Definition: rel.h:457

◆ get_relation_constraints()

static List * get_relation_constraints ( PlannerInfo root,
Oid  relationObjectId,
RelOptInfo rel,
bool  include_noinherit,
bool  include_notnull,
bool  include_partition 
)
static

Definition at line 1181 of file plancat.c.

References NullTest::arg, NullTest::argisrow, canonicalize_qual(), ConstrCheck::ccbin, ConstrCheck::ccnoinherit, ConstrCheck::ccvalid, ChangeVarNodes(), TupleConstr::check, TupleDescData::constr, eval_const_expressions(), TupleConstr::has_not_null, i, IS_NOT_NULL, lappend(), list_concat(), NullTest::location, make_ands_implicit(), makeNode, makeVar(), TupleDescData::natts, NIL, NoLock, NullTest::nulltesttype, TupleConstr::num_check, RelOptInfo::partition_qual, RelationData::rd_att, RelationData::rd_rel, RelOptInfo::relid, set_baserel_partition_constraint(), stringToNode(), table_close(), table_open(), and TupleDescAttr.

Referenced by relation_excluded_by_constraints().

1186 {
1187  List *result = NIL;
1188  Index varno = rel->relid;
1189  Relation relation;
1190  TupleConstr *constr;
1191 
1192  /*
1193  * We assume the relation has already been safely locked.
1194  */
1195  relation = table_open(relationObjectId, NoLock);
1196 
1197  constr = relation->rd_att->constr;
1198  if (constr != NULL)
1199  {
1200  int num_check = constr->num_check;
1201  int i;
1202 
1203  for (i = 0; i < num_check; i++)
1204  {
1205  Node *cexpr;
1206 
1207  /*
1208  * If this constraint hasn't been fully validated yet, we must
1209  * ignore it here. Also ignore if NO INHERIT and we weren't told
1210  * that that's safe.
1211  */
1212  if (!constr->check[i].ccvalid)
1213  continue;
1214  if (constr->check[i].ccnoinherit && !include_noinherit)
1215  continue;
1216 
1217  cexpr = stringToNode(constr->check[i].ccbin);
1218 
1219  /*
1220  * Run each expression through const-simplification and
1221  * canonicalization. This is not just an optimization, but is
1222  * necessary, because we will be comparing it to
1223  * similarly-processed qual clauses, and may fail to detect valid
1224  * matches without this. This must match the processing done to
1225  * qual clauses in preprocess_expression()! (We can skip the
1226  * stuff involving subqueries, however, since we don't allow any
1227  * in check constraints.)
1228  */
1229  cexpr = eval_const_expressions(root, cexpr);
1230 
1231  cexpr = (Node *) canonicalize_qual((Expr *) cexpr, true);
1232 
1233  /* Fix Vars to have the desired varno */
1234  if (varno != 1)
1235  ChangeVarNodes(cexpr, 1, varno, 0);
1236 
1237  /*
1238  * Finally, convert to implicit-AND format (that is, a List) and
1239  * append the resulting item(s) to our output list.
1240  */
1241  result = list_concat(result,
1242  make_ands_implicit((Expr *) cexpr));
1243  }
1244 
1245  /* Add NOT NULL constraints in expression form, if requested */
1246  if (include_notnull && constr->has_not_null)
1247  {
1248  int natts = relation->rd_att->natts;
1249 
1250  for (i = 1; i <= natts; i++)
1251  {
1252  Form_pg_attribute att = TupleDescAttr(relation->rd_att, i - 1);
1253 
1254  if (att->attnotnull && !att->attisdropped)
1255  {
1256  NullTest *ntest = makeNode(NullTest);
1257 
1258  ntest->arg = (Expr *) makeVar(varno,
1259  i,
1260  att->atttypid,
1261  att->atttypmod,
1262  att->attcollation,
1263  0);
1264  ntest->nulltesttype = IS_NOT_NULL;
1265 
1266  /*
1267  * argisrow=false is correct even for a composite column,
1268  * because attnotnull does not represent a SQL-spec IS NOT
1269  * NULL test in such a case, just IS DISTINCT FROM NULL.
1270  */
1271  ntest->argisrow = false;
1272  ntest->location = -1;
1273  result = lappend(result, ntest);
1274  }
1275  }
1276  }
1277  }
1278 
1279  /*
1280  * Add partitioning constraints, if requested.
1281  */
1282  if (include_partition && relation->rd_rel->relispartition)
1283  {
1284  /* make sure rel->partition_qual is set */
1285  set_baserel_partition_constraint(relation, rel);
1286  result = list_concat(result, rel->partition_qual);
1287  }
1288 
1289  table_close(relation, NoLock);
1290 
1291  return result;
1292 }
#define NIL
Definition: pg_list.h:65
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
Definition: nodes.h:528
List * list_concat(List *list1, const List *list2)
Definition: list.c:530
void * stringToNode(const char *str)
Definition: read.c:89
Node * eval_const_expressions(PlannerInfo *root, Node *node)
Definition: clauses.c:2022
Form_pg_class rd_rel
Definition: rel.h:110
Expr * arg
Definition: primnodes.h:1243
#define NoLock
Definition: lockdefs.h:34
TupleConstr * constr
Definition: tupdesc.h:85
Expr * canonicalize_qual(Expr *qual, bool is_check)
Definition: prepqual.c:292
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Index relid
Definition: pathnodes.h:694
List * lappend(List *list, void *datum)
Definition: list.c:336
List * make_ands_implicit(Expr *clause)
Definition: makefuncs.c:719
unsigned int Index
Definition: c.h:537
TupleDesc rd_att
Definition: rel.h:111
NullTestType nulltesttype
Definition: primnodes.h:1244
uint16 num_check
Definition: tupdesc.h:43
static void set_baserel_partition_constraint(Relation relation, RelOptInfo *rel)
Definition: plancat.c:2334
#define makeNode(_type_)
Definition: nodes.h:576
int location
Definition: primnodes.h:1246
int i
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
Definition: rewriteManip.c:610
bool argisrow
Definition: primnodes.h:1245
ConstrCheck * check
Definition: tupdesc.h:40
bool ccvalid
Definition: tupdesc.h:32
List * partition_qual
Definition: pathnodes.h:750
bool has_not_null
Definition: tupdesc.h:44
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
Definition: pg_list.h:50
char * ccbin
Definition: tupdesc.h:31
bool ccnoinherit
Definition: tupdesc.h:33

◆ get_relation_data_width()

int32 get_relation_data_width ( Oid  relid,
int32 attr_widths 
)

Definition at line 1141 of file plancat.c.

References get_rel_data_width(), NoLock, table_close(), and table_open().

Referenced by plan_cluster_use_sort(), and set_rel_width().

1142 {
1143  int32 result;
1144  Relation relation;
1145 
1146  /* As above, assume relation is already locked */
1147  relation = table_open(relid, NoLock);
1148 
1149  result = get_rel_data_width(relation, attr_widths);
1150 
1151  table_close(relation, NoLock);
1152 
1153  return result;
1154 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
signed int int32
Definition: c.h:417
#define NoLock
Definition: lockdefs.h:34
int32 get_rel_data_width(Relation rel, int32 *attr_widths)
Definition: plancat.c:1099
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ get_relation_foreign_keys()

static void get_relation_foreign_keys ( PlannerInfo root,
RelOptInfo rel,
Relation  relation,
bool  inhparent 
)
static

Definition at line 498 of file plancat.c.

References Assert, ForeignKeyOptInfo::con_relid, ForeignKeyCacheInfo::confkey, ForeignKeyOptInfo::confkey, ForeignKeyCacheInfo::confrelid, ForeignKeyCacheInfo::conkey, ForeignKeyOptInfo::conkey, ForeignKeyCacheInfo::conpfeqop, ForeignKeyOptInfo::conpfeqop, ForeignKeyCacheInfo::conrelid, ForeignKeyOptInfo::eclass, ForeignKeyOptInfo::fk_eclass_member, PlannerInfo::fkey_list, RangeTblEntry::inh, lappend(), lfirst, list_length(), makeNode, ForeignKeyOptInfo::nconst_ec, ForeignKeyCacheInfo::nkeys, ForeignKeyOptInfo::nkeys, ForeignKeyOptInfo::nmatched_ec, ForeignKeyOptInfo::nmatched_rcols, ForeignKeyOptInfo::nmatched_ri, PlannerInfo::parse, ForeignKeyOptInfo::ref_relid, RelationGetFKeyList(), RelationGetRelid, RelOptInfo::relid, RangeTblEntry::relid, RELOPT_BASEREL, RelOptInfo::reloptkind, ForeignKeyOptInfo::rinfos, Query::rtable, RTE_RELATION, and RangeTblEntry::rtekind.

Referenced by get_relation_info().

500 {
501  List *rtable = root->parse->rtable;
502  List *cachedfkeys;
503  ListCell *lc;
504 
505  /*
506  * If it's not a baserel, we don't care about its FKs. Also, if the query
507  * references only a single relation, we can skip the lookup since no FKs
508  * could satisfy the requirements below.
509  */
510  if (rel->reloptkind != RELOPT_BASEREL ||
511  list_length(rtable) < 2)
512  return;
513 
514  /*
515  * If it's the parent of an inheritance tree, ignore its FKs. We could
516  * make useful FK-based deductions if we found that all members of the
517  * inheritance tree have equivalent FK constraints, but detecting that
518  * would require code that hasn't been written.
519  */
520  if (inhparent)
521  return;
522 
523  /*
524  * Extract data about relation's FKs from the relcache. Note that this
525  * list belongs to the relcache and might disappear in a cache flush, so
526  * we must not do any further catalog access within this function.
527  */
528  cachedfkeys = RelationGetFKeyList(relation);
529 
530  /*
531  * Figure out which FKs are of interest for this query, and create
532  * ForeignKeyOptInfos for them. We want only FKs that reference some
533  * other RTE of the current query. In queries containing self-joins,
534  * there might be more than one other RTE for a referenced table, and we
535  * should make a ForeignKeyOptInfo for each occurrence.
536  *
537  * Ideally, we would ignore RTEs that correspond to non-baserels, but it's
538  * too hard to identify those here, so we might end up making some useless
539  * ForeignKeyOptInfos. If so, match_foreign_keys_to_quals() will remove
540  * them again.
541  */
542  foreach(lc, cachedfkeys)
543  {
544  ForeignKeyCacheInfo *cachedfk = (ForeignKeyCacheInfo *) lfirst(lc);
545  Index rti;
546  ListCell *lc2;
547 
548  /* conrelid should always be that of the table we're considering */
549  Assert(cachedfk->conrelid == RelationGetRelid(relation));
550 
551  /* Scan to find other RTEs matching confrelid */
552  rti = 0;
553  foreach(lc2, rtable)
554  {
555  RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc2);
556  ForeignKeyOptInfo *info;
557 
558  rti++;
559  /* Ignore if not the correct table */
560  if (rte->rtekind != RTE_RELATION ||
561  rte->relid != cachedfk->confrelid)
562  continue;
563  /* Ignore if it's an inheritance parent; doesn't really match */
564  if (rte->inh)
565  continue;
566  /* Ignore self-referential FKs; we only care about joins */
567  if (rti == rel->relid)
568  continue;
569 
570  /* OK, let's make an entry */
571  info = makeNode(ForeignKeyOptInfo);
572  info->con_relid = rel->relid;
573  info->ref_relid = rti;
574  info->nkeys = cachedfk->nkeys;
575  memcpy(info->conkey, cachedfk->conkey, sizeof(info->conkey));
576  memcpy(info->confkey, cachedfk->confkey, sizeof(info->confkey));
577  memcpy(info->conpfeqop, cachedfk->conpfeqop, sizeof(info->conpfeqop));
578  /* zero out fields to be filled by match_foreign_keys_to_quals */
579  info->nmatched_ec = 0;
580  info->nconst_ec = 0;
581  info->nmatched_rcols = 0;
582  info->nmatched_ri = 0;
583  memset(info->eclass, 0, sizeof(info->eclass));
584  memset(info->fk_eclass_member, 0, sizeof(info->fk_eclass_member));
585  memset(info->rinfos, 0, sizeof(info->rinfos));
586 
587  root->fkey_list = lappend(root->fkey_list, info);
588  }
589  }
590 }
Query * parse
Definition: pathnodes.h:173
RelOptKind reloptkind
Definition: pathnodes.h:663
AttrNumber conkey[INDEX_MAX_KEYS]
Definition: rel.h:263
List * fkey_list
Definition: pathnodes.h:290
List * rtable
Definition: parsenodes.h:137
Oid conpfeqop[INDEX_MAX_KEYS]
Definition: pathnodes.h:890
Index relid
Definition: pathnodes.h:694
List * lappend(List *list, void *datum)
Definition: list.c:336
struct EquivalenceClass * eclass[INDEX_MAX_KEYS]
Definition: pathnodes.h:898
struct EquivalenceMember * fk_eclass_member[INDEX_MAX_KEYS]
Definition: pathnodes.h:900
AttrNumber conkey[INDEX_MAX_KEYS]
Definition: pathnodes.h:888
unsigned int Index
Definition: c.h:537
#define makeNode(_type_)
Definition: nodes.h:576
Oid conpfeqop[INDEX_MAX_KEYS]
Definition: rel.h:265
#define Assert(condition)
Definition: c.h:792
#define lfirst(lc)
Definition: pg_list.h:169
static int list_length(const List *l)
Definition: pg_list.h:149
RTEKind rtekind
Definition: parsenodes.h:981
List * RelationGetFKeyList(Relation relation)
Definition: relcache.c:4417
AttrNumber confkey[INDEX_MAX_KEYS]
Definition: rel.h:264
Definition: pg_list.h:50
AttrNumber confkey[INDEX_MAX_KEYS]
Definition: pathnodes.h:889
#define RelationGetRelid(relation)
Definition: rel.h:457
List * rinfos[INDEX_MAX_KEYS]
Definition: pathnodes.h:902

◆ get_relation_info()

void get_relation_info ( PlannerInfo root,
Oid  relationObjectId,
bool  inhparent,
RelOptInfo rel 
)

Definition at line 113 of file plancat.c.

References _bt_getrootheight(), RelOptInfo::allvisfrac, IndexOptInfo::amcanmarkpos, IndexAmRoutine::amcanorder, IndexAmRoutine::amcanorderbyop, IndexOptInfo::amcanorderbyop, IndexAmRoutine::amcanparallel, IndexOptInfo::amcanparallel, IndexAmRoutine::amcostestimate, IndexOptInfo::amcostestimate, IndexAmRoutine::amgetbitmap, IndexAmRoutine::amgettuple, IndexOptInfo::amhasgetbitmap, IndexOptInfo::amhasgettuple, IndexAmRoutine::ammarkpos, IndexAmRoutine::amoptionalkey, IndexOptInfo::amoptionalkey, IndexAmRoutine::amrestrpos, IndexAmRoutine::amsearcharray, IndexOptInfo::amsearcharray, IndexAmRoutine::amsearchnulls, IndexOptInfo::amsearchnulls, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, BTLessStrategyNumber, build_index_tlist(), IndexOptInfo::canreturn, ChangeVarNodes(), ereport, errcode(), errmsg(), ERROR, estimate_rel_size(), RelOptInfo::fdwroutine, FirstLowInvalidHeapAttributeNumber, get_opfamily_member(), get_ordering_op_properties(), get_relation_foreign_keys(), get_relation_info_hook, get_relation_statistics(), GetFdwRoutineForRelation(), GetForeignServerIdByRelId(), PlannerInfo::glob, HeapTupleHeaderGetXmin, IndexOptInfo::hypothetical, i, IgnoreSystemIndexes, IndexOptInfo::immediate, index_can_return(), index_check_collation_versions(), index_close(), index_open(), IndexOptInfo::indexcollations, IndexOptInfo::indexkeys, RelOptInfo::indexlist, IndexOptInfo::indexoid, IndexOptInfo::indexprs, IndexOptInfo::indextlist, IndexOptInfo::indpred, IndexOptInfo::indrestrictinfo, InvalidOid, IsSystemRelation(), lcons(), lfirst_oid, list_free(), makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, IndexOptInfo::ncolumns, NIL, IndexOptInfo::nkeycolumns, NoLock, IndexOptInfo::nulls_first, OidIsValid, IndexOptInfo::opcintype, IndexOptInfo::opclassoptions, IndexOptInfo::opfamily, RelOptInfo::pages, IndexOptInfo::pages, palloc(), palloc0(), IndexOptInfo::predOK, RelationData::rd_indam, RelationData::rd_indcollation, RelationData::rd_index, RelationData::rd_indextuple, RelationData::rd_indoption, RelationData::rd_opcintype, RelationData::rd_opfamily, RelationData::rd_rel, RelationData::rd_tableam, RelationData::rd_version_checked, RecoveryInProgress(), IndexOptInfo::rel, RelOptInfo::rel_parallel_workers, IndexOptInfo::relam, RelationGetForm, RelationGetIndexAttOptions(), RelationGetIndexExpressions(), RelationGetIndexList(), RelationGetIndexPredicate(), RelationGetNumberOfAttributes, RelationGetNumberOfBlocks, RelationGetParallelWorkers, RelationGetRelid, RelationNeedsWAL, RelOptInfo::relid, RangeTblEntry::rellockmode, RelOptInfo::reltablespace, IndexOptInfo::reltablespace, IndexOptInfo::reverse_sort, TableAmRoutine::scan_bitmap_next_block, RelOptInfo::serverid, set_relation_partition_info(), PlannerInfo::simple_rte_array, IndexOptInfo::sortopfamily, RelOptInfo::statlist, HeapTupleData::t_data, table_close(), table_open(), TransactionIdPrecedes(), TransactionXmin, PlannerGlobal::transientPlan, IndexOptInfo::tree_height, RelOptInfo::tuples, IndexOptInfo::tuples, and IndexOptInfo::unique.

Referenced by build_simple_rel().

115 {
116  Index varno = rel->relid;
117  Relation relation;
118  bool hasindex;
119  List *indexinfos = NIL;
120 
121  /*
122  * We need not lock the relation since it was already locked, either by
123  * the rewriter or when expand_inherited_rtentry() added it to the query's
124  * rangetable.
125  */
126  relation = table_open(relationObjectId, NoLock);
127 
128  /* Temporary and unlogged relations are inaccessible during recovery. */
129  if (!RelationNeedsWAL(relation) && RecoveryInProgress())
130  ereport(ERROR,
131  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
132  errmsg("cannot access temporary or unlogged relations during recovery")));
133 
135  rel->max_attr = RelationGetNumberOfAttributes(relation);
136  rel->reltablespace = RelationGetForm(relation)->reltablespace;
137 
138  Assert(rel->max_attr >= rel->min_attr);
139  rel->attr_needed = (Relids *)
140  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
141  rel->attr_widths = (int32 *)
142  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
143 
144  /*
145  * Estimate relation size --- unless it's an inheritance parent, in which
146  * case the size we want is not the rel's own size but the size of its
147  * inheritance tree. That will be computed in set_append_rel_size().
148  */
149  if (!inhparent)
150  estimate_rel_size(relation, rel->attr_widths - rel->min_attr,
151  &rel->pages, &rel->tuples, &rel->allvisfrac);
152 
153  /* Retrieve the parallel_workers reloption, or -1 if not set. */
155 
156  /*
157  * Make list of indexes. Ignore indexes on system catalogs if told to.
158  * Don't bother with indexes for an inheritance parent, either.
159  */
160  if (inhparent ||
161  (IgnoreSystemIndexes && IsSystemRelation(relation)))
162  hasindex = false;
163  else
164  hasindex = relation->rd_rel->relhasindex;
165 
166  if (hasindex)
167  {
168  List *indexoidlist;
169  LOCKMODE lmode;
170  ListCell *l;
171 
172  indexoidlist = RelationGetIndexList(relation);
173 
174  /*
175  * For each index, we get the same type of lock that the executor will
176  * need, and do not release it. This saves a couple of trips to the
177  * shared lock manager while not creating any real loss of
178  * concurrency, because no schema changes could be happening on the
179  * index while we hold lock on the parent rel, and no lock type used
180  * for queries blocks any other kind of index operation.
181  */
182  lmode = root->simple_rte_array[varno]->rellockmode;
183 
184  foreach(l, indexoidlist)
185  {
186  Oid indexoid = lfirst_oid(l);
187  Relation indexRelation;
189  IndexAmRoutine *amroutine;
190  IndexOptInfo *info;
191  int ncolumns,
192  nkeycolumns;
193  int i;
194 
195  /*
196  * Extract info from the relation descriptor for the index.
197  */
198  indexRelation = index_open(indexoid, lmode);
199  index = indexRelation->rd_index;
200 
201  /* Warn if any dependent collations' versions have moved. */
202  if (!IsSystemRelation(relation) &&
203  !indexRelation->rd_version_checked)
204  {
206  indexRelation->rd_version_checked = true;
207  }
208 
209  /*
210  * Ignore invalid indexes, since they can't safely be used for
211  * queries. Note that this is OK because the data structure we
212  * are constructing is only used by the planner --- the executor
213  * still needs to insert into "invalid" indexes, if they're marked
214  * indisready.
215  */
216  if (!index->indisvalid)
217  {
218  index_close(indexRelation, NoLock);
219  continue;
220  }
221 
222  /*
223  * Ignore partitioned indexes, since they are not usable for
224  * queries.
225  */
226  if (indexRelation->rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
227  {
228  index_close(indexRelation, NoLock);
229  continue;
230  }
231 
232  /*
233  * If the index is valid, but cannot yet be used, ignore it; but
234  * mark the plan we are generating as transient. See
235  * src/backend/access/heap/README.HOT for discussion.
236  */
237  if (index->indcheckxmin &&
240  {
241  root->glob->transientPlan = true;
242  index_close(indexRelation, NoLock);
243  continue;
244  }
245 
246  info = makeNode(IndexOptInfo);
247 
248  info->indexoid = index->indexrelid;
249  info->reltablespace =
250  RelationGetForm(indexRelation)->reltablespace;
251  info->rel = rel;
252  info->ncolumns = ncolumns = index->indnatts;
253  info->nkeycolumns = nkeycolumns = index->indnkeyatts;
254 
255  info->indexkeys = (int *) palloc(sizeof(int) * ncolumns);
256  info->indexcollations = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
257  info->opfamily = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
258  info->opcintype = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
259  info->canreturn = (bool *) palloc(sizeof(bool) * ncolumns);
260 
261  for (i = 0; i < ncolumns; i++)
262  {
263  info->indexkeys[i] = index->indkey.values[i];
264  info->canreturn[i] = index_can_return(indexRelation, i + 1);
265  }
266 
267  for (i = 0; i < nkeycolumns; i++)
268  {
269  info->opfamily[i] = indexRelation->rd_opfamily[i];
270  info->opcintype[i] = indexRelation->rd_opcintype[i];
271  info->indexcollations[i] = indexRelation->rd_indcollation[i];
272  }
273 
274  info->relam = indexRelation->rd_rel->relam;
275 
276  /* We copy just the fields we need, not all of rd_indam */
277  amroutine = indexRelation->rd_indam;
278  info->amcanorderbyop = amroutine->amcanorderbyop;
279  info->amoptionalkey = amroutine->amoptionalkey;
280  info->amsearcharray = amroutine->amsearcharray;
281  info->amsearchnulls = amroutine->amsearchnulls;
282  info->amcanparallel = amroutine->amcanparallel;
283  info->amhasgettuple = (amroutine->amgettuple != NULL);
284  info->amhasgetbitmap = amroutine->amgetbitmap != NULL &&
285  relation->rd_tableam->scan_bitmap_next_block != NULL;
286  info->amcanmarkpos = (amroutine->ammarkpos != NULL &&
287  amroutine->amrestrpos != NULL);
288  info->amcostestimate = amroutine->amcostestimate;
289  Assert(info->amcostestimate != NULL);
290 
291  /* Fetch index opclass options */
292  info->opclassoptions = RelationGetIndexAttOptions(indexRelation, true);
293 
294  /*
295  * Fetch the ordering information for the index, if any.
296  */
297  if (info->relam == BTREE_AM_OID)
298  {
299  /*
300  * If it's a btree index, we can use its opfamily OIDs
301  * directly as the sort ordering opfamily OIDs.
302  */
303  Assert(amroutine->amcanorder);
304 
305  info->sortopfamily = info->opfamily;
306  info->reverse_sort = (bool *) palloc(sizeof(bool) * nkeycolumns);
307  info->nulls_first = (bool *) palloc(sizeof(bool) * nkeycolumns);
308 
309  for (i = 0; i < nkeycolumns; i++)
310  {
311  int16 opt = indexRelation->rd_indoption[i];
312 
313  info->reverse_sort[i] = (opt & INDOPTION_DESC) != 0;
314  info->nulls_first[i] = (opt & INDOPTION_NULLS_FIRST) != 0;
315  }
316  }
317  else if (amroutine->amcanorder)
318  {
319  /*
320  * Otherwise, identify the corresponding btree opfamilies by
321  * trying to map this index's "<" operators into btree. Since
322  * "<" uniquely defines the behavior of a sort order, this is
323  * a sufficient test.
324  *
325  * XXX This method is rather slow and also requires the
326  * undesirable assumption that the other index AM numbers its
327  * strategies the same as btree. It'd be better to have a way
328  * to explicitly declare the corresponding btree opfamily for
329  * each opfamily of the other index type. But given the lack
330  * of current or foreseeable amcanorder index types, it's not
331  * worth expending more effort on now.
332  */
333  info->sortopfamily = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
334  info->reverse_sort = (bool *) palloc(sizeof(bool) * nkeycolumns);
335  info->nulls_first = (bool *) palloc(sizeof(bool) * nkeycolumns);
336 
337  for (i = 0; i < nkeycolumns; i++)
338  {
339  int16 opt = indexRelation->rd_indoption[i];
340  Oid ltopr;
341  Oid btopfamily;
342  Oid btopcintype;
343  int16 btstrategy;
344 
345  info->reverse_sort[i] = (opt & INDOPTION_DESC) != 0;
346  info->nulls_first[i] = (opt & INDOPTION_NULLS_FIRST) != 0;
347 
348  ltopr = get_opfamily_member(info->opfamily[i],
349  info->opcintype[i],
350  info->opcintype[i],
352  if (OidIsValid(ltopr) &&
354  &btopfamily,
355  &btopcintype,
356  &btstrategy) &&
357  btopcintype == info->opcintype[i] &&
358  btstrategy == BTLessStrategyNumber)
359  {
360  /* Successful mapping */
361  info->sortopfamily[i] = btopfamily;
362  }
363  else
364  {
365  /* Fail ... quietly treat index as unordered */
366  info->sortopfamily = NULL;
367  info->reverse_sort = NULL;
368  info->nulls_first = NULL;
369  break;
370  }
371  }
372  }
373  else
374  {
375  info->sortopfamily = NULL;
376  info->reverse_sort = NULL;
377  info->nulls_first = NULL;
378  }
379 
380  /*
381  * Fetch the index expressions and predicate, if any. We must
382  * modify the copies we obtain from the relcache to have the
383  * correct varno for the parent relation, so that they match up
384  * correctly against qual clauses.
385  */
386  info->indexprs = RelationGetIndexExpressions(indexRelation);
387  info->indpred = RelationGetIndexPredicate(indexRelation);
388  if (info->indexprs && varno != 1)
389  ChangeVarNodes((Node *) info->indexprs, 1, varno, 0);
390  if (info->indpred && varno != 1)
391  ChangeVarNodes((Node *) info->indpred, 1, varno, 0);
392 
393  /* Build targetlist using the completed indexprs data */
394  info->indextlist = build_index_tlist(root, info, relation);
395 
396  info->indrestrictinfo = NIL; /* set later, in indxpath.c */
397  info->predOK = false; /* set later, in indxpath.c */
398  info->unique = index->indisunique;
399  info->immediate = index->indimmediate;
400  info->hypothetical = false;
401 
402  /*
403  * Estimate the index size. If it's not a partial index, we lock
404  * the number-of-tuples estimate to equal the parent table; if it
405  * is partial then we have to use the same methods as we would for
406  * a table, except we can be sure that the index is not larger
407  * than the table.
408  */
409  if (info->indpred == NIL)
410  {
411  info->pages = RelationGetNumberOfBlocks(indexRelation);
412  info->tuples = rel->tuples;
413  }
414  else
415  {
416  double allvisfrac; /* dummy */
417 
418  estimate_rel_size(indexRelation, NULL,
419  &info->pages, &info->tuples, &allvisfrac);
420  if (info->tuples > rel->tuples)
421  info->tuples = rel->tuples;
422  }
423 
424  if (info->relam == BTREE_AM_OID)
425  {
426  /* For btrees, get tree height while we have the index open */
427  info->tree_height = _bt_getrootheight(indexRelation);
428  }
429  else
430  {
431  /* For other index types, just set it to "unknown" for now */
432  info->tree_height = -1;
433  }
434 
435  index_close(indexRelation, NoLock);
436 
437  /*
438  * We've historically used lcons() here. It'd make more sense to
439  * use lappend(), but that causes the planner to change behavior
440  * in cases where two indexes seem equally attractive. For now,
441  * stick with lcons() --- few tables should have so many indexes
442  * that the O(N^2) behavior of lcons() is really a problem.
443  */
444  indexinfos = lcons(info, indexinfos);
445  }
446 
447  list_free(indexoidlist);
448  }
449 
450  rel->indexlist = indexinfos;
451 
452  rel->statlist = get_relation_statistics(rel, relation);
453 
454  /* Grab foreign-table info using the relcache, while we have it */
455  if (relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
456  {
458  rel->fdwroutine = GetFdwRoutineForRelation(relation, true);
459  }
460  else
461  {
462  rel->serverid = InvalidOid;
463  rel->fdwroutine = NULL;
464  }
465 
466  /* Collect info about relation's foreign keys, if relevant */
467  get_relation_foreign_keys(root, rel, relation, inhparent);
468 
469  /*
470  * Collect info about relation's partitioning scheme, if any. Only
471  * inheritance parents may be partitioned.
472  */
473  if (inhparent && relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
474  set_relation_partition_info(root, rel, relation);
475 
476  table_close(relation, NoLock);
477 
478  /*
479  * Allow a plugin to editorialize on the info we obtained from the
480  * catalogs. Actions might include altering the assumed relation size,
481  * removing an index, or adding a hypothetical index to the indexlist.
482  */
484  (*get_relation_info_hook) (root, relationObjectId, inhparent, rel);
485 }
signed short int16
Definition: c.h:416
#define NIL
Definition: pg_list.h:65
struct IndexAmRoutine * rd_indam
Definition: rel.h:189
List * statlist
Definition: pathnodes.h:704
int16 * rd_indoption
Definition: rel.h:194
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
static List * get_relation_statistics(RelOptInfo *rel, Relation relation)
Definition: plancat.c:1303
Oid * indexcollations
Definition: pathnodes.h:832
Relids * attr_needed
Definition: pathnodes.h:699
bool IsSystemRelation(Relation relation)
Definition: catalog.c:66
amgettuple_function amgettuple
Definition: amapi.h:273
int _bt_getrootheight(Relation rel)
Definition: nbtpage.c:610
int LOCKMODE
Definition: lockdefs.h:26
bool amcanorderbyop
Definition: amapi.h:222
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:463
List * indextlist
Definition: pathnodes.h:846
#define RelationGetForm(relation)
Definition: rel.h:451
double tuples
Definition: pathnodes.h:706
Oid reltablespace
Definition: pathnodes.h:695
Definition: nodes.h:528
Oid * sortopfamily
Definition: pathnodes.h:835
int errcode(int sqlerrcode)
Definition: elog.c:704
Oid reltablespace
Definition: pathnodes.h:819
bool IgnoreSystemIndexes
Definition: miscinit.c:79
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
bool hypothetical
Definition: pathnodes.h:857
bool immediate
Definition: pathnodes.h:856
double tuples
Definition: pathnodes.h:824
Form_pg_class rd_rel
Definition: rel.h:110
unsigned int Oid
Definition: postgres_ext.h:31
bool RecoveryInProgress(void)
Definition: xlog.c:8148
int tree_height
Definition: pathnodes.h:825
#define OidIsValid(objectId)
Definition: c.h:698
bool amoptionalkey
Definition: amapi.h:230
double allvisfrac
Definition: pathnodes.h:707
signed int int32
Definition: c.h:417
List * RelationGetIndexPredicate(Relation relation)
Definition: relcache.c:4873
struct HeapTupleData * rd_indextuple
Definition: rel.h:177
TransactionId TransactionXmin
Definition: snapmgr.c:112
HeapTupleHeader t_data
Definition: htup.h:68
Definition: type.h:89
BlockNumber pages
Definition: pathnodes.h:823
bool index_can_return(Relation indexRelation, int attno)
Definition: indexam.c:731
Form_pg_index rd_index
Definition: rel.h:175
RelOptInfo * rel
Definition: pathnodes.h:820
bool amoptionalkey
Definition: pathnodes.h:861
amgetbitmap_function amgetbitmap
Definition: amapi.h:274
Oid * rd_indcollation
Definition: rel.h:200
#define ERROR
Definition: elog.h:45
bool rd_version_checked
Definition: rel.h:66
bool(* scan_bitmap_next_block)(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:759
amcostestimate_function amcostestimate
Definition: amapi.h:265
#define NoLock
Definition: lockdefs.h:34
bool amcanorderbyop
Definition: pathnodes.h:860
List * RelationGetIndexExpressions(Relation relation)
Definition: relcache.c:4760
PlannerGlobal * glob
Definition: pathnodes.h:175
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:719
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
Definition: lsyscache.c:164
static void set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel, Relation relation)
Definition: plancat.c:2133
get_relation_info_hook_type get_relation_info_hook
Definition: plancat.c:60
Oid * rd_opfamily
Definition: rel.h:190
void estimate_rel_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: plancat.c:961
void(* amcostestimate)()
Definition: pathnodes.h:869
bool amhasgetbitmap
Definition: pathnodes.h:865
bool amcanparallel
Definition: amapi.h:242
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
Index relid
Definition: pathnodes.h:694
RangeTblEntry ** simple_rte_array
Definition: pathnodes.h:205
Oid serverid
Definition: pathnodes.h:715
FormData_pg_index * Form_pg_index
Definition: pg_index.h:68
bool amsearchnulls
Definition: amapi.h:234
List * indrestrictinfo
Definition: pathnodes.h:848
void * palloc0(Size size)
Definition: mcxt.c:981
int rel_parallel_workers
Definition: pathnodes.h:712
const struct TableAmRoutine * rd_tableam
Definition: rel.h:172
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:211
unsigned int Index
Definition: c.h:537
List * indexlist
Definition: pathnodes.h:703
bool amsearcharray
Definition: amapi.h:232
bool amhasgettuple
Definition: pathnodes.h:864
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
List * lcons(void *datum, List *list)
Definition: list.c:468
#define makeNode(_type_)
Definition: nodes.h:576
void index_check_collation_versions(Oid relid)
Definition: index.c:1331
BlockNumber pages
Definition: pathnodes.h:705
#define Assert(condition)
Definition: c.h:792
static void get_relation_foreign_keys(PlannerInfo *root, RelOptInfo *rel, Relation relation, bool inhparent)
Definition: plancat.c:498
#define HeapTupleHeaderGetXmin(tup)
Definition: htup_details.h:313
Oid GetForeignServerIdByRelId(Oid relid)
Definition: foreign.c:340
bool get_ordering_op_properties(Oid opno, Oid *opfamily, Oid *opcintype, int16 *strategy)
Definition: lsyscache.c:205
bool amsearcharray
Definition: pathnodes.h:862
ammarkpos_function ammarkpos
Definition: amapi.h:276
bool amcanorder
Definition: amapi.h:220
int nkeycolumns
Definition: pathnodes.h:829
#define RelationNeedsWAL(relation)
Definition: rel.h:563
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4526
Oid * opcintype
Definition: pathnodes.h:834
Bitmapset * Relids
Definition: pathnodes.h:28
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
bool amcanmarkpos
Definition: pathnodes.h:867
Oid * opfamily
Definition: pathnodes.h:833
AttrNumber max_attr
Definition: pathnodes.h:698
void * palloc(Size size)
Definition: mcxt.c:950
int errmsg(const char *fmt,...)
Definition: elog.c:915
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:427
void list_free(List *list)
Definition: list.c:1391
int i
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
Definition: rewriteManip.c:610
#define RelationGetParallelWorkers(relation, defaultpw)
Definition: rel.h:360
static List * build_index_tlist(PlannerInfo *root, IndexOptInfo *index, Relation heapRelation)
Definition: plancat.c:1713
int * indexkeys
Definition: pathnodes.h:830
bool * canreturn
Definition: pathnodes.h:839
bytea ** RelationGetIndexAttOptions(Relation relation, bool copy)
Definition: relcache.c:5448
bool amsearchnulls
Definition: pathnodes.h:863
Oid * rd_opcintype
Definition: rel.h:191
bool * nulls_first
Definition: pathnodes.h:837
bool * reverse_sort
Definition: pathnodes.h:836
bytea ** opclassoptions
Definition: pathnodes.h:838
#define BTLessStrategyNumber
Definition: stratnum.h:29
List * indpred
Definition: pathnodes.h:844
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
int32 * attr_widths
Definition: pathnodes.h:700
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:457
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132
bool amcanparallel
Definition: pathnodes.h:866
#define lfirst_oid(lc)
Definition: pg_list.h:171
List * indexprs
Definition: pathnodes.h:843
bool transientPlan
Definition: pathnodes.h:133
amrestrpos_function amrestrpos
Definition: amapi.h:277
AttrNumber min_attr
Definition: pathnodes.h:697

◆ get_relation_statistics()

static List * get_relation_statistics ( RelOptInfo rel,
Relation  relation 
)
static

Definition at line 1303 of file plancat.c.

References bms_add_member(), bms_copy(), bms_free(), elog, ERROR, GETSTRUCT, HeapTupleIsValid, i, StatisticExtInfo::keys, StatisticExtInfo::kind, lappend(), lfirst_oid, list_free(), makeNode, NIL, ObjectIdGetDatum, StatisticExtInfo::rel, RelationGetStatExtList(), ReleaseSysCache(), SearchSysCache1(), statext_is_kind_built(), STATEXTDATASTXOID, STATEXTOID, and StatisticExtInfo::statOid.

Referenced by get_relation_info().

1304 {
1305  List *statoidlist;
1306  List *stainfos = NIL;
1307  ListCell *l;
1308 
1309  statoidlist = RelationGetStatExtList(relation);
1310 
1311  foreach(l, statoidlist)
1312  {
1313  Oid statOid = lfirst_oid(l);
1314  Form_pg_statistic_ext staForm;
1315  HeapTuple htup;
1316  HeapTuple dtup;
1317  Bitmapset *keys = NULL;
1318  int i;
1319 
1320  htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid));
1321  if (!HeapTupleIsValid(htup))
1322  elog(ERROR, "cache lookup failed for statistics object %u", statOid);
1323  staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
1324 
1326  if (!HeapTupleIsValid(dtup))
1327  elog(ERROR, "cache lookup failed for statistics object %u", statOid);
1328 
1329  /*
1330  * First, build the array of columns covered. This is ultimately
1331  * wasted if no stats within the object have actually been built, but
1332  * it doesn't seem worth troubling over that case.
1333  */
1334  for (i = 0; i < staForm->stxkeys.dim1; i++)
1335  keys = bms_add_member(keys, staForm->stxkeys.values[i]);
1336 
1337  /* add one StatisticExtInfo for each kind built */
1338  if (statext_is_kind_built(dtup, STATS_EXT_NDISTINCT))
1339  {
1341 
1342  info->statOid = statOid;
1343  info->rel = rel;
1344  info->kind = STATS_EXT_NDISTINCT;
1345  info->keys = bms_copy(keys);
1346 
1347  stainfos = lappend(stainfos, info);
1348  }
1349 
1350  if (statext_is_kind_built(dtup, STATS_EXT_DEPENDENCIES))
1351  {
1353 
1354  info->statOid = statOid;
1355  info->rel = rel;
1356  info->kind = STATS_EXT_DEPENDENCIES;
1357  info->keys = bms_copy(keys);
1358 
1359  stainfos = lappend(stainfos, info);
1360  }
1361 
1362  if (statext_is_kind_built(dtup, STATS_EXT_MCV))
1363  {
1365 
1366  info->statOid = statOid;
1367  info->rel = rel;
1368  info->kind = STATS_EXT_MCV;
1369  info->keys = bms_copy(keys);
1370 
1371  stainfos = lappend(stainfos, info);
1372  }
1373 
1374  ReleaseSysCache(htup);
1375  ReleaseSysCache(dtup);
1376  bms_free(keys);
1377  }
1378 
1379  list_free(statoidlist);
1380 
1381  return stainfos;
1382 }
#define NIL
Definition: pg_list.h:65
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
bool statext_is_kind_built(HeapTuple htup, char type)
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
RelOptInfo * rel
Definition: pathnodes.h:917
List * lappend(List *list, void *datum)
Definition: list.c:336
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
#define makeNode(_type_)
Definition: nodes.h:576
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
List * RelationGetStatExtList(Relation relation)
Definition: relcache.c:4645
Bitmapset * keys
Definition: pathnodes.h:919
void list_free(List *list)
Definition: list.c:1391
#define elog(elevel,...)
Definition: elog.h:228
int i
Definition: pg_list.h:50
FormData_pg_statistic_ext * Form_pg_statistic_ext
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ has_row_triggers()

bool has_row_triggers ( PlannerInfo root,
Index  rti,
CmdType  event 
)

Definition at line 2068 of file plancat.c.

References CMD_DELETE, CMD_INSERT, CMD_UPDATE, elog, ERROR, NoLock, planner_rt_fetch, RangeTblEntry::relid, table_close(), table_open(), TriggerDesc::trig_delete_after_row, TriggerDesc::trig_delete_before_row, TriggerDesc::trig_insert_after_row, TriggerDesc::trig_insert_before_row, TriggerDesc::trig_update_after_row, TriggerDesc::trig_update_before_row, and RelationData::trigdesc.

Referenced by make_modifytable().

2069 {
2070  RangeTblEntry *rte = planner_rt_fetch(rti, root);
2071  Relation relation;
2072  TriggerDesc *trigDesc;
2073  bool result = false;
2074 
2075  /* Assume we already have adequate lock */
2076  relation = table_open(rte->relid, NoLock);
2077 
2078  trigDesc = relation->trigdesc;
2079  switch (event)
2080  {
2081  case CMD_INSERT:
2082  if (trigDesc &&
2083  (trigDesc->trig_insert_after_row ||
2084  trigDesc->trig_insert_before_row))
2085  result = true;
2086  break;
2087  case CMD_UPDATE:
2088  if (trigDesc &&
2089  (trigDesc->trig_update_after_row ||
2090  trigDesc->trig_update_before_row))
2091  result = true;
2092  break;
2093  case CMD_DELETE:
2094  if (trigDesc &&
2095  (trigDesc->trig_delete_after_row ||
2096  trigDesc->trig_delete_before_row))
2097  result = true;
2098  break;
2099  default:
2100  elog(ERROR, "unrecognized CmdType: %d", (int) event);
2101  break;
2102  }
2103 
2104  table_close(relation, NoLock);
2105  return result;
2106 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define ERROR
Definition: elog.h:45
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:377
TriggerDesc * trigdesc
Definition: rel.h:116
bool trig_delete_after_row
Definition: reltrigger.h:67
#define NoLock
Definition: lockdefs.h:34
bool trig_update_before_row
Definition: reltrigger.h:61
bool trig_insert_after_row
Definition: reltrigger.h:57
bool trig_update_after_row
Definition: reltrigger.h:62
bool trig_insert_before_row
Definition: reltrigger.h:56
#define elog(elevel,...)
Definition: elog.h:228
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
bool trig_delete_before_row
Definition: reltrigger.h:66

◆ has_stored_generated_columns()

bool has_stored_generated_columns ( PlannerInfo root,
Index  rti 
)

Definition at line 2109 of file plancat.c.

References TupleDescData::constr, TupleConstr::has_generated_stored, NoLock, planner_rt_fetch, RelationGetDescr, RangeTblEntry::relid, table_close(), and table_open().

Referenced by make_modifytable().

2110 {
2111  RangeTblEntry *rte = planner_rt_fetch(rti, root);
2112  Relation relation;
2113  TupleDesc tupdesc;
2114  bool result = false;
2115 
2116  /* Assume we already have adequate lock */
2117  relation = table_open(rte->relid, NoLock);
2118 
2119  tupdesc = RelationGetDescr(relation);
2120  result = tupdesc->constr && tupdesc->constr->has_generated_stored;
2121 
2122  table_close(relation, NoLock);
2123 
2124  return result;
2125 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define RelationGetDescr(relation)
Definition: rel.h:483
bool has_generated_stored
Definition: tupdesc.h:45
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:377
#define NoLock
Definition: lockdefs.h:34
TupleConstr * constr
Definition: tupdesc.h:85
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ has_unique_index()

bool has_unique_index ( RelOptInfo rel,
AttrNumber  attno 
)

Definition at line 2036 of file plancat.c.

References IndexOptInfo::indexkeys, RelOptInfo::indexlist, IndexOptInfo::indpred, lfirst, NIL, IndexOptInfo::nkeycolumns, IndexOptInfo::predOK, and IndexOptInfo::unique.

Referenced by examine_variable().

2037 {
2038  ListCell *ilist;
2039 
2040  foreach(ilist, rel->indexlist)
2041  {
2042  IndexOptInfo *index = (IndexOptInfo *) lfirst(ilist);
2043 
2044  /*
2045  * Note: ignore partial indexes, since they don't allow us to conclude
2046  * that all attr values are distinct, *unless* they are marked predOK
2047  * which means we know the index's predicate is satisfied by the
2048  * query. We don't take any interest in expressional indexes either.
2049  * Also, a multicolumn unique index doesn't allow us to conclude that
2050  * just the specified attr is unique.
2051  */
2052  if (index->unique &&
2053  index->nkeycolumns == 1 &&
2054  index->indexkeys[0] == attno &&
2055  (index->indpred == NIL || index->predOK))
2056  return true;
2057  }
2058  return false;
2059 }
#define NIL
Definition: pg_list.h:65
Definition: type.h:89
List * indexlist
Definition: pathnodes.h:703
#define lfirst(lc)
Definition: pg_list.h:169
int nkeycolumns
Definition: pathnodes.h:829
int * indexkeys
Definition: pathnodes.h:830
List * indpred
Definition: pathnodes.h:844

◆ infer_arbiter_indexes()

List* infer_arbiter_indexes ( PlannerInfo root)

Definition at line 613 of file plancat.c.

References OnConflictExpr::action, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, bms_add_member(), bms_equal(), OnConflictExpr::constraint, ereport, errcode(), errmsg(), ERROR, InferenceElem::expr, FirstLowInvalidHeapAttributeNumber, get_constraint_index(), index_close(), index_open(), infer_collation_opclass_match(), InferenceElem::infercollid, InferenceElem::inferopclass, InvalidOid, IsA, lappend(), lappend_oid(), lfirst, lfirst_oid, list_difference(), list_free(), list_member(), next, NIL, NoLock, Query::onConflict, ONCONFLICT_UPDATE, PlannerInfo::parse, predicate_implied_by(), RelationData::rd_index, RelationGetIndexExpressions(), RelationGetIndexList(), RelationGetIndexPredicate(), RangeTblEntry::relid, RangeTblEntry::rellockmode, Query::resultRelation, rt_fetch, Query::rtable, table_close(), table_open(), and Var::varattno.

Referenced by make_modifytable().

614 {
615  OnConflictExpr *onconflict = root->parse->onConflict;
616 
617  /* Iteration state */
618  RangeTblEntry *rte;
619  Relation relation;
620  Oid indexOidFromConstraint = InvalidOid;
621  List *indexList;
622  ListCell *l;
623 
624  /* Normalized inference attributes and inference expressions: */
625  Bitmapset *inferAttrs = NULL;
626  List *inferElems = NIL;
627 
628  /* Results */
629  List *results = NIL;
630 
631  /*
632  * Quickly return NIL for ON CONFLICT DO NOTHING without an inference
633  * specification or named constraint. ON CONFLICT DO UPDATE statements
634  * must always provide one or the other (but parser ought to have caught
635  * that already).
636  */
637  if (onconflict->arbiterElems == NIL &&
638  onconflict->constraint == InvalidOid)
639  return NIL;
640 
641  /*
642  * We need not lock the relation since it was already locked, either by
643  * the rewriter or when expand_inherited_rtentry() added it to the query's
644  * rangetable.
645  */
646  rte = rt_fetch(root->parse->resultRelation, root->parse->rtable);
647 
648  relation = table_open(rte->relid, NoLock);
649 
650  /*
651  * Build normalized/BMS representation of plain indexed attributes, as
652  * well as a separate list of expression items. This simplifies matching
653  * the cataloged definition of indexes.
654  */
655  foreach(l, onconflict->arbiterElems)
656  {
657  InferenceElem *elem = (InferenceElem *) lfirst(l);
658  Var *var;
659  int attno;
660 
661  if (!IsA(elem->expr, Var))
662  {
663  /* If not a plain Var, just shove it in inferElems for now */
664  inferElems = lappend(inferElems, elem->expr);
665  continue;
666  }
667 
668  var = (Var *) elem->expr;
669  attno = var->varattno;
670 
671  if (attno == 0)
672  ereport(ERROR,
673  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
674  errmsg("whole row unique index inference specifications are not supported")));
675 
676  inferAttrs = bms_add_member(inferAttrs,
678  }
679 
680  /*
681  * Lookup named constraint's index. This is not immediately returned
682  * because some additional sanity checks are required.
683  */
684  if (onconflict->constraint != InvalidOid)
685  {
686  indexOidFromConstraint = get_constraint_index(onconflict->constraint);
687 
688  if (indexOidFromConstraint == InvalidOid)
689  ereport(ERROR,
690  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
691  errmsg("constraint in ON CONFLICT clause has no associated index")));
692  }
693 
694  /*
695  * Using that representation, iterate through the list of indexes on the
696  * target relation to try and find a match
697  */
698  indexList = RelationGetIndexList(relation);
699 
700  foreach(l, indexList)
701  {
702  Oid indexoid = lfirst_oid(l);
703  Relation idxRel;
704  Form_pg_index idxForm;
705  Bitmapset *indexedAttrs;
706  List *idxExprs;
707  List *predExprs;
708  AttrNumber natt;
709  ListCell *el;
710 
711  /*
712  * Extract info from the relation descriptor for the index. Obtain
713  * the same lock type that the executor will ultimately use.
714  *
715  * Let executor complain about !indimmediate case directly, because
716  * enforcement needs to occur there anyway when an inference clause is
717  * omitted.
718  */
719  idxRel = index_open(indexoid, rte->rellockmode);
720  idxForm = idxRel->rd_index;
721 
722  if (!idxForm->indisvalid)
723  goto next;
724 
725  /*
726  * Note that we do not perform a check against indcheckxmin (like e.g.
727  * get_relation_info()) here to eliminate candidates, because
728  * uniqueness checking only cares about the most recently committed
729  * tuple versions.
730  */
731 
732  /*
733  * Look for match on "ON constraint_name" variant, which may not be
734  * unique constraint. This can only be a constraint name.
735  */
736  if (indexOidFromConstraint == idxForm->indexrelid)
737  {
738  if (!idxForm->indisunique && onconflict->action == ONCONFLICT_UPDATE)
739  ereport(ERROR,
740  (errcode(ERRCODE_WRONG_OBJECT_TYPE),
741  errmsg("ON CONFLICT DO UPDATE not supported with exclusion constraints")));
742 
743  results = lappend_oid(results, idxForm->indexrelid);
744  list_free(indexList);
745  index_close(idxRel, NoLock);
746  table_close(relation, NoLock);
747  return results;
748  }
749  else if (indexOidFromConstraint != InvalidOid)
750  {
751  /* No point in further work for index in named constraint case */
752  goto next;
753  }
754 
755  /*
756  * Only considering conventional inference at this point (not named
757  * constraints), so index under consideration can be immediately
758  * skipped if it's not unique
759  */
760  if (!idxForm->indisunique)
761  goto next;
762 
763  /* Build BMS representation of plain (non expression) index attrs */
764  indexedAttrs = NULL;
765  for (natt = 0; natt < idxForm->indnkeyatts; natt++)
766  {
767  int attno = idxRel->rd_index->indkey.values[natt];
768 
769  if (attno != 0)
770  indexedAttrs = bms_add_member(indexedAttrs,
772  }
773 
774  /* Non-expression attributes (if any) must match */
775  if (!bms_equal(indexedAttrs, inferAttrs))
776  goto next;
777 
778  /* Expression attributes (if any) must match */
779  idxExprs = RelationGetIndexExpressions(idxRel);
780  foreach(el, onconflict->arbiterElems)
781  {
782  InferenceElem *elem = (InferenceElem *) lfirst(el);
783 
784  /*
785  * Ensure that collation/opclass aspects of inference expression
786  * element match. Even though this loop is primarily concerned
787  * with matching expressions, it is a convenient point to check
788  * this for both expressions and ordinary (non-expression)
789  * attributes appearing as inference elements.
790  */
791  if (!infer_collation_opclass_match(elem, idxRel, idxExprs))
792  goto next;
793 
794  /*
795  * Plain Vars don't factor into count of expression elements, and
796  * the question of whether or not they satisfy the index
797  * definition has already been considered (they must).
798  */
799  if (IsA(elem->expr, Var))
800  continue;
801 
802  /*
803  * Might as well avoid redundant check in the rare cases where
804  * infer_collation_opclass_match() is required to do real work.
805  * Otherwise, check that element expression appears in cataloged
806  * index definition.
807  */
808  if (elem->infercollid != InvalidOid ||
809  elem->inferopclass != InvalidOid ||
810  list_member(idxExprs, elem->expr))
811  continue;
812 
813  goto next;
814  }
815 
816  /*
817  * Now that all inference elements were matched, ensure that the
818  * expression elements from inference clause are not missing any
819  * cataloged expressions. This does the right thing when unique
820  * indexes redundantly repeat the same attribute, or if attributes
821  * redundantly appear multiple times within an inference clause.
822  */
823  if (list_difference(idxExprs, inferElems) != NIL)
824  goto next;
825 
826  /*
827  * If it's a partial index, its predicate must be implied by the ON
828  * CONFLICT's WHERE clause.
829  */
830  predExprs = RelationGetIndexPredicate(idxRel);
831 
832  if (!predicate_implied_by(predExprs, (List *) onconflict->arbiterWhere, false))
833  goto next;
834 
835  results = lappend_oid(results, idxForm->indexrelid);
836 next:
837  index_close(idxRel, NoLock);
838  }
839 
840  list_free(indexList);
841  table_close(relation, NoLock);
842 
843  if (results == NIL)
844  ereport(ERROR,
845  (errcode(ERRCODE_INVALID_COLUMN_REFERENCE),
846  errmsg("there is no unique or exclusion constraint matching the ON CONFLICT specification")));
847 
848  return results;
849 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
Query * parse
Definition: pathnodes.h:173
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
static int32 next
Definition: blutils.c:219
OnConflictExpr * onConflict
Definition: parsenodes.h:144
int resultRelation
Definition: parsenodes.h:122
static bool infer_collation_opclass_match(InferenceElem *elem, Relation idxRel, List *idxExprs)
Definition: plancat.c:879
int errcode(int sqlerrcode)
Definition: elog.c:704
AttrNumber varattno
Definition: primnodes.h:186
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
unsigned int Oid
Definition: postgres_ext.h:31
Definition: primnodes.h:181
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
List * RelationGetIndexPredicate(Relation relation)
Definition: relcache.c:4873
List * arbiterElems
Definition: primnodes.h:1553
Form_pg_index rd_index
Definition: rel.h:175
List * rtable
Definition: parsenodes.h:137
#define ERROR
Definition: elog.h:45
bool list_member(const List *list, const void *datum)
Definition: list.c:628
#define NoLock
Definition: lockdefs.h:34
List * RelationGetIndexExpressions(Relation relation)
Definition: relcache.c:4760
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
List * lappend(List *list, void *datum)
Definition: list.c:336
OnConflictAction action
Definition: primnodes.h:1550
FormData_pg_index * Form_pg_index
Definition: pg_index.h:68
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:155
#define lfirst(lc)
Definition: pg_list.h:169
List * list_difference(const List *list1, const List *list2)
Definition: list.c:1091
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4526
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
Node * arbiterWhere
Definition: primnodes.h:1555
int errmsg(const char *fmt,...)
Definition: elog.c:915
void list_free(List *list)
Definition: list.c:1391
Oid get_constraint_index(Oid conoid)
Definition: lsyscache.c:1106
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:151
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:132
#define lfirst_oid(lc)
Definition: pg_list.h:171
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

◆ infer_collation_opclass_match()

static bool infer_collation_opclass_match ( InferenceElem elem,
Relation  idxRel,
List idxExprs 
)
static

Definition at line 879 of file plancat.c.

References equal(), InferenceElem::expr, get_opclass_family(), get_opclass_input_type(), InferenceElem::infercollid, InferenceElem::inferopclass, InvalidOid, IsA, list_nth(), TupleDescData::natts, RelationData::rd_att, RelationData::rd_indcollation, RelationData::rd_index, RelationData::rd_opcintype, and RelationData::rd_opfamily.

Referenced by infer_arbiter_indexes().

881 {
882  AttrNumber natt;
883  Oid inferopfamily = InvalidOid; /* OID of opclass opfamily */
884  Oid inferopcinputtype = InvalidOid; /* OID of opclass input type */
885  int nplain = 0; /* # plain attrs observed */
886 
887  /*
888  * If inference specification element lacks collation/opclass, then no
889  * need to check for exact match.
890  */
891  if (elem->infercollid == InvalidOid && elem->inferopclass == InvalidOid)
892  return true;
893 
894  /*
895  * Lookup opfamily and input type, for matching indexes
896  */
897  if (elem->inferopclass)
898  {
899  inferopfamily = get_opclass_family(elem->inferopclass);
900  inferopcinputtype = get_opclass_input_type(elem->inferopclass);
901  }
902 
903  for (natt = 1; natt <= idxRel->rd_att->natts; natt++)
904  {
905  Oid opfamily = idxRel->rd_opfamily[natt - 1];
906  Oid opcinputtype = idxRel->rd_opcintype[natt - 1];
907  Oid collation = idxRel->rd_indcollation[natt - 1];
908  int attno = idxRel->rd_index->indkey.values[natt - 1];
909 
910  if (attno != 0)
911  nplain++;
912 
913  if (elem->inferopclass != InvalidOid &&
914  (inferopfamily != opfamily || inferopcinputtype != opcinputtype))
915  {
916  /* Attribute needed to match opclass, but didn't */
917  continue;
918  }
919 
920  if (elem->infercollid != InvalidOid &&
921  elem->infercollid != collation)
922  {
923  /* Attribute needed to match collation, but didn't */
924  continue;
925  }
926 
927  /* If one matching index att found, good enough -- return true */
928  if (IsA(elem->expr, Var))
929  {
930  if (((Var *) elem->expr)->varattno == attno)
931  return true;
932  }
933  else if (attno == 0)
934  {
935  Node *nattExpr = list_nth(idxExprs, (natt - 1) - nplain);
936 
937  /*
938  * Note that unlike routines like match_index_to_operand() we
939  * don't need to care about RelabelType. Neither the index
940  * definition nor the inference clause should contain them.
941  */
942  if (equal(elem->expr, nattExpr))
943  return true;
944  }
945  }
946 
947  return false;
948 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3042
Definition: nodes.h:528
unsigned int Oid
Definition: postgres_ext.h:31
Definition: primnodes.h:181
Form_pg_index rd_index
Definition: rel.h:175
Oid * rd_indcollation
Definition: rel.h:200
static void * list_nth(const List *list, int n)
Definition: pg_list.h:278
Oid * rd_opfamily
Definition: rel.h:190
TupleDesc rd_att
Definition: rel.h:111
#define InvalidOid
Definition: postgres_ext.h:36
Oid get_opclass_family(Oid opclass)
Definition: lsyscache.c:1156
Oid * rd_opcintype
Definition: rel.h:191
int16 AttrNumber
Definition: attnum.h:21
Oid get_opclass_input_type(Oid opclass)
Definition: lsyscache.c:1178

◆ join_selectivity()

Selectivity join_selectivity ( PlannerInfo root,
Oid  operatorid,
List args,
Oid  inputcollid,
JoinType  jointype,
SpecialJoinInfo sjinfo 
)

Definition at line 1814 of file plancat.c.

References DatumGetFloat8, elog, ERROR, get_oprjoin(), Int16GetDatum, ObjectIdGetDatum, OidFunctionCall5Coll(), and PointerGetDatum.

Referenced by clause_selectivity_ext(), rowcomparesel(), and test_support_func().

1820 {
1821  RegProcedure oprjoin = get_oprjoin(operatorid);
1822  float8 result;
1823 
1824  /*
1825  * if the oprjoin procedure is missing for whatever reason, use a
1826  * selectivity of 0.5
1827  */
1828  if (!oprjoin)
1829  return (Selectivity) 0.5;
1830 
1831  result = DatumGetFloat8(OidFunctionCall5Coll(oprjoin,
1832  inputcollid,
1833  PointerGetDatum(root),
1834  ObjectIdGetDatum(operatorid),
1835  PointerGetDatum(args),
1836  Int16GetDatum(jointype),
1837  PointerGetDatum(sjinfo)));
1838 
1839  if (result < 0.0 || result > 1.0)
1840  elog(ERROR, "invalid join selectivity: %f", result);
1841 
1842  return (Selectivity) result;
1843 }
RegProcedure get_oprjoin(Oid opno)
Definition: lsyscache.c:1525
#define PointerGetDatum(X)
Definition: postgres.h:556
regproc RegProcedure
Definition: c.h:573
#define Int16GetDatum(X)
Definition: postgres.h:451
double Selectivity
Definition: nodes.h:661
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
double float8
Definition: c.h:553
#define DatumGetFloat8(X)
Definition: postgres.h:714
Datum OidFunctionCall5Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4, Datum arg5)
Definition: fmgr.c:1455
#define elog(elevel,...)
Definition: elog.h:228

◆ relation_excluded_by_constraints()

bool relation_excluded_by_constraints ( PlannerInfo root,
RelOptInfo rel,
RangeTblEntry rte 
)

Definition at line 1396 of file plancat.c.

References Assert, RelOptInfo::baserestrictinfo, RestrictInfo::clause, constraint_exclusion, CONSTRAINT_EXCLUSION_OFF, CONSTRAINT_EXCLUSION_ON, CONSTRAINT_EXCLUSION_PARTITION, contain_mutable_functions(), DatumGetBool, get_relation_constraints(), RangeTblEntry::inh, INHKIND_NONE, PlannerInfo::inhTargetKind, IS_SIMPLE_REL, IsA, lappend(), lfirst, linitial, list_length(), NIL, PlannerInfo::parse, predicate_refuted_by(), RelOptInfo::relid, RangeTblEntry::relid, RangeTblEntry::relkind, RELOPT_BASEREL, RELOPT_OTHER_MEMBER_REL, RelOptInfo::reloptkind, Query::resultRelation, RTE_RELATION, and RangeTblEntry::rtekind.

Referenced by set_append_rel_size(), and set_rel_size().

1398 {
1399  bool include_noinherit;
1400  bool include_notnull;
1401  bool include_partition = false;
1402  List *safe_restrictions;
1403  List *constraint_pred;
1404  List *safe_constraints;
1405  ListCell *lc;
1406 
1407  /* As of now, constraint exclusion works only with simple relations. */
1408  Assert(IS_SIMPLE_REL(rel));
1409 
1410  /*
1411  * If there are no base restriction clauses, we have no hope of proving
1412  * anything below, so fall out quickly.
1413  */
1414  if (rel->baserestrictinfo == NIL)
1415  return false;
1416 
1417  /*
1418  * Regardless of the setting of constraint_exclusion, detect
1419  * constant-FALSE-or-NULL restriction clauses. Because const-folding will
1420  * reduce "anything AND FALSE" to just "FALSE", any such case should
1421  * result in exactly one baserestrictinfo entry. This doesn't fire very
1422  * often, but it seems cheap enough to be worth doing anyway. (Without
1423  * this, we'd miss some optimizations that 9.5 and earlier found via much
1424  * more roundabout methods.)
1425  */
1426  if (list_length(rel->baserestrictinfo) == 1)
1427  {
1429  Expr *clause = rinfo->clause;
1430 
1431  if (clause && IsA(clause, Const) &&
1432  (((Const *) clause)->constisnull ||
1433  !DatumGetBool(((Const *) clause)->constvalue)))
1434  return true;
1435  }
1436 
1437  /*
1438  * Skip further tests, depending on constraint_exclusion.
1439  */
1440  switch (constraint_exclusion)
1441  {
1443  /* In 'off' mode, never make any further tests */
1444  return false;
1445 
1447 
1448  /*
1449  * When constraint_exclusion is set to 'partition' we only handle
1450  * appendrel members. Normally, they are RELOPT_OTHER_MEMBER_REL
1451  * relations, but we also consider inherited target relations as
1452  * appendrel members for the purposes of constraint exclusion
1453  * (since, indeed, they were appendrel members earlier in
1454  * inheritance_planner).
1455  *
1456  * In both cases, partition pruning was already applied, so there
1457  * is no need to consider the rel's partition constraints here.
1458  */
1459  if (rel->reloptkind == RELOPT_OTHER_MEMBER_REL ||
1460  (rel->relid == root->parse->resultRelation &&
1461  root->inhTargetKind != INHKIND_NONE))
1462  break; /* appendrel member, so process it */
1463  return false;
1464 
1466 
1467  /*
1468  * In 'on' mode, always apply constraint exclusion. If we are
1469  * considering a baserel that is a partition (i.e., it was
1470  * directly named rather than expanded from a parent table), then
1471  * its partition constraints haven't been considered yet, so
1472  * include them in the processing here.
1473  */
1474  if (rel->reloptkind == RELOPT_BASEREL &&
1475  !(rel->relid == root->parse->resultRelation &&
1476  root->inhTargetKind != INHKIND_NONE))
1477  include_partition = true;
1478  break; /* always try to exclude */
1479  }
1480 
1481  /*
1482  * Check for self-contradictory restriction clauses. We dare not make
1483  * deductions with non-immutable functions, but any immutable clauses that
1484  * are self-contradictory allow us to conclude the scan is unnecessary.
1485  *
1486  * Note: strip off RestrictInfo because predicate_refuted_by() isn't
1487  * expecting to see any in its predicate argument.
1488  */
1489  safe_restrictions = NIL;
1490  foreach(lc, rel->baserestrictinfo)
1491  {
1492  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1493 
1494  if (!contain_mutable_functions((Node *) rinfo->clause))
1495  safe_restrictions = lappend(safe_restrictions, rinfo->clause);
1496  }
1497 
1498  /*
1499  * We can use weak refutation here, since we're comparing restriction
1500  * clauses with restriction clauses.
1501  */
1502  if (predicate_refuted_by(safe_restrictions, safe_restrictions, true))
1503  return true;
1504 
1505  /*
1506  * Only plain relations have constraints, so stop here for other rtekinds.
1507  */
1508  if (rte->rtekind != RTE_RELATION)
1509  return false;
1510 
1511  /*
1512  * If we are scanning just this table, we can use NO INHERIT constraints,
1513  * but not if we're scanning its children too. (Note that partitioned
1514  * tables should never have NO INHERIT constraints; but it's not necessary
1515  * for us to assume that here.)
1516  */
1517  include_noinherit = !rte->inh;
1518 
1519  /*
1520  * Currently, attnotnull constraints must be treated as NO INHERIT unless
1521  * this is a partitioned table. In future we might track their
1522  * inheritance status more accurately, allowing this to be refined.
1523  */
1524  include_notnull = (!rte->inh || rte->relkind == RELKIND_PARTITIONED_TABLE);
1525 
1526  /*
1527  * Fetch the appropriate set of constraint expressions.
1528  */
1529  constraint_pred = get_relation_constraints(root, rte->relid, rel,
1530  include_noinherit,
1531  include_notnull,
1532  include_partition);
1533 
1534  /*
1535  * We do not currently enforce that CHECK constraints contain only
1536  * immutable functions, so it's necessary to check here. We daren't draw
1537  * conclusions from plan-time evaluation of non-immutable functions. Since
1538  * they're ANDed, we can just ignore any mutable constraints in the list,
1539  * and reason about the rest.
1540  */
1541  safe_constraints = NIL;
1542  foreach(lc, constraint_pred)
1543  {
1544  Node *pred = (Node *) lfirst(lc);
1545 
1546  if (!contain_mutable_functions(pred))
1547  safe_constraints = lappend(safe_constraints, pred);
1548  }
1549 
1550  /*
1551  * The constraints are effectively ANDed together, so we can just try to
1552  * refute the entire collection at once. This may allow us to make proofs
1553  * that would fail if we took them individually.
1554  *
1555  * Note: we use rel->baserestrictinfo, not safe_restrictions as might seem
1556  * an obvious optimization. Some of the clauses might be OR clauses that
1557  * have volatile and nonvolatile subclauses, and it's OK to make
1558  * deductions with the nonvolatile parts.
1559  *
1560  * We need strong refutation because we have to prove that the constraints
1561  * would yield false, not just NULL.
1562  */
1563  if (predicate_refuted_by(safe_constraints, rel->baserestrictinfo, false))
1564  return true;
1565 
1566  return false;
1567 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:579
Query * parse
Definition: pathnodes.h:173
RelOptKind reloptkind
Definition: pathnodes.h:663
List * baserestrictinfo
Definition: pathnodes.h:728
int constraint_exclusion
Definition: plancat.c:57
int resultRelation
Definition: parsenodes.h:122
Definition: nodes.h:528
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:639
#define linitial(l)
Definition: pg_list.h:174
bool predicate_refuted_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:221
#define DatumGetBool(X)
Definition: postgres.h:393
Index relid
Definition: pathnodes.h:694
List * lappend(List *list, void *datum)
Definition: list.c:336
Expr * clause
Definition: pathnodes.h:1994
#define Assert(condition)
Definition: c.h:792
#define lfirst(lc)
Definition: pg_list.h:169
InheritanceKind inhTargetKind
Definition: pathnodes.h:336
static int list_length(const List *l)
Definition: pg_list.h:149
RTEKind rtekind
Definition: parsenodes.h:981
static List * get_relation_constraints(PlannerInfo *root, Oid relationObjectId, RelOptInfo *rel, bool include_noinherit, bool include_notnull, bool include_partition)
Definition: plancat.c:1181
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:358
Definition: pg_list.h:50

◆ restriction_selectivity()

Selectivity restriction_selectivity ( PlannerInfo root,
Oid  operatorid,
List args,
Oid  inputcollid,
int  varRelid 
)

Definition at line 1775 of file plancat.c.

References DatumGetFloat8, elog, ERROR, get_oprrest(), Int32GetDatum, ObjectIdGetDatum, OidFunctionCall4Coll(), and PointerGetDatum.

Referenced by clause_selectivity_ext(), rowcomparesel(), and test_support_func().

1780 {
1781  RegProcedure oprrest = get_oprrest(operatorid);
1782  float8 result;
1783 
1784  /*
1785  * if the oprrest procedure is missing for whatever reason, use a
1786  * selectivity of 0.5
1787  */
1788  if (!oprrest)
1789  return (Selectivity) 0.5;
1790 
1791  result = DatumGetFloat8(OidFunctionCall4Coll(oprrest,
1792  inputcollid,
1793  PointerGetDatum(root),
1794  ObjectIdGetDatum(operatorid),
1795  PointerGetDatum(args),
1796  Int32GetDatum(varRelid)));
1797 
1798  if (result < 0.0 || result > 1.0)
1799  elog(ERROR, "invalid restriction selectivity: %f", result);
1800 
1801  return (Selectivity) result;
1802 }
#define PointerGetDatum(X)
Definition: postgres.h:556
regproc RegProcedure
Definition: c.h:573
double Selectivity
Definition: nodes.h:661
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:45
double float8
Definition: c.h:553
RegProcedure get_oprrest(Oid opno)
Definition: lsyscache.c:1501
#define DatumGetFloat8(X)
Definition: postgres.h:714
Datum OidFunctionCall4Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Definition: fmgr.c:1444
#define Int32GetDatum(X)
Definition: postgres.h:479
#define elog(elevel,...)
Definition: elog.h:228

◆ set_baserel_partition_constraint()

static void set_baserel_partition_constraint ( Relation  relation,
RelOptInfo rel 
)
static

Definition at line 2334 of file plancat.c.

References ChangeVarNodes(), expression_planner(), RelOptInfo::partition_qual, RelationGetPartitionQual(), and RelOptInfo::relid.

Referenced by get_relation_constraints(), and set_relation_partition_info().

2335 {
2336  List *partconstr;
2337 
2338  if (rel->partition_qual) /* already done */
2339  return;
2340 
2341  /*
2342  * Run the partition quals through const-simplification similar to check
2343  * constraints. We skip canonicalize_qual, though, because partition
2344  * quals should be in canonical form already; also, since the qual is in
2345  * implicit-AND format, we'd have to explicitly convert it to explicit-AND
2346  * format and back again.
2347  */
2348  partconstr = RelationGetPartitionQual(relation);
2349  if (partconstr)
2350  {
2351  partconstr = (List *) expression_planner((Expr *) partconstr);
2352  if (rel->relid != 1)
2353  ChangeVarNodes((Node *) partconstr, 1, rel->relid, 0);
2354  rel->partition_qual = partconstr;
2355  }
2356 }
Expr * expression_planner(Expr *expr)
Definition: planner.c:6166
Definition: nodes.h:528
Index relid
Definition: pathnodes.h:694
List * RelationGetPartitionQual(Relation rel)
Definition: partcache.c:276
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
Definition: rewriteManip.c:610
List * partition_qual
Definition: pathnodes.h:750
Definition: pg_list.h:50

◆ set_baserel_partition_key_exprs()

static void set_baserel_partition_key_exprs ( Relation  relation,
RelOptInfo rel 
)
static

Definition at line 2266 of file plancat.c.

References Assert, ChangeVarNodes(), copyObject, elog, ERROR, InvalidAttrNumber, IS_SIMPLE_REL, lfirst, list_head(), list_make1, lnext(), makeVar(), RelOptInfo::nullable_partexprs, palloc(), palloc0(), PartitionKeyData::partattrs, PartitionKeyData::partexprs, RelOptInfo::partexprs, PartitionKeyData::partnatts, PartitionKeyData::parttypcoll, PartitionKeyData::parttypid, PartitionKeyData::parttypmod, RelationGetPartitionKey(), and RelOptInfo::relid.

Referenced by set_relation_partition_info().

2268 {
2269  PartitionKey partkey = RelationGetPartitionKey(relation);
2270  int partnatts;
2271  int cnt;
2272  List **partexprs;
2273  ListCell *lc;
2274  Index varno = rel->relid;
2275 
2276  Assert(IS_SIMPLE_REL(rel) && rel->relid > 0);
2277 
2278  /* A partitioned table should have a partition key. */
2279  Assert(partkey != NULL);
2280 
2281  partnatts = partkey->partnatts;
2282  partexprs = (List **) palloc(sizeof(List *) * partnatts);
2283  lc = list_head(partkey->partexprs);
2284 
2285  for (cnt = 0; cnt < partnatts; cnt++)
2286  {
2287  Expr *partexpr;
2288  AttrNumber attno = partkey->partattrs[cnt];
2289 
2290  if (attno != InvalidAttrNumber)
2291  {
2292  /* Single column partition key is stored as a Var node. */
2293  Assert(attno > 0);
2294 
2295  partexpr = (Expr *) makeVar(varno, attno,
2296  partkey->parttypid[cnt],
2297  partkey->parttypmod[cnt],
2298  partkey->parttypcoll[cnt], 0);
2299  }
2300  else
2301  {
2302  if (lc == NULL)
2303  elog(ERROR, "wrong number of partition key expressions");
2304 
2305  /* Re-stamp the expression with given varno. */
2306  partexpr = (Expr *) copyObject(lfirst(lc));
2307  ChangeVarNodes((Node *) partexpr, 1, varno, 0);
2308  lc = lnext(partkey->partexprs, lc);
2309  }
2310 
2311  /* Base relations have a single expression per key. */
2312  partexprs[cnt] = list_make1(partexpr);
2313  }
2314 
2315  rel->partexprs = partexprs;
2316 
2317  /*
2318  * A base relation does not have nullable partition key expressions, since
2319  * no outer join is involved. We still allocate an array of empty
2320  * expression lists to keep partition key expression handling code simple.
2321  * See build_joinrel_partition_info() and match_expr_to_partition_keys().
2322  */
2323  rel->nullable_partexprs = (List **) palloc0(sizeof(List *) * partnatts);
2324 }
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:322
Definition: nodes.h:528
List * partexprs
Definition: partcache.h:30
PartitionKey RelationGetPartitionKey(Relation rel)
Definition: partcache.c:54
List ** nullable_partexprs
Definition: pathnodes.h:755
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:639
#define list_make1(x1)
Definition: pg_list.h:206
Oid * parttypcoll
Definition: partcache.h:46
List ** partexprs
Definition: pathnodes.h:754
#define ERROR
Definition: elog.h:45
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
Var * makeVar(Index varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
Index relid
Definition: pathnodes.h:694
void * palloc0(Size size)
Definition: mcxt.c:981
AttrNumber * partattrs
Definition: partcache.h:28
unsigned int Index
Definition: c.h:537
int32 * parttypmod
Definition: partcache.h:42
#define Assert(condition)
Definition: c.h:792
#define lfirst(lc)
Definition: pg_list.h:169
#define InvalidAttrNumber
Definition: attnum.h:23
void * palloc(Size size)
Definition: mcxt.c:950
#define elog(elevel,...)
Definition: elog.h:228
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
Definition: rewriteManip.c:610
#define copyObject(obj)
Definition: nodes.h:644
Definition: pg_list.h:50
int16 AttrNumber
Definition: attnum.h:21

◆ set_relation_partition_info()

static void set_relation_partition_info ( PlannerInfo root,
RelOptInfo rel,
Relation  relation 
)
static

Definition at line 2133 of file plancat.c.

References Assert, PartitionDescData::boundinfo, RelOptInfo::boundinfo, CreatePartitionDirectory(), CurrentMemoryContext, find_partition_scheme(), PlannerInfo::glob, PartitionDescData::nparts, RelOptInfo::nparts, RelOptInfo::part_scheme, PlannerGlobal::partition_directory, PartitionDirectoryLookup(), set_baserel_partition_constraint(), and set_baserel_partition_key_exprs().

Referenced by get_relation_info().

2135 {
2136  PartitionDesc partdesc;
2137 
2138  /* Create the PartitionDirectory infrastructure if we didn't already */
2139  if (root->glob->partition_directory == NULL)
2140  root->glob->partition_directory =
2142 
2144  relation);
2145  rel->part_scheme = find_partition_scheme(root, relation);
2146  Assert(partdesc != NULL && rel->part_scheme != NULL);
2147  rel->boundinfo = partdesc->boundinfo;
2148  rel->nparts = partdesc->nparts;
2149  set_baserel_partition_key_exprs(relation, rel);
2150  set_baserel_partition_constraint(relation, rel);
2151 }
PartitionDirectory CreatePartitionDirectory(MemoryContext mcxt)
Definition: partdesc.c:283
PartitionBoundInfo boundinfo
Definition: partdesc.h:29
PlannerGlobal * glob
Definition: pathnodes.h:175
int nparts
Definition: pathnodes.h:744
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:747
static void set_baserel_partition_constraint(Relation relation, RelOptInfo *rel)
Definition: plancat.c:2334
static PartitionScheme find_partition_scheme(PlannerInfo *root, Relation rel)
Definition: plancat.c:2159
#define Assert(condition)
Definition: c.h:792
PartitionScheme part_scheme
Definition: pathnodes.h:743
PartitionDesc PartitionDirectoryLookup(PartitionDirectory pdir, Relation rel)
Definition: partdesc.c:315
static void set_baserel_partition_key_exprs(Relation relation, RelOptInfo *rel)
Definition: plancat.c:2266
PartitionDirectory partition_directory
Definition: pathnodes.h:143

Variable Documentation

◆ constraint_exclusion

int constraint_exclusion = CONSTRAINT_EXCLUSION_PARTITION

Definition at line 57 of file plancat.c.

Referenced by relation_excluded_by_constraints().

◆ get_relation_info_hook

get_relation_info_hook_type get_relation_info_hook = NULL

Definition at line 60 of file plancat.c.

Referenced by get_relation_info().