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/dependency.h"
#include "catalog/heap.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 1908 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_walker().

1910 {
1911  HeapTuple proctup;
1912  Form_pg_proc procform;
1913 
1914  proctup = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
1915  if (!HeapTupleIsValid(proctup))
1916  elog(ERROR, "cache lookup failed for function %u", funcid);
1917  procform = (Form_pg_proc) GETSTRUCT(proctup);
1918 
1919  if (OidIsValid(procform->prosupport))
1920  {
1921  SupportRequestCost req;
1922  SupportRequestCost *sresult;
1923 
1924  req.type = T_SupportRequestCost;
1925  req.root = root;
1926  req.funcid = funcid;
1927  req.node = node;
1928 
1929  /* Initialize cost fields so that support function doesn't have to */
1930  req.startup = 0;
1931  req.per_tuple = 0;
1932 
1933  sresult = (SupportRequestCost *)
1934  DatumGetPointer(OidFunctionCall1(procform->prosupport,
1935  PointerGetDatum(&req)));
1936 
1937  if (sresult == &req)
1938  {
1939  /* Success, so accumulate support function's estimate into *cost */
1940  cost->startup += req.startup;
1941  cost->per_tuple += req.per_tuple;
1942  ReleaseSysCache(proctup);
1943  return;
1944  }
1945  }
1946 
1947  /* No support function, or it failed, so rely on procost */
1948  cost->per_tuple += procform->procost * cpu_operator_cost;
1949 
1950  ReleaseSysCache(proctup);
1951 }
#define GETSTRUCT(TUP)
Definition: htup_details.h:655
#define PointerGetDatum(X)
Definition: postgres.h:556
#define OidIsValid(objectId)
Definition: c.h:651
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:43
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:662
double cpu_operator_cost
Definition: costsize.c:115
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
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:214

◆ build_index_tlist()

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

Definition at line 1704 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().

1706 {
1707  List *tlist = NIL;
1708  Index varno = index->rel->relid;
1709  ListCell *indexpr_item;
1710  int i;
1711 
1712  indexpr_item = list_head(index->indexprs);
1713  for (i = 0; i < index->ncolumns; i++)
1714  {
1715  int indexkey = index->indexkeys[i];
1716  Expr *indexvar;
1717 
1718  if (indexkey != 0)
1719  {
1720  /* simple column */
1721  const FormData_pg_attribute *att_tup;
1722 
1723  if (indexkey < 0)
1724  att_tup = SystemAttributeDefinition(indexkey);
1725  else
1726  att_tup = TupleDescAttr(heapRelation->rd_att, indexkey - 1);
1727 
1728  indexvar = (Expr *) makeVar(varno,
1729  indexkey,
1730  att_tup->atttypid,
1731  att_tup->atttypmod,
1732  att_tup->attcollation,
1733  0);
1734  }
1735  else
1736  {
1737  /* expression column */
1738  if (indexpr_item == NULL)
1739  elog(ERROR, "wrong number of index expressions");
1740  indexvar = (Expr *) lfirst(indexpr_item);
1741  indexpr_item = lnext(index->indexprs, indexpr_item);
1742  }
1743 
1744  tlist = lappend(tlist,
1745  makeTargetEntry(indexvar,
1746  i + 1,
1747  NULL,
1748  false));
1749  }
1750  if (indexpr_item != NULL)
1751  elog(ERROR, "wrong number of index expressions");
1752 
1753  return tlist;
1754 }
#define NIL
Definition: pg_list.h:65
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:321
#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:43
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:693
List * lappend(List *list, void *datum)
Definition: list.c:321
unsigned int Index
Definition: c.h:482
TupleDesc rd_att
Definition: rel.h:110
FormData_pg_attribute
Definition: pg_attribute.h:177
#define lfirst(lc)
Definition: pg_list.h:190
#define elog(elevel,...)
Definition: elog.h:214
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 1583 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().

1584 {
1585  List *tlist = NIL;
1586  Index varno = rel->relid;
1587  RangeTblEntry *rte = planner_rt_fetch(varno, root);
1588  Relation relation;
1589  Query *subquery;
1590  Var *var;
1591  ListCell *l;
1592  int attrno,
1593  numattrs;
1594  List *colvars;
1595 
1596  switch (rte->rtekind)
1597  {
1598  case RTE_RELATION:
1599  /* Assume we already have adequate lock */
1600  relation = table_open(rte->relid, NoLock);
1601 
1602  numattrs = RelationGetNumberOfAttributes(relation);
1603  for (attrno = 1; attrno <= numattrs; attrno++)
1604  {
1605  Form_pg_attribute att_tup = TupleDescAttr(relation->rd_att,
1606  attrno - 1);
1607 
1608  if (att_tup->attisdropped || att_tup->atthasmissing)
1609  {
1610  /* found a dropped or missing col, so punt */
1611  tlist = NIL;
1612  break;
1613  }
1614 
1615  var = makeVar(varno,
1616  attrno,
1617  att_tup->atttypid,
1618  att_tup->atttypmod,
1619  att_tup->attcollation,
1620  0);
1621 
1622  tlist = lappend(tlist,
1623  makeTargetEntry((Expr *) var,
1624  attrno,
1625  NULL,
1626  false));
1627  }
1628 
1629  table_close(relation, NoLock);
1630  break;
1631 
1632  case RTE_SUBQUERY:
1633  subquery = rte->subquery;
1634  foreach(l, subquery->targetList)
1635  {
1636  TargetEntry *tle = (TargetEntry *) lfirst(l);
1637 
1638  /*
1639  * A resjunk column of the subquery can be reflected as
1640  * resjunk in the physical tlist; we need not punt.
1641  */
1642  var = makeVarFromTargetEntry(varno, tle);
1643 
1644  tlist = lappend(tlist,
1645  makeTargetEntry((Expr *) var,
1646  tle->resno,
1647  NULL,
1648  tle->resjunk));
1649  }
1650  break;
1651 
1652  case RTE_FUNCTION:
1653  case RTE_TABLEFUNC:
1654  case RTE_VALUES:
1655  case RTE_CTE:
1656  case RTE_NAMEDTUPLESTORE:
1657  case RTE_RESULT:
1658  /* Not all of these can have dropped cols, but share code anyway */
1659  expandRTE(rte, varno, 0, -1, true /* include dropped */ ,
1660  NULL, &colvars);
1661  foreach(l, colvars)
1662  {
1663  var = (Var *) lfirst(l);
1664 
1665  /*
1666  * A non-Var in expandRTE's output means a dropped column;
1667  * must punt.
1668  */
1669  if (!IsA(var, Var))
1670  {
1671  tlist = NIL;
1672  break;
1673  }
1674 
1675  tlist = lappend(tlist,
1676  makeTargetEntry((Expr *) var,
1677  var->varattno,
1678  NULL,
1679  false));
1680  }
1681  break;
1682 
1683  default:
1684  /* caller error */
1685  elog(ERROR, "unsupported RTE kind %d in build_physical_tlist",
1686  (int) rte->rtekind);
1687  break;
1688  }
1689 
1690  return tlist;
1691 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:462
#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:1414
#define ERROR
Definition: elog.h:43
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:373
#define NoLock
Definition: lockdefs.h:34
AttrNumber resno
Definition: primnodes.h:1408
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:693
List * lappend(List *list, void *datum)
Definition: list.c:321
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, int location, bool include_dropped, List **colnames, List **colvars)
unsigned int Index
Definition: c.h:482
TupleDesc rd_att
Definition: rel.h:110
#define lfirst(lc)
Definition: pg_list.h:190
RTEKind rtekind
Definition: parsenodes.h:976
Query * subquery
Definition: parsenodes.h:1011
#define elog(elevel,...)
Definition: elog.h:214
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 949 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().

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

◆ find_partition_scheme()

static PartitionScheme find_partition_scheme ( PlannerInfo root,
Relation  rel 
)
static

Definition at line 2150 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().

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

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

◆ get_function_rows()

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

Definition at line 1969 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().

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

◆ get_rel_data_width()

int32 get_rel_data_width ( Relation  rel,
int32 attr_widths 
)

Definition at line 1090 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().

1091 {
1092  int32 tuple_width = 0;
1093  int i;
1094 
1095  for (i = 1; i <= RelationGetNumberOfAttributes(rel); i++)
1096  {
1097  Form_pg_attribute att = TupleDescAttr(rel->rd_att, i - 1);
1098  int32 item_width;
1099 
1100  if (att->attisdropped)
1101  continue;
1102 
1103  /* use previously cached data, if any */
1104  if (attr_widths != NULL && attr_widths[i] > 0)
1105  {
1106  tuple_width += attr_widths[i];
1107  continue;
1108  }
1109 
1110  /* This should match set_rel_width() in costsize.c */
1111  item_width = get_attavgwidth(RelationGetRelid(rel), i);
1112  if (item_width <= 0)
1113  {
1114  item_width = get_typavgwidth(att->atttypid, att->atttypmod);
1115  Assert(item_width > 0);
1116  }
1117  if (attr_widths != NULL)
1118  attr_widths[i] = item_width;
1119  tuple_width += item_width;
1120  }
1121 
1122  return tuple_width;
1123 }
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:462
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92
signed int int32
Definition: c.h:362
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:193
TupleDesc rd_att
Definition: rel.h:110
int32 get_typavgwidth(Oid typid, int32 typmod)
Definition: lsyscache.c:2466
#define Assert(condition)
Definition: c.h:745
int i
int32 get_attavgwidth(Oid relid, AttrNumber attnum)
Definition: lsyscache.c:2980
#define RelationGetRelid(relation)
Definition: rel.h:456

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

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

1133 {
1134  int32 result;
1135  Relation relation;
1136 
1137  /* As above, assume relation is already locked */
1138  relation = table_open(relid, NoLock);
1139 
1140  result = get_rel_data_width(relation, attr_widths);
1141 
1142  table_close(relation, NoLock);
1143 
1144  return result;
1145 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
signed int int32
Definition: c.h:362
#define NoLock
Definition: lockdefs.h:34
int32 get_rel_data_width(Relation rel, int32 *attr_widths)
Definition: plancat.c:1090
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 488 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, PlannerInfo::fkey_list, RangeTblEntry::inh, lappend(), lfirst, list_length(), makeNode, 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().

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

◆ 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, IndexAmRoutine::amcanorder, IndexAmRoutine::amcanorderbyop, IndexOptInfo::amcanorderbyop, IndexAmRoutine::amcanparallel, IndexOptInfo::amcanparallel, IndexAmRoutine::amcostestimate, IndexOptInfo::amcostestimate, IndexAmRoutine::amgetbitmap, IndexAmRoutine::amgettuple, IndexOptInfo::amhasgetbitmap, IndexOptInfo::amhasgettuple, IndexAmRoutine::amoptionalkey, IndexOptInfo::amoptionalkey, 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_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, 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  /*
202  * Ignore invalid indexes, since they can't safely be used for
203  * queries. Note that this is OK because the data structure we
204  * are constructing is only used by the planner --- the executor
205  * still needs to insert into "invalid" indexes, if they're marked
206  * indisready.
207  */
208  if (!index->indisvalid)
209  {
210  index_close(indexRelation, NoLock);
211  continue;
212  }
213 
214  /*
215  * Ignore partitioned indexes, since they are not usable for
216  * queries.
217  */
218  if (indexRelation->rd_rel->relkind == RELKIND_PARTITIONED_INDEX)
219  {
220  index_close(indexRelation, NoLock);
221  continue;
222  }
223 
224  /*
225  * If the index is valid, but cannot yet be used, ignore it; but
226  * mark the plan we are generating as transient. See
227  * src/backend/access/heap/README.HOT for discussion.
228  */
229  if (index->indcheckxmin &&
232  {
233  root->glob->transientPlan = true;
234  index_close(indexRelation, NoLock);
235  continue;
236  }
237 
238  info = makeNode(IndexOptInfo);
239 
240  info->indexoid = index->indexrelid;
241  info->reltablespace =
242  RelationGetForm(indexRelation)->reltablespace;
243  info->rel = rel;
244  info->ncolumns = ncolumns = index->indnatts;
245  info->nkeycolumns = nkeycolumns = index->indnkeyatts;
246 
247  info->indexkeys = (int *) palloc(sizeof(int) * ncolumns);
248  info->indexcollations = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
249  info->opfamily = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
250  info->opcintype = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
251  info->canreturn = (bool *) palloc(sizeof(bool) * ncolumns);
252 
253  for (i = 0; i < ncolumns; i++)
254  {
255  info->indexkeys[i] = index->indkey.values[i];
256  info->canreturn[i] = index_can_return(indexRelation, i + 1);
257  }
258 
259  for (i = 0; i < nkeycolumns; i++)
260  {
261  info->opfamily[i] = indexRelation->rd_opfamily[i];
262  info->opcintype[i] = indexRelation->rd_opcintype[i];
263  info->indexcollations[i] = indexRelation->rd_indcollation[i];
264  }
265 
266  info->relam = indexRelation->rd_rel->relam;
267 
268  /* We copy just the fields we need, not all of rd_indam */
269  amroutine = indexRelation->rd_indam;
270  info->amcanorderbyop = amroutine->amcanorderbyop;
271  info->amoptionalkey = amroutine->amoptionalkey;
272  info->amsearcharray = amroutine->amsearcharray;
273  info->amsearchnulls = amroutine->amsearchnulls;
274  info->amcanparallel = amroutine->amcanparallel;
275  info->amhasgettuple = (amroutine->amgettuple != NULL);
276  info->amhasgetbitmap = amroutine->amgetbitmap != NULL &&
277  relation->rd_tableam->scan_bitmap_next_block != NULL;
278  info->amcostestimate = amroutine->amcostestimate;
279  Assert(info->amcostestimate != NULL);
280 
281  /* Fetch index opclass options */
282  info->opclassoptions = RelationGetIndexAttOptions(indexRelation, true);
283 
284  /*
285  * Fetch the ordering information for the index, if any.
286  */
287  if (info->relam == BTREE_AM_OID)
288  {
289  /*
290  * If it's a btree index, we can use its opfamily OIDs
291  * directly as the sort ordering opfamily OIDs.
292  */
293  Assert(amroutine->amcanorder);
294 
295  info->sortopfamily = info->opfamily;
296  info->reverse_sort = (bool *) palloc(sizeof(bool) * nkeycolumns);
297  info->nulls_first = (bool *) palloc(sizeof(bool) * nkeycolumns);
298 
299  for (i = 0; i < nkeycolumns; i++)
300  {
301  int16 opt = indexRelation->rd_indoption[i];
302 
303  info->reverse_sort[i] = (opt & INDOPTION_DESC) != 0;
304  info->nulls_first[i] = (opt & INDOPTION_NULLS_FIRST) != 0;
305  }
306  }
307  else if (amroutine->amcanorder)
308  {
309  /*
310  * Otherwise, identify the corresponding btree opfamilies by
311  * trying to map this index's "<" operators into btree. Since
312  * "<" uniquely defines the behavior of a sort order, this is
313  * a sufficient test.
314  *
315  * XXX This method is rather slow and also requires the
316  * undesirable assumption that the other index AM numbers its
317  * strategies the same as btree. It'd be better to have a way
318  * to explicitly declare the corresponding btree opfamily for
319  * each opfamily of the other index type. But given the lack
320  * of current or foreseeable amcanorder index types, it's not
321  * worth expending more effort on now.
322  */
323  info->sortopfamily = (Oid *) palloc(sizeof(Oid) * nkeycolumns);
324  info->reverse_sort = (bool *) palloc(sizeof(bool) * nkeycolumns);
325  info->nulls_first = (bool *) palloc(sizeof(bool) * nkeycolumns);
326 
327  for (i = 0; i < nkeycolumns; i++)
328  {
329  int16 opt = indexRelation->rd_indoption[i];
330  Oid ltopr;
331  Oid btopfamily;
332  Oid btopcintype;
333  int16 btstrategy;
334 
335  info->reverse_sort[i] = (opt & INDOPTION_DESC) != 0;
336  info->nulls_first[i] = (opt & INDOPTION_NULLS_FIRST) != 0;
337 
338  ltopr = get_opfamily_member(info->opfamily[i],
339  info->opcintype[i],
340  info->opcintype[i],
342  if (OidIsValid(ltopr) &&
344  &btopfamily,
345  &btopcintype,
346  &btstrategy) &&
347  btopcintype == info->opcintype[i] &&
348  btstrategy == BTLessStrategyNumber)
349  {
350  /* Successful mapping */
351  info->sortopfamily[i] = btopfamily;
352  }
353  else
354  {
355  /* Fail ... quietly treat index as unordered */
356  info->sortopfamily = NULL;
357  info->reverse_sort = NULL;
358  info->nulls_first = NULL;
359  break;
360  }
361  }
362  }
363  else
364  {
365  info->sortopfamily = NULL;
366  info->reverse_sort = NULL;
367  info->nulls_first = NULL;
368  }
369 
370  /*
371  * Fetch the index expressions and predicate, if any. We must
372  * modify the copies we obtain from the relcache to have the
373  * correct varno for the parent relation, so that they match up
374  * correctly against qual clauses.
375  */
376  info->indexprs = RelationGetIndexExpressions(indexRelation);
377  info->indpred = RelationGetIndexPredicate(indexRelation);
378  if (info->indexprs && varno != 1)
379  ChangeVarNodes((Node *) info->indexprs, 1, varno, 0);
380  if (info->indpred && varno != 1)
381  ChangeVarNodes((Node *) info->indpred, 1, varno, 0);
382 
383  /* Build targetlist using the completed indexprs data */
384  info->indextlist = build_index_tlist(root, info, relation);
385 
386  info->indrestrictinfo = NIL; /* set later, in indxpath.c */
387  info->predOK = false; /* set later, in indxpath.c */
388  info->unique = index->indisunique;
389  info->immediate = index->indimmediate;
390  info->hypothetical = false;
391 
392  /*
393  * Estimate the index size. If it's not a partial index, we lock
394  * the number-of-tuples estimate to equal the parent table; if it
395  * is partial then we have to use the same methods as we would for
396  * a table, except we can be sure that the index is not larger
397  * than the table.
398  */
399  if (info->indpred == NIL)
400  {
401  info->pages = RelationGetNumberOfBlocks(indexRelation);
402  info->tuples = rel->tuples;
403  }
404  else
405  {
406  double allvisfrac; /* dummy */
407 
408  estimate_rel_size(indexRelation, NULL,
409  &info->pages, &info->tuples, &allvisfrac);
410  if (info->tuples > rel->tuples)
411  info->tuples = rel->tuples;
412  }
413 
414  if (info->relam == BTREE_AM_OID)
415  {
416  /* For btrees, get tree height while we have the index open */
417  info->tree_height = _bt_getrootheight(indexRelation);
418  }
419  else
420  {
421  /* For other index types, just set it to "unknown" for now */
422  info->tree_height = -1;
423  }
424 
425  index_close(indexRelation, NoLock);
426 
427  /*
428  * We've historically used lcons() here. It'd make more sense to
429  * use lappend(), but that causes the planner to change behavior
430  * in cases where two indexes seem equally attractive. For now,
431  * stick with lcons() --- few tables should have so many indexes
432  * that the O(N^2) behavior of lcons() is really a problem.
433  */
434  indexinfos = lcons(info, indexinfos);
435  }
436 
437  list_free(indexoidlist);
438  }
439 
440  rel->indexlist = indexinfos;
441 
442  rel->statlist = get_relation_statistics(rel, relation);
443 
444  /* Grab foreign-table info using the relcache, while we have it */
445  if (relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
446  {
448  rel->fdwroutine = GetFdwRoutineForRelation(relation, true);
449  }
450  else
451  {
452  rel->serverid = InvalidOid;
453  rel->fdwroutine = NULL;
454  }
455 
456  /* Collect info about relation's foreign keys, if relevant */
457  get_relation_foreign_keys(root, rel, relation, inhparent);
458 
459  /*
460  * Collect info about relation's partitioning scheme, if any. Only
461  * inheritance parents may be partitioned.
462  */
463  if (inhparent && relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
464  set_relation_partition_info(root, rel, relation);
465 
466  table_close(relation, NoLock);
467 
468  /*
469  * Allow a plugin to editorialize on the info we obtained from the
470  * catalogs. Actions might include altering the assumed relation size,
471  * removing an index, or adding a hypothetical index to the indexlist.
472  */
474  (*get_relation_info_hook) (root, relationObjectId, inhparent, rel);
475 }
signed short int16
Definition: c.h:361
#define NIL
Definition: pg_list.h:65
struct IndexAmRoutine * rd_indam
Definition: rel.h:188
List * statlist
Definition: pathnodes.h:703
int16 * rd_indoption
Definition: rel.h:193
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
static List * get_relation_statistics(RelOptInfo *rel, Relation relation)
Definition: plancat.c:1294
Oid * indexcollations
Definition: pathnodes.h:832
Relids * attr_needed
Definition: pathnodes.h:698
bool IsSystemRelation(Relation relation)
Definition: catalog.c:68
amgettuple_function amgettuple
Definition: amapi.h:272
int _bt_getrootheight(Relation rel)
Definition: nbtpage.c:604
int LOCKMODE
Definition: lockdefs.h:26
bool amcanorderbyop
Definition: amapi.h:221
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:462
List * indextlist
Definition: pathnodes.h:846
#define RelationGetForm(relation)
Definition: rel.h:450
double tuples
Definition: pathnodes.h:705
Oid reltablespace
Definition: pathnodes.h:694
Definition: nodes.h:529
Oid * sortopfamily
Definition: pathnodes.h:835
int errcode(int sqlerrcode)
Definition: elog.c:610
Oid reltablespace
Definition: pathnodes.h:819
bool IgnoreSystemIndexes
Definition: miscinit.c:77
#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:109
unsigned int Oid
Definition: postgres_ext.h:31
bool RecoveryInProgress(void)
Definition: xlog.c:8069
int tree_height
Definition: pathnodes.h:825
#define OidIsValid(objectId)
Definition: c.h:651
bool amoptionalkey
Definition: amapi.h:229
double allvisfrac
Definition: pathnodes.h:706
signed int int32
Definition: c.h:362
List * RelationGetIndexPredicate(Relation relation)
Definition: relcache.c:4854
struct HeapTupleData * rd_indextuple
Definition: rel.h:176
TransactionId TransactionXmin
Definition: snapmgr.c:166
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:728
Form_pg_index rd_index
Definition: rel.h:174
RelOptInfo * rel
Definition: pathnodes.h:820
bool amoptionalkey
Definition: pathnodes.h:861
amgetbitmap_function amgetbitmap
Definition: amapi.h:273
Oid * rd_indcollation
Definition: rel.h:199
#define ERROR
Definition: elog.h:43
bool(* scan_bitmap_next_block)(TableScanDesc scan, struct TBMIterateResult *tbmres)
Definition: tableam.h:659
amcostestimate_function amcostestimate
Definition: amapi.h:264
#define NoLock
Definition: lockdefs.h:34
bool amcanorderbyop
Definition: pathnodes.h:860
List * RelationGetIndexExpressions(Relation relation)
Definition: relcache.c:4741
PlannerGlobal * glob
Definition: pathnodes.h:181
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:718
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:2124
get_relation_info_hook_type get_relation_info_hook
Definition: plancat.c:60
Oid * rd_opfamily
Definition: rel.h:189
void estimate_rel_size(Relation rel, int32 *attr_widths, BlockNumber *pages, double *tuples, double *allvisfrac)
Definition: plancat.c:949
void(* amcostestimate)()
Definition: pathnodes.h:868
bool amhasgetbitmap
Definition: pathnodes.h:865
bool amcanparallel
Definition: amapi.h:241
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
Index relid
Definition: pathnodes.h:693
RangeTblEntry ** simple_rte_array
Definition: pathnodes.h:211
Oid serverid
Definition: pathnodes.h:714
FormData_pg_index * Form_pg_index
Definition: pg_index.h:68
bool amsearchnulls
Definition: amapi.h:233
List * indrestrictinfo
Definition: pathnodes.h:848
void * palloc0(Size size)
Definition: mcxt.c:980
int rel_parallel_workers
Definition: pathnodes.h:711
const struct TableAmRoutine * rd_tableam
Definition: rel.h:171
#define RelationGetNumberOfBlocks(reln)
Definition: bufmgr.h:211
unsigned int Index
Definition: c.h:482
List * indexlist
Definition: pathnodes.h:702
bool amsearcharray
Definition: amapi.h:231
bool amhasgettuple
Definition: pathnodes.h:864
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:144
List * lcons(void *datum, List *list)
Definition: list.c:453
#define makeNode(_type_)
Definition: nodes.h:577
BlockNumber pages
Definition: pathnodes.h:704
#define Assert(condition)
Definition: c.h:745
static void get_relation_foreign_keys(PlannerInfo *root, RelOptInfo *rel, Relation relation, bool inhparent)
Definition: plancat.c:488
#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
bool amcanorder
Definition: amapi.h:219
int nkeycolumns
Definition: pathnodes.h:829
#define RelationNeedsWAL(relation)
Definition: rel.h:562
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4507
Oid * opcintype
Definition: pathnodes.h:834
Bitmapset * Relids
Definition: pathnodes.h:28
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:158
Oid * opfamily
Definition: pathnodes.h:833
AttrNumber max_attr
Definition: pathnodes.h:697
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:824
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:427
void list_free(List *list)
Definition: list.c:1376
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:359
static List * build_index_tlist(PlannerInfo *root, IndexOptInfo *index, Relation heapRelation)
Definition: plancat.c:1704
int * indexkeys
Definition: pathnodes.h:830
bool * canreturn
Definition: pathnodes.h:839
bytea ** RelationGetIndexAttOptions(Relation relation, bool copy)
Definition: relcache.c:5429
bool amsearchnulls
Definition: pathnodes.h:863
Oid * rd_opcintype
Definition: rel.h:190
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:699
Definition: pg_list.h:50
#define RelationGetRelid(relation)
Definition: rel.h:456
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:192
List * indexprs
Definition: pathnodes.h:843
bool transientPlan
Definition: pathnodes.h:139
AttrNumber min_attr
Definition: pathnodes.h:696

◆ get_relation_statistics()

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

Definition at line 1294 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().

1295 {
1296  List *statoidlist;
1297  List *stainfos = NIL;
1298  ListCell *l;
1299 
1300  statoidlist = RelationGetStatExtList(relation);
1301 
1302  foreach(l, statoidlist)
1303  {
1304  Oid statOid = lfirst_oid(l);
1305  Form_pg_statistic_ext staForm;
1306  HeapTuple htup;
1307  HeapTuple dtup;
1308  Bitmapset *keys = NULL;
1309  int i;
1310 
1311  htup = SearchSysCache1(STATEXTOID, ObjectIdGetDatum(statOid));
1312  if (!HeapTupleIsValid(htup))
1313  elog(ERROR, "cache lookup failed for statistics object %u", statOid);
1314  staForm = (Form_pg_statistic_ext) GETSTRUCT(htup);
1315 
1317  if (!HeapTupleIsValid(dtup))
1318  elog(ERROR, "cache lookup failed for statistics object %u", statOid);
1319 
1320  /*
1321  * First, build the array of columns covered. This is ultimately
1322  * wasted if no stats within the object have actually been built, but
1323  * it doesn't seem worth troubling over that case.
1324  */
1325  for (i = 0; i < staForm->stxkeys.dim1; i++)
1326  keys = bms_add_member(keys, staForm->stxkeys.values[i]);
1327 
1328  /* add one StatisticExtInfo for each kind built */
1329  if (statext_is_kind_built(dtup, STATS_EXT_NDISTINCT))
1330  {
1332 
1333  info->statOid = statOid;
1334  info->rel = rel;
1335  info->kind = STATS_EXT_NDISTINCT;
1336  info->keys = bms_copy(keys);
1337 
1338  stainfos = lappend(stainfos, info);
1339  }
1340 
1341  if (statext_is_kind_built(dtup, STATS_EXT_DEPENDENCIES))
1342  {
1344 
1345  info->statOid = statOid;
1346  info->rel = rel;
1347  info->kind = STATS_EXT_DEPENDENCIES;
1348  info->keys = bms_copy(keys);
1349 
1350  stainfos = lappend(stainfos, info);
1351  }
1352 
1353  if (statext_is_kind_built(dtup, STATS_EXT_MCV))
1354  {
1356 
1357  info->statOid = statOid;
1358  info->rel = rel;
1359  info->kind = STATS_EXT_MCV;
1360  info->keys = bms_copy(keys);
1361 
1362  stainfos = lappend(stainfos, info);
1363  }
1364 
1365  ReleaseSysCache(htup);
1366  ReleaseSysCache(dtup);
1367  bms_free(keys);
1368  }
1369 
1370  list_free(statoidlist);
1371 
1372  return stainfos;
1373 }
#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:43
RelOptInfo * rel
Definition: pathnodes.h:913
List * lappend(List *list, void *datum)
Definition: list.c:321
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1116
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1164
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
#define makeNode(_type_)
Definition: nodes.h:577
#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:4626
Bitmapset * keys
Definition: pathnodes.h:915
void list_free(List *list)
Definition: list.c:1376
#define elog(elevel,...)
Definition: elog.h:214
int i
Definition: pg_list.h:50
FormData_pg_statistic_ext * Form_pg_statistic_ext
#define lfirst_oid(lc)
Definition: pg_list.h:192

◆ has_row_triggers()

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

Definition at line 2059 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().

2060 {
2061  RangeTblEntry *rte = planner_rt_fetch(rti, root);
2062  Relation relation;
2063  TriggerDesc *trigDesc;
2064  bool result = false;
2065 
2066  /* Assume we already have adequate lock */
2067  relation = table_open(rte->relid, NoLock);
2068 
2069  trigDesc = relation->trigdesc;
2070  switch (event)
2071  {
2072  case CMD_INSERT:
2073  if (trigDesc &&
2074  (trigDesc->trig_insert_after_row ||
2075  trigDesc->trig_insert_before_row))
2076  result = true;
2077  break;
2078  case CMD_UPDATE:
2079  if (trigDesc &&
2080  (trigDesc->trig_update_after_row ||
2081  trigDesc->trig_update_before_row))
2082  result = true;
2083  break;
2084  case CMD_DELETE:
2085  if (trigDesc &&
2086  (trigDesc->trig_delete_after_row ||
2087  trigDesc->trig_delete_before_row))
2088  result = true;
2089  break;
2090  default:
2091  elog(ERROR, "unrecognized CmdType: %d", (int) event);
2092  break;
2093  }
2094 
2095  table_close(relation, NoLock);
2096  return result;
2097 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define ERROR
Definition: elog.h:43
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:373
TriggerDesc * trigdesc
Definition: rel.h:115
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:214
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 2100 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().

2101 {
2102  RangeTblEntry *rte = planner_rt_fetch(rti, root);
2103  Relation relation;
2104  TupleDesc tupdesc;
2105  bool result = false;
2106 
2107  /* Assume we already have adequate lock */
2108  relation = table_open(rte->relid, NoLock);
2109 
2110  tupdesc = RelationGetDescr(relation);
2111  result = tupdesc->constr && tupdesc->constr->has_generated_stored;
2112 
2113  table_close(relation, NoLock);
2114 
2115  return result;
2116 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:133
#define RelationGetDescr(relation)
Definition: rel.h:482
bool has_generated_stored
Definition: tupdesc.h:45
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:373
#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 2027 of file plancat.c.

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

Referenced by examine_variable().

2028 {
2029  ListCell *ilist;
2030 
2031  foreach(ilist, rel->indexlist)
2032  {
2033  IndexOptInfo *index = (IndexOptInfo *) lfirst(ilist);
2034 
2035  /*
2036  * Note: ignore partial indexes, since they don't allow us to conclude
2037  * that all attr values are distinct, *unless* they are marked predOK
2038  * which means we know the index's predicate is satisfied by the
2039  * query. We don't take any interest in expressional indexes either.
2040  * Also, a multicolumn unique index doesn't allow us to conclude that
2041  * just the specified attr is unique.
2042  */
2043  if (index->unique &&
2044  index->nkeycolumns == 1 &&
2045  index->indexkeys[0] == attno &&
2046  (index->indpred == NIL || index->predOK))
2047  return true;
2048  }
2049  return false;
2050 }
#define NIL
Definition: pg_list.h:65
Definition: type.h:89
List * indexlist
Definition: pathnodes.h:702
#define lfirst(lc)
Definition: pg_list.h:190
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 601 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().

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

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

◆ join_selectivity()

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

Definition at line 1805 of file plancat.c.

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

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

1811 {
1812  RegProcedure oprjoin = get_oprjoin(operatorid);
1813  float8 result;
1814 
1815  /*
1816  * if the oprjoin procedure is missing for whatever reason, use a
1817  * selectivity of 0.5
1818  */
1819  if (!oprjoin)
1820  return (Selectivity) 0.5;
1821 
1822  result = DatumGetFloat8(OidFunctionCall5Coll(oprjoin,
1823  inputcollid,
1824  PointerGetDatum(root),
1825  ObjectIdGetDatum(operatorid),
1826  PointerGetDatum(args),
1827  Int16GetDatum(jointype),
1828  PointerGetDatum(sjinfo)));
1829 
1830  if (result < 0.0 || result > 1.0)
1831  elog(ERROR, "invalid join selectivity: %f", result);
1832 
1833  return (Selectivity) result;
1834 }
RegProcedure get_oprjoin(Oid opno)
Definition: lsyscache.c:1493
#define PointerGetDatum(X)
Definition: postgres.h:556
regproc RegProcedure
Definition: c.h:518
#define Int16GetDatum(X)
Definition: postgres.h:451
double Selectivity
Definition: nodes.h:662
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
#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:1456
#define elog(elevel,...)
Definition: elog.h:214

◆ relation_excluded_by_constraints()

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

Definition at line 1387 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().

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

◆ restriction_selectivity()

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

Definition at line 1766 of file plancat.c.

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

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

1771 {
1772  RegProcedure oprrest = get_oprrest(operatorid);
1773  float8 result;
1774 
1775  /*
1776  * if the oprrest procedure is missing for whatever reason, use a
1777  * selectivity of 0.5
1778  */
1779  if (!oprrest)
1780  return (Selectivity) 0.5;
1781 
1782  result = DatumGetFloat8(OidFunctionCall4Coll(oprrest,
1783  inputcollid,
1784  PointerGetDatum(root),
1785  ObjectIdGetDatum(operatorid),
1786  PointerGetDatum(args),
1787  Int32GetDatum(varRelid)));
1788 
1789  if (result < 0.0 || result > 1.0)
1790  elog(ERROR, "invalid restriction selectivity: %f", result);
1791 
1792  return (Selectivity) result;
1793 }
#define PointerGetDatum(X)
Definition: postgres.h:556
regproc RegProcedure
Definition: c.h:518
double Selectivity
Definition: nodes.h:662
#define ObjectIdGetDatum(X)
Definition: postgres.h:507
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:498
RegProcedure get_oprrest(Oid opno)
Definition: lsyscache.c:1469
#define DatumGetFloat8(X)
Definition: postgres.h:714
Datum OidFunctionCall4Coll(Oid functionId, Oid collation, Datum arg1, Datum arg2, Datum arg3, Datum arg4)
Definition: fmgr.c:1445
#define Int32GetDatum(X)
Definition: postgres.h:479
#define elog(elevel,...)
Definition: elog.h:214

◆ set_baserel_partition_constraint()

static void set_baserel_partition_constraint ( Relation  relation,
RelOptInfo rel 
)
static

Definition at line 2325 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().

2326 {
2327  List *partconstr;
2328 
2329  if (rel->partition_qual) /* already done */
2330  return;
2331 
2332  /*
2333  * Run the partition quals through const-simplification similar to check
2334  * constraints. We skip canonicalize_qual, though, because partition
2335  * quals should be in canonical form already; also, since the qual is in
2336  * implicit-AND format, we'd have to explicitly convert it to explicit-AND
2337  * format and back again.
2338  */
2339  partconstr = RelationGetPartitionQual(relation);
2340  if (partconstr)
2341  {
2342  partconstr = (List *) expression_planner((Expr *) partconstr);
2343  if (rel->relid != 1)
2344  ChangeVarNodes((Node *) partconstr, 1, rel->relid, 0);
2345  rel->partition_qual = partconstr;
2346  }
2347 }
Expr * expression_planner(Expr *expr)
Definition: planner.c:6151
Definition: nodes.h:529
Index relid
Definition: pathnodes.h:693
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:749
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 2257 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().

2259 {
2260  PartitionKey partkey = RelationGetPartitionKey(relation);
2261  int partnatts;
2262  int cnt;
2263  List **partexprs;
2264  ListCell *lc;
2265  Index varno = rel->relid;
2266 
2267  Assert(IS_SIMPLE_REL(rel) && rel->relid > 0);
2268 
2269  /* A partitioned table should have a partition key. */
2270  Assert(partkey != NULL);
2271 
2272  partnatts = partkey->partnatts;
2273  partexprs = (List **) palloc(sizeof(List *) * partnatts);
2274  lc = list_head(partkey->partexprs);
2275 
2276  for (cnt = 0; cnt < partnatts; cnt++)
2277  {
2278  Expr *partexpr;
2279  AttrNumber attno = partkey->partattrs[cnt];
2280 
2281  if (attno != InvalidAttrNumber)
2282  {
2283  /* Single column partition key is stored as a Var node. */
2284  Assert(attno > 0);
2285 
2286  partexpr = (Expr *) makeVar(varno, attno,
2287  partkey->parttypid[cnt],
2288  partkey->parttypmod[cnt],
2289  partkey->parttypcoll[cnt], 0);
2290  }
2291  else
2292  {
2293  if (lc == NULL)
2294  elog(ERROR, "wrong number of partition key expressions");
2295 
2296  /* Re-stamp the expression with given varno. */
2297  partexpr = (Expr *) copyObject(lfirst(lc));
2298  ChangeVarNodes((Node *) partexpr, 1, varno, 0);
2299  lc = lnext(partkey->partexprs, lc);
2300  }
2301 
2302  /* Base relations have a single expression per key. */
2303  partexprs[cnt] = list_make1(partexpr);
2304  }
2305 
2306  rel->partexprs = partexprs;
2307 
2308  /*
2309  * A base relation does not have nullable partition key expressions, since
2310  * no outer join is involved. We still allocate an array of empty
2311  * expression lists to keep partition key expression handling code simple.
2312  * See build_joinrel_partition_info() and match_expr_to_partition_keys().
2313  */
2314  rel->nullable_partexprs = (List **) palloc0(sizeof(List *) * partnatts);
2315 }
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:321
Definition: nodes.h:529
List * partexprs
Definition: partcache.h:30
PartitionKey RelationGetPartitionKey(Relation rel)
Definition: partcache.c:54
List ** nullable_partexprs
Definition: pathnodes.h:754
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:638
#define list_make1(x1)
Definition: pg_list.h:227
Oid * parttypcoll
Definition: partcache.h:46
List ** partexprs
Definition: pathnodes.h:753
#define ERROR
Definition: elog.h:43
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:693
void * palloc0(Size size)
Definition: mcxt.c:980
AttrNumber * partattrs
Definition: partcache.h:28
unsigned int Index
Definition: c.h:482
int32 * parttypmod
Definition: partcache.h:42
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:190
#define InvalidAttrNumber
Definition: attnum.h:23
void * palloc(Size size)
Definition: mcxt.c:949
#define elog(elevel,...)
Definition: elog.h:214
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
Definition: rewriteManip.c:610
#define copyObject(obj)
Definition: nodes.h:645
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 2124 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().

2126 {
2127  PartitionDesc partdesc;
2128 
2129  /* Create the PartitionDirectory infrastructure if we didn't already */
2130  if (root->glob->partition_directory == NULL)
2131  root->glob->partition_directory =
2133 
2135  relation);
2136  rel->part_scheme = find_partition_scheme(root, relation);
2137  Assert(partdesc != NULL && rel->part_scheme != NULL);
2138  rel->boundinfo = partdesc->boundinfo;
2139  rel->nparts = partdesc->nparts;
2140  set_baserel_partition_key_exprs(relation, rel);
2141  set_baserel_partition_constraint(relation, rel);
2142 }
PartitionDirectory CreatePartitionDirectory(MemoryContext mcxt)
Definition: partdesc.c:284
PartitionBoundInfo boundinfo
Definition: partdesc.h:29
PlannerGlobal * glob
Definition: pathnodes.h:181
int nparts
Definition: pathnodes.h:743
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:746
static void set_baserel_partition_constraint(Relation relation, RelOptInfo *rel)
Definition: plancat.c:2325
static PartitionScheme find_partition_scheme(PlannerInfo *root, Relation rel)
Definition: plancat.c:2150
#define Assert(condition)
Definition: c.h:745
PartitionScheme part_scheme
Definition: pathnodes.h:742
PartitionDesc PartitionDirectoryLookup(PartitionDirectory pdir, Relation rel)
Definition: partdesc.c:316
static void set_baserel_partition_key_exprs(Relation relation, RelOptInfo *rel)
Definition: plancat.c:2257
PartitionDirectory partition_directory
Definition: pathnodes.h:149

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