PostgreSQL Source Code  git master
indxpath.c File Reference
#include "postgres.h"
#include <math.h>
#include "access/stratnum.h"
#include "access/sysattr.h"
#include "catalog/pg_am.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_type.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "optimizer/cost.h"
#include "optimizer/optimizer.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/prep.h"
#include "optimizer/restrictinfo.h"
#include "utils/lsyscache.h"
#include "utils/selfuncs.h"
Include dependency graph for indxpath.c:

Go to the source code of this file.

Data Structures

struct  IndexClauseSet
 
struct  PathClauseUsage
 
struct  ec_member_matches_arg
 

Macros

#define IndexCollMatchesExprColl(idxcollation, exprcollation)    ((idxcollation) == InvalidOid || (idxcollation) == (exprcollation))
 

Enumerations

enum  ScanTypeControl { ST_INDEXSCAN , ST_BITMAPSCAN , ST_ANYSCAN }
 

Functions

static void consider_index_join_clauses (PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *rclauseset, IndexClauseSet *jclauseset, IndexClauseSet *eclauseset, List **bitindexpaths)
 
static void consider_index_join_outer_rels (PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *rclauseset, IndexClauseSet *jclauseset, IndexClauseSet *eclauseset, List **bitindexpaths, List *indexjoinclauses, int considered_clauses, List **considered_relids)
 
static void get_join_index_paths (PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *rclauseset, IndexClauseSet *jclauseset, IndexClauseSet *eclauseset, List **bitindexpaths, Relids relids, List **considered_relids)
 
static bool eclass_already_used (EquivalenceClass *parent_ec, Relids oldrelids, List *indexjoinclauses)
 
static void get_index_paths (PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *clauses, List **bitindexpaths)
 
static Listbuild_index_paths (PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *clauses, bool useful_predicate, ScanTypeControl scantype, bool *skip_nonnative_saop)
 
static Listbuild_paths_for_OR (PlannerInfo *root, RelOptInfo *rel, List *clauses, List *other_clauses)
 
static Listgenerate_bitmap_or_paths (PlannerInfo *root, RelOptInfo *rel, List *clauses, List *other_clauses)
 
static Pathchoose_bitmap_and (PlannerInfo *root, RelOptInfo *rel, List *paths)
 
static int path_usage_comparator (const void *a, const void *b)
 
static Cost bitmap_scan_cost_est (PlannerInfo *root, RelOptInfo *rel, Path *ipath)
 
static Cost bitmap_and_cost_est (PlannerInfo *root, RelOptInfo *rel, List *paths)
 
static PathClauseUsageclassify_index_clause_usage (Path *path, List **clauselist)
 
static void find_indexpath_quals (Path *bitmapqual, List **quals, List **preds)
 
static int find_list_position (Node *node, List **nodelist)
 
static bool check_index_only (RelOptInfo *rel, IndexOptInfo *index)
 
static double get_loop_count (PlannerInfo *root, Index cur_relid, Relids outer_relids)
 
static double adjust_rowcount_for_semijoins (PlannerInfo *root, Index cur_relid, Index outer_relid, double rowcount)
 
static double approximate_joinrel_size (PlannerInfo *root, Relids relids)
 
static void match_restriction_clauses_to_index (PlannerInfo *root, IndexOptInfo *index, IndexClauseSet *clauseset)
 
static void match_join_clauses_to_index (PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *clauseset, List **joinorclauses)
 
static void match_eclass_clauses_to_index (PlannerInfo *root, IndexOptInfo *index, IndexClauseSet *clauseset)
 
static void match_clauses_to_index (PlannerInfo *root, List *clauses, IndexOptInfo *index, IndexClauseSet *clauseset)
 
static void match_clause_to_index (PlannerInfo *root, RestrictInfo *rinfo, IndexOptInfo *index, IndexClauseSet *clauseset)
 
static IndexClausematch_clause_to_indexcol (PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
 
static bool IsBooleanOpfamily (Oid opfamily)
 
static IndexClausematch_boolean_index_clause (PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
 
static IndexClausematch_opclause_to_indexcol (PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
 
static IndexClausematch_funcclause_to_indexcol (PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
 
static IndexClauseget_index_clause_from_support (PlannerInfo *root, RestrictInfo *rinfo, Oid funcid, int indexarg, int indexcol, IndexOptInfo *index)
 
static IndexClausematch_saopclause_to_indexcol (PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
 
static IndexClausematch_rowcompare_to_indexcol (PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
 
static IndexClauseexpand_indexqual_rowcompare (PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index, Oid expr_op, bool var_on_left)
 
static void match_pathkeys_to_index (IndexOptInfo *index, List *pathkeys, List **orderby_clauses_p, List **clause_columns_p)
 
static Exprmatch_clause_to_ordering_op (IndexOptInfo *index, int indexcol, Expr *clause, Oid pk_opfamily)
 
static bool ec_member_matches_indexcol (PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
 
void create_index_paths (PlannerInfo *root, RelOptInfo *rel)
 
void check_index_predicates (PlannerInfo *root, RelOptInfo *rel)
 
bool relation_has_unique_index_for (PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
 
bool relation_has_unique_index_ext (PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist, List **extra_clauses)
 
bool indexcol_is_bool_constant_for_query (PlannerInfo *root, IndexOptInfo *index, int indexcol)
 
bool match_index_to_operand (Node *operand, int indexcol, IndexOptInfo *index)
 
bool is_pseudo_constant_for_index (PlannerInfo *root, Node *expr, IndexOptInfo *index)
 

Macro Definition Documentation

◆ IndexCollMatchesExprColl

#define IndexCollMatchesExprColl (   idxcollation,
  exprcollation 
)     ((idxcollation) == InvalidOid || (idxcollation) == (exprcollation))

Definition at line 40 of file indxpath.c.

Enumeration Type Documentation

◆ ScanTypeControl

Enumerator
ST_INDEXSCAN 
ST_BITMAPSCAN 
ST_ANYSCAN 

Definition at line 44 of file indxpath.c.

45 {
46  ST_INDEXSCAN, /* must support amgettuple */
47  ST_BITMAPSCAN, /* must support amgetbitmap */
48  ST_ANYSCAN, /* either is okay */
ScanTypeControl
Definition: indxpath.c:45
@ ST_ANYSCAN
Definition: indxpath.c:48
@ ST_BITMAPSCAN
Definition: indxpath.c:47
@ ST_INDEXSCAN
Definition: indxpath.c:46

Function Documentation

◆ adjust_rowcount_for_semijoins()

static double adjust_rowcount_for_semijoins ( PlannerInfo root,
Index  cur_relid,
Index  outer_relid,
double  rowcount 
)
static

Definition at line 1882 of file indxpath.c.

1886 {
1887  ListCell *lc;
1888 
1889  foreach(lc, root->join_info_list)
1890  {
1891  SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(lc);
1892 
1893  if (sjinfo->jointype == JOIN_SEMI &&
1894  bms_is_member(cur_relid, sjinfo->syn_lefthand) &&
1895  bms_is_member(outer_relid, sjinfo->syn_righthand))
1896  {
1897  /* Estimate number of unique-ified rows */
1898  double nraw;
1899  double nunique;
1900 
1901  nraw = approximate_joinrel_size(root, sjinfo->syn_righthand);
1902  nunique = estimate_num_groups(root,
1903  sjinfo->semi_rhs_exprs,
1904  nraw,
1905  NULL,
1906  NULL);
1907  if (rowcount > nunique)
1908  rowcount = nunique;
1909  }
1910  }
1911  return rowcount;
1912 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
static double approximate_joinrel_size(PlannerInfo *root, Relids relids)
Definition: indxpath.c:1926
@ JOIN_SEMI
Definition: nodes.h:307
#define lfirst(lc)
Definition: pg_list.h:172
tree ctl root
Definition: radixtree.h:1884
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset, EstimationInfo *estinfo)
Definition: selfuncs.c:3416
Relids syn_lefthand
Definition: pathnodes.h:2884
List * semi_rhs_exprs
Definition: pathnodes.h:2897
JoinType jointype
Definition: pathnodes.h:2886
Relids syn_righthand
Definition: pathnodes.h:2885

References approximate_joinrel_size(), bms_is_member(), estimate_num_groups(), JOIN_SEMI, SpecialJoinInfo::jointype, lfirst, root, SpecialJoinInfo::semi_rhs_exprs, SpecialJoinInfo::syn_lefthand, and SpecialJoinInfo::syn_righthand.

Referenced by get_loop_count().

◆ approximate_joinrel_size()

static double approximate_joinrel_size ( PlannerInfo root,
Relids  relids 
)
static

Definition at line 1926 of file indxpath.c.

1927 {
1928  double rowcount = 1.0;
1929  int relid;
1930 
1931  relid = -1;
1932  while ((relid = bms_next_member(relids, relid)) >= 0)
1933  {
1934  RelOptInfo *rel;
1935 
1936  /* Paranoia: ignore bogus relid indexes */
1937  if (relid >= root->simple_rel_array_size)
1938  continue;
1939  rel = root->simple_rel_array[relid];
1940  if (rel == NULL)
1941  continue;
1942  Assert(rel->relid == relid); /* sanity check on array */
1943 
1944  /* Relation could be proven empty, if so ignore */
1945  if (IS_DUMMY_REL(rel))
1946  continue;
1947 
1948  /* Otherwise, rel's rows estimate should be valid by now */
1949  Assert(rel->rows > 0);
1950 
1951  /* Accumulate product */
1952  rowcount *= rel->rows;
1953  }
1954  return rowcount;
1955 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1306
#define Assert(condition)
Definition: c.h:858
#define IS_DUMMY_REL(r)
Definition: pathnodes.h:1935
Index relid
Definition: pathnodes.h:908
Cardinality rows
Definition: pathnodes.h:867

References Assert, bms_next_member(), IS_DUMMY_REL, RelOptInfo::relid, root, and RelOptInfo::rows.

Referenced by adjust_rowcount_for_semijoins().

◆ bitmap_and_cost_est()

static Cost bitmap_and_cost_est ( PlannerInfo root,
RelOptInfo rel,
List paths 
)
static

Definition at line 1560 of file indxpath.c.

1561 {
1562  BitmapAndPath *apath;
1563 
1564  /*
1565  * Might as well build a real BitmapAndPath here, as the work is slightly
1566  * too complicated to be worth repeating just to save one palloc.
1567  */
1568  apath = create_bitmap_and_path(root, rel, paths);
1569 
1570  return bitmap_scan_cost_est(root, rel, (Path *) apath);
1571 }
static Cost bitmap_scan_cost_est(PlannerInfo *root, RelOptInfo *rel, Path *ipath)
Definition: indxpath.c:1526
BitmapAndPath * create_bitmap_and_path(PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
Definition: pathnode.c:1075

References bitmap_scan_cost_est(), create_bitmap_and_path(), and root.

Referenced by choose_bitmap_and().

◆ bitmap_scan_cost_est()

static Cost bitmap_scan_cost_est ( PlannerInfo root,
RelOptInfo rel,
Path ipath 
)
static

Definition at line 1526 of file indxpath.c.

1527 {
1528  BitmapHeapPath bpath;
1529 
1530  /* Set up a dummy BitmapHeapPath */
1531  bpath.path.type = T_BitmapHeapPath;
1532  bpath.path.pathtype = T_BitmapHeapScan;
1533  bpath.path.parent = rel;
1534  bpath.path.pathtarget = rel->reltarget;
1535  bpath.path.param_info = ipath->param_info;
1536  bpath.path.pathkeys = NIL;
1537  bpath.bitmapqual = ipath;
1538 
1539  /*
1540  * Check the cost of temporary path without considering parallelism.
1541  * Parallel bitmap heap path will be considered at later stage.
1542  */
1543  bpath.path.parallel_workers = 0;
1544 
1545  /* Now we can do cost_bitmap_heap_scan */
1546  cost_bitmap_heap_scan(&bpath.path, root, rel,
1547  bpath.path.param_info,
1548  ipath,
1549  get_loop_count(root, rel->relid,
1550  PATH_REQ_OUTER(ipath)));
1551 
1552  return bpath.path.total_cost;
1553 }
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:1013
static double get_loop_count(PlannerInfo *root, Index cur_relid, Relids outer_relids)
Definition: indxpath.c:1829
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1658
#define NIL
Definition: pg_list.h:68
Path * bitmapqual
Definition: pathnodes.h:1774
List * pathkeys
Definition: pathnodes.h:1654
NodeTag pathtype
Definition: pathnodes.h:1615
int parallel_workers
Definition: pathnodes.h:1646
Cost total_cost
Definition: pathnodes.h:1651
struct PathTarget * reltarget
Definition: pathnodes.h:883

References BitmapHeapPath::bitmapqual, cost_bitmap_heap_scan(), get_loop_count(), NIL, Path::parallel_workers, BitmapHeapPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtype, RelOptInfo::relid, RelOptInfo::reltarget, root, and Path::total_cost.

Referenced by bitmap_and_cost_est(), and choose_bitmap_and().

◆ build_index_paths()

static List * build_index_paths ( PlannerInfo root,
RelOptInfo rel,
IndexOptInfo index,
IndexClauseSet clauses,
bool  useful_predicate,
ScanTypeControl  scantype,
bool skip_nonnative_saop 
)
static

Definition at line 804 of file indxpath.c.

809 {
810  List *result = NIL;
811  IndexPath *ipath;
812  List *index_clauses;
813  Relids outer_relids;
814  double loop_count;
815  List *orderbyclauses;
816  List *orderbyclausecols;
817  List *index_pathkeys;
818  List *useful_pathkeys;
819  bool pathkeys_possibly_useful;
820  bool index_is_ordered;
821  bool index_only_scan;
822  int indexcol;
823 
824  Assert(skip_nonnative_saop != NULL || scantype == ST_BITMAPSCAN);
825 
826  /*
827  * Check that index supports the desired scan type(s)
828  */
829  switch (scantype)
830  {
831  case ST_INDEXSCAN:
832  if (!index->amhasgettuple)
833  return NIL;
834  break;
835  case ST_BITMAPSCAN:
836  if (!index->amhasgetbitmap)
837  return NIL;
838  break;
839  case ST_ANYSCAN:
840  /* either or both are OK */
841  break;
842  }
843 
844  /*
845  * 1. Combine the per-column IndexClause lists into an overall list.
846  *
847  * In the resulting list, clauses are ordered by index key, so that the
848  * column numbers form a nondecreasing sequence. (This order is depended
849  * on by btree and possibly other places.) The list can be empty, if the
850  * index AM allows that.
851  *
852  * We also build a Relids set showing which outer rels are required by the
853  * selected clauses. Any lateral_relids are included in that, but not
854  * otherwise accounted for.
855  */
856  index_clauses = NIL;
857  outer_relids = bms_copy(rel->lateral_relids);
858  for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
859  {
860  ListCell *lc;
861 
862  foreach(lc, clauses->indexclauses[indexcol])
863  {
864  IndexClause *iclause = (IndexClause *) lfirst(lc);
865  RestrictInfo *rinfo = iclause->rinfo;
866 
867  if (skip_nonnative_saop && !index->amsearcharray &&
868  IsA(rinfo->clause, ScalarArrayOpExpr))
869  {
870  /*
871  * Caller asked us to generate IndexPaths that omit any
872  * ScalarArrayOpExpr clauses when the underlying index AM
873  * lacks native support.
874  *
875  * We must omit this clause (and tell caller about it).
876  */
877  *skip_nonnative_saop = true;
878  continue;
879  }
880 
881  /* OK to include this clause */
882  index_clauses = lappend(index_clauses, iclause);
883  outer_relids = bms_add_members(outer_relids,
884  rinfo->clause_relids);
885  }
886 
887  /*
888  * If no clauses match the first index column, check for amoptionalkey
889  * restriction. We can't generate a scan over an index with
890  * amoptionalkey = false unless there's at least one index clause.
891  * (When working on columns after the first, this test cannot fail. It
892  * is always okay for columns after the first to not have any
893  * clauses.)
894  */
895  if (index_clauses == NIL && !index->amoptionalkey)
896  return NIL;
897  }
898 
899  /* We do not want the index's rel itself listed in outer_relids */
900  outer_relids = bms_del_member(outer_relids, rel->relid);
901 
902  /* Compute loop_count for cost estimation purposes */
903  loop_count = get_loop_count(root, rel->relid, outer_relids);
904 
905  /*
906  * 2. Compute pathkeys describing index's ordering, if any, then see how
907  * many of them are actually useful for this query. This is not relevant
908  * if we are only trying to build bitmap indexscans.
909  */
910  pathkeys_possibly_useful = (scantype != ST_BITMAPSCAN &&
911  has_useful_pathkeys(root, rel));
912  index_is_ordered = (index->sortopfamily != NULL);
913  if (index_is_ordered && pathkeys_possibly_useful)
914  {
915  index_pathkeys = build_index_pathkeys(root, index,
917  useful_pathkeys = truncate_useless_pathkeys(root, rel,
918  index_pathkeys);
919  orderbyclauses = NIL;
920  orderbyclausecols = NIL;
921  }
922  else if (index->amcanorderbyop && pathkeys_possibly_useful)
923  {
924  /*
925  * See if we can generate ordering operators for query_pathkeys or at
926  * least some prefix thereof. Matching to just a prefix of the
927  * query_pathkeys will allow an incremental sort to be considered on
928  * the index's partially sorted results.
929  */
930  match_pathkeys_to_index(index, root->query_pathkeys,
931  &orderbyclauses,
932  &orderbyclausecols);
933  if (list_length(root->query_pathkeys) == list_length(orderbyclauses))
934  useful_pathkeys = root->query_pathkeys;
935  else
936  useful_pathkeys = list_copy_head(root->query_pathkeys,
937  list_length(orderbyclauses));
938  }
939  else
940  {
941  useful_pathkeys = NIL;
942  orderbyclauses = NIL;
943  orderbyclausecols = NIL;
944  }
945 
946  /*
947  * 3. Check if an index-only scan is possible. If we're not building
948  * plain indexscans, this isn't relevant since bitmap scans don't support
949  * index data retrieval anyway.
950  */
951  index_only_scan = (scantype != ST_BITMAPSCAN &&
952  check_index_only(rel, index));
953 
954  /*
955  * 4. Generate an indexscan path if there are relevant restriction clauses
956  * in the current clauses, OR the index ordering is potentially useful for
957  * later merging or final output ordering, OR the index has a useful
958  * predicate, OR an index-only scan is possible.
959  */
960  if (index_clauses != NIL || useful_pathkeys != NIL || useful_predicate ||
961  index_only_scan)
962  {
963  ipath = create_index_path(root, index,
964  index_clauses,
965  orderbyclauses,
966  orderbyclausecols,
967  useful_pathkeys,
969  index_only_scan,
970  outer_relids,
971  loop_count,
972  false);
973  result = lappend(result, ipath);
974 
975  /*
976  * If appropriate, consider parallel index scan. We don't allow
977  * parallel index scan for bitmap index scans.
978  */
979  if (index->amcanparallel &&
980  rel->consider_parallel && outer_relids == NULL &&
981  scantype != ST_BITMAPSCAN)
982  {
983  ipath = create_index_path(root, index,
984  index_clauses,
985  orderbyclauses,
986  orderbyclausecols,
987  useful_pathkeys,
989  index_only_scan,
990  outer_relids,
991  loop_count,
992  true);
993 
994  /*
995  * if, after costing the path, we find that it's not worth using
996  * parallel workers, just free it.
997  */
998  if (ipath->path.parallel_workers > 0)
999  add_partial_path(rel, (Path *) ipath);
1000  else
1001  pfree(ipath);
1002  }
1003  }
1004 
1005  /*
1006  * 5. If the index is ordered, a backwards scan might be interesting.
1007  */
1008  if (index_is_ordered && pathkeys_possibly_useful)
1009  {
1010  index_pathkeys = build_index_pathkeys(root, index,
1012  useful_pathkeys = truncate_useless_pathkeys(root, rel,
1013  index_pathkeys);
1014  if (useful_pathkeys != NIL)
1015  {
1016  ipath = create_index_path(root, index,
1017  index_clauses,
1018  NIL,
1019  NIL,
1020  useful_pathkeys,
1022  index_only_scan,
1023  outer_relids,
1024  loop_count,
1025  false);
1026  result = lappend(result, ipath);
1027 
1028  /* If appropriate, consider parallel index scan */
1029  if (index->amcanparallel &&
1030  rel->consider_parallel && outer_relids == NULL &&
1031  scantype != ST_BITMAPSCAN)
1032  {
1033  ipath = create_index_path(root, index,
1034  index_clauses,
1035  NIL,
1036  NIL,
1037  useful_pathkeys,
1039  index_only_scan,
1040  outer_relids,
1041  loop_count,
1042  true);
1043 
1044  /*
1045  * if, after costing the path, we find that it's not worth
1046  * using parallel workers, just free it.
1047  */
1048  if (ipath->path.parallel_workers > 0)
1049  add_partial_path(rel, (Path *) ipath);
1050  else
1051  pfree(ipath);
1052  }
1053  }
1054  }
1055 
1056  return result;
1057 }
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:917
Bitmapset * bms_del_member(Bitmapset *a, int x)
Definition: bitmapset.c:868
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:122
static bool check_index_only(RelOptInfo *rel, IndexOptInfo *index)
Definition: indxpath.c:1730
static void match_pathkeys_to_index(IndexOptInfo *index, List *pathkeys, List **orderby_clauses_p, List **clause_columns_p)
Definition: indxpath.c:3020
List * lappend(List *list, void *datum)
Definition: list.c:339
List * list_copy_head(const List *oldlist, int len)
Definition: list.c:1593
void pfree(void *pointer)
Definition: mcxt.c:1520
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:2261
List * truncate_useless_pathkeys(PlannerInfo *root, RelOptInfo *rel, List *pathkeys)
Definition: pathkeys.c:2215
List * build_index_pathkeys(PlannerInfo *root, IndexOptInfo *index, ScanDirection scandir)
Definition: pathkeys.c:755
IndexPath * create_index_path(PlannerInfo *root, IndexOptInfo *index, List *indexclauses, List *indexorderbys, List *indexorderbycols, List *pathkeys, ScanDirection indexscandir, bool indexonly, Relids required_outer, double loop_count, bool partial_path)
Definition: pathnode.c:993
void add_partial_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:747
static int list_length(const List *l)
Definition: pg_list.h:152
@ BackwardScanDirection
Definition: sdir.h:26
@ ForwardScanDirection
Definition: sdir.h:28
List * indexclauses[INDEX_MAX_KEYS]
Definition: indxpath.c:56
struct RestrictInfo * rinfo
Definition: pathnodes.h:1747
Path path
Definition: pathnodes.h:1698
Definition: pg_list.h:54
bool consider_parallel
Definition: pathnodes.h:877
Relids lateral_relids
Definition: pathnodes.h:903
Expr * clause
Definition: pathnodes.h:2552
Definition: type.h:95

References add_partial_path(), Assert, BackwardScanDirection, bms_add_members(), bms_copy(), bms_del_member(), build_index_pathkeys(), check_index_only(), RestrictInfo::clause, RelOptInfo::consider_parallel, create_index_path(), ForwardScanDirection, get_loop_count(), has_useful_pathkeys(), IndexClauseSet::indexclauses, IsA, lappend(), RelOptInfo::lateral_relids, lfirst, list_copy_head(), list_length(), match_pathkeys_to_index(), NIL, Path::parallel_workers, IndexPath::path, pfree(), RelOptInfo::relid, IndexClause::rinfo, root, ST_ANYSCAN, ST_BITMAPSCAN, ST_INDEXSCAN, and truncate_useless_pathkeys().

Referenced by build_paths_for_OR(), and get_index_paths().

◆ build_paths_for_OR()

static List * build_paths_for_OR ( PlannerInfo root,
RelOptInfo rel,
List clauses,
List other_clauses 
)
static

Definition at line 1086 of file indxpath.c.

1088 {
1089  List *result = NIL;
1090  List *all_clauses = NIL; /* not computed till needed */
1091  ListCell *lc;
1092 
1093  foreach(lc, rel->indexlist)
1094  {
1096  IndexClauseSet clauseset;
1097  List *indexpaths;
1098  bool useful_predicate;
1099 
1100  /* Ignore index if it doesn't support bitmap scans */
1101  if (!index->amhasgetbitmap)
1102  continue;
1103 
1104  /*
1105  * Ignore partial indexes that do not match the query. If a partial
1106  * index is marked predOK then we know it's OK. Otherwise, we have to
1107  * test whether the added clauses are sufficient to imply the
1108  * predicate. If so, we can use the index in the current context.
1109  *
1110  * We set useful_predicate to true iff the predicate was proven using
1111  * the current set of clauses. This is needed to prevent matching a
1112  * predOK index to an arm of an OR, which would be a legal but
1113  * pointlessly inefficient plan. (A better plan will be generated by
1114  * just scanning the predOK index alone, no OR.)
1115  */
1116  useful_predicate = false;
1117  if (index->indpred != NIL)
1118  {
1119  if (index->predOK)
1120  {
1121  /* Usable, but don't set useful_predicate */
1122  }
1123  else
1124  {
1125  /* Form all_clauses if not done already */
1126  if (all_clauses == NIL)
1127  all_clauses = list_concat_copy(clauses, other_clauses);
1128 
1129  if (!predicate_implied_by(index->indpred, all_clauses, false))
1130  continue; /* can't use it at all */
1131 
1132  if (!predicate_implied_by(index->indpred, other_clauses, false))
1133  useful_predicate = true;
1134  }
1135  }
1136 
1137  /*
1138  * Identify the restriction clauses that can match the index.
1139  */
1140  MemSet(&clauseset, 0, sizeof(clauseset));
1141  match_clauses_to_index(root, clauses, index, &clauseset);
1142 
1143  /*
1144  * If no matches so far, and the index predicate isn't useful, we
1145  * don't want it.
1146  */
1147  if (!clauseset.nonempty && !useful_predicate)
1148  continue;
1149 
1150  /*
1151  * Add "other" restriction clauses to the clauseset.
1152  */
1153  match_clauses_to_index(root, other_clauses, index, &clauseset);
1154 
1155  /*
1156  * Construct paths if possible.
1157  */
1158  indexpaths = build_index_paths(root, rel,
1159  index, &clauseset,
1160  useful_predicate,
1161  ST_BITMAPSCAN,
1162  NULL);
1163  result = list_concat(result, indexpaths);
1164  }
1165 
1166  return result;
1167 }
#define MemSet(start, val, len)
Definition: c.h:1020
static List * build_index_paths(PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *clauses, bool useful_predicate, ScanTypeControl scantype, bool *skip_nonnative_saop)
Definition: indxpath.c:804
static void match_clauses_to_index(PlannerInfo *root, List *clauses, IndexOptInfo *index, IndexClauseSet *clauseset)
Definition: indxpath.c:2051
List * list_concat(List *list1, const List *list2)
Definition: list.c:561
List * list_concat_copy(const List *list1, const List *list2)
Definition: list.c:598
bool predicate_implied_by(List *predicate_list, List *clause_list, bool weak)
Definition: predtest.c:152
bool nonempty
Definition: indxpath.c:54
List * indexlist
Definition: pathnodes.h:934

References build_index_paths(), RelOptInfo::indexlist, lfirst, list_concat(), list_concat_copy(), match_clauses_to_index(), MemSet, NIL, IndexClauseSet::nonempty, predicate_implied_by(), root, and ST_BITMAPSCAN.

Referenced by generate_bitmap_or_paths().

◆ check_index_only()

static bool check_index_only ( RelOptInfo rel,
IndexOptInfo index 
)
static

Definition at line 1730 of file indxpath.c.

1731 {
1732  bool result;
1733  Bitmapset *attrs_used = NULL;
1734  Bitmapset *index_canreturn_attrs = NULL;
1735  ListCell *lc;
1736  int i;
1737 
1738  /* Index-only scans must be enabled */
1739  if (!enable_indexonlyscan)
1740  return false;
1741 
1742  /*
1743  * Check that all needed attributes of the relation are available from the
1744  * index.
1745  */
1746 
1747  /*
1748  * First, identify all the attributes needed for joins or final output.
1749  * Note: we must look at rel's targetlist, not the attr_needed data,
1750  * because attr_needed isn't computed for inheritance child rels.
1751  */
1752  pull_varattnos((Node *) rel->reltarget->exprs, rel->relid, &attrs_used);
1753 
1754  /*
1755  * Add all the attributes used by restriction clauses; but consider only
1756  * those clauses not implied by the index predicate, since ones that are
1757  * so implied don't need to be checked explicitly in the plan.
1758  *
1759  * Note: attributes used only in index quals would not be needed at
1760  * runtime either, if we are certain that the index is not lossy. However
1761  * it'd be complicated to account for that accurately, and it doesn't
1762  * matter in most cases, since we'd conclude that such attributes are
1763  * available from the index anyway.
1764  */
1765  foreach(lc, index->indrestrictinfo)
1766  {
1767  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1768 
1769  pull_varattnos((Node *) rinfo->clause, rel->relid, &attrs_used);
1770  }
1771 
1772  /*
1773  * Construct a bitmapset of columns that the index can return back in an
1774  * index-only scan.
1775  */
1776  for (i = 0; i < index->ncolumns; i++)
1777  {
1778  int attno = index->indexkeys[i];
1779 
1780  /*
1781  * For the moment, we just ignore index expressions. It might be nice
1782  * to do something with them, later.
1783  */
1784  if (attno == 0)
1785  continue;
1786 
1787  if (index->canreturn[i])
1788  index_canreturn_attrs =
1789  bms_add_member(index_canreturn_attrs,
1791  }
1792 
1793  /* Do we have all the necessary attributes? */
1794  result = bms_is_subset(attrs_used, index_canreturn_attrs);
1795 
1796  bms_free(attrs_used);
1797  bms_free(index_canreturn_attrs);
1798 
1799  return result;
1800 }
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:412
void bms_free(Bitmapset *a)
Definition: bitmapset.c:239
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:815
bool enable_indexonlyscan
Definition: costsize.c:136
int i
Definition: isn.c:73
Definition: nodes.h:129
List * exprs
Definition: pathnodes.h:1522
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:291

References bms_add_member(), bms_free(), bms_is_subset(), RestrictInfo::clause, enable_indexonlyscan, PathTarget::exprs, FirstLowInvalidHeapAttributeNumber, i, lfirst, pull_varattnos(), RelOptInfo::relid, and RelOptInfo::reltarget.

Referenced by build_index_paths().

◆ check_index_predicates()

void check_index_predicates ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 3244 of file indxpath.c.

3245 {
3246  List *clauselist;
3247  bool have_partial;
3248  bool is_target_rel;
3249  Relids otherrels;
3250  ListCell *lc;
3251 
3252  /* Indexes are available only on base or "other" member relations. */
3253  Assert(IS_SIMPLE_REL(rel));
3254 
3255  /*
3256  * Initialize the indrestrictinfo lists to be identical to
3257  * baserestrictinfo, and check whether there are any partial indexes. If
3258  * not, this is all we need to do.
3259  */
3260  have_partial = false;
3261  foreach(lc, rel->indexlist)
3262  {
3264 
3265  index->indrestrictinfo = rel->baserestrictinfo;
3266  if (index->indpred)
3267  have_partial = true;
3268  }
3269  if (!have_partial)
3270  return;
3271 
3272  /*
3273  * Construct a list of clauses that we can assume true for the purpose of
3274  * proving the index(es) usable. Restriction clauses for the rel are
3275  * always usable, and so are any join clauses that are "movable to" this
3276  * rel. Also, we can consider any EC-derivable join clauses (which must
3277  * be "movable to" this rel, by definition).
3278  */
3279  clauselist = list_copy(rel->baserestrictinfo);
3280 
3281  /* Scan the rel's join clauses */
3282  foreach(lc, rel->joininfo)
3283  {
3284  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
3285 
3286  /* Check if clause can be moved to this rel */
3287  if (!join_clause_is_movable_to(rinfo, rel))
3288  continue;
3289 
3290  clauselist = lappend(clauselist, rinfo);
3291  }
3292 
3293  /*
3294  * Add on any equivalence-derivable join clauses. Computing the correct
3295  * relid sets for generate_join_implied_equalities is slightly tricky
3296  * because the rel could be a child rel rather than a true baserel, and in
3297  * that case we must subtract its parents' relid(s) from all_query_rels.
3298  * Additionally, we mustn't consider clauses that are only computable
3299  * after outer joins that can null the rel.
3300  */
3301  if (rel->reloptkind == RELOPT_OTHER_MEMBER_REL)
3302  otherrels = bms_difference(root->all_query_rels,
3303  find_childrel_parents(root, rel));
3304  else
3305  otherrels = bms_difference(root->all_query_rels, rel->relids);
3306  otherrels = bms_del_members(otherrels, rel->nulling_relids);
3307 
3308  if (!bms_is_empty(otherrels))
3309  clauselist =
3310  list_concat(clauselist,
3312  bms_union(rel->relids,
3313  otherrels),
3314  otherrels,
3315  rel,
3316  NULL));
3317 
3318  /*
3319  * Normally we remove quals that are implied by a partial index's
3320  * predicate from indrestrictinfo, indicating that they need not be
3321  * checked explicitly by an indexscan plan using this index. However, if
3322  * the rel is a target relation of UPDATE/DELETE/MERGE/SELECT FOR UPDATE,
3323  * we cannot remove such quals from the plan, because they need to be in
3324  * the plan so that they will be properly rechecked by EvalPlanQual
3325  * testing. Some day we might want to remove such quals from the main
3326  * plan anyway and pass them through to EvalPlanQual via a side channel;
3327  * but for now, we just don't remove implied quals at all for target
3328  * relations.
3329  */
3330  is_target_rel = (bms_is_member(rel->relid, root->all_result_relids) ||
3331  get_plan_rowmark(root->rowMarks, rel->relid) != NULL);
3332 
3333  /*
3334  * Now try to prove each index predicate true, and compute the
3335  * indrestrictinfo lists for partial indexes. Note that we compute the
3336  * indrestrictinfo list even for non-predOK indexes; this might seem
3337  * wasteful, but we may be able to use such indexes in OR clauses, cf
3338  * generate_bitmap_or_paths().
3339  */
3340  foreach(lc, rel->indexlist)
3341  {
3343  ListCell *lcr;
3344 
3345  if (index->indpred == NIL)
3346  continue; /* ignore non-partial indexes here */
3347 
3348  if (!index->predOK) /* don't repeat work if already proven OK */
3349  index->predOK = predicate_implied_by(index->indpred, clauselist,
3350  false);
3351 
3352  /* If rel is an update target, leave indrestrictinfo as set above */
3353  if (is_target_rel)
3354  continue;
3355 
3356  /* Else compute indrestrictinfo as the non-implied quals */
3357  index->indrestrictinfo = NIL;
3358  foreach(lcr, rel->baserestrictinfo)
3359  {
3360  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lcr);
3361 
3362  /* predicate_implied_by() assumes first arg is immutable */
3363  if (contain_mutable_functions((Node *) rinfo->clause) ||
3365  index->indpred, false))
3366  index->indrestrictinfo = lappend(index->indrestrictinfo, rinfo);
3367  }
3368  }
3369 }
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:251
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:346
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:1161
#define bms_is_empty(a)
Definition: bitmapset.h:118
bool contain_mutable_functions(Node *clause)
Definition: clauses.c:370
List * generate_join_implied_equalities(PlannerInfo *root, Relids join_relids, Relids outer_relids, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo)
Definition: equivclass.c:1392
List * list_copy(const List *oldlist)
Definition: list.c:1573
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:829
@ RELOPT_OTHER_MEMBER_REL
Definition: pathnodes.h:819
#define list_make1(x1)
Definition: pg_list.h:212
PlanRowMark * get_plan_rowmark(List *rowmarks, Index rtindex)
Definition: preptlist.c:509
Relids find_childrel_parents(PlannerInfo *root, RelOptInfo *rel)
Definition: relnode.c:1521
bool join_clause_is_movable_to(RestrictInfo *rinfo, RelOptInfo *baserel)
Definition: restrictinfo.c:584
List * baserestrictinfo
Definition: pathnodes.h:975
List * joininfo
Definition: pathnodes.h:981
Relids relids
Definition: pathnodes.h:861
RelOptKind reloptkind
Definition: pathnodes.h:855
Relids nulling_relids
Definition: pathnodes.h:928

References Assert, RelOptInfo::baserestrictinfo, bms_del_members(), bms_difference(), bms_is_empty, bms_is_member(), bms_union(), RestrictInfo::clause, contain_mutable_functions(), find_childrel_parents(), generate_join_implied_equalities(), get_plan_rowmark(), RelOptInfo::indexlist, IS_SIMPLE_REL, join_clause_is_movable_to(), RelOptInfo::joininfo, lappend(), lfirst, list_concat(), list_copy(), list_make1, NIL, RelOptInfo::nulling_relids, predicate_implied_by(), RelOptInfo::relid, RelOptInfo::relids, RELOPT_OTHER_MEMBER_REL, RelOptInfo::reloptkind, and root.

Referenced by set_plain_rel_size(), and set_tablesample_rel_size().

◆ choose_bitmap_and()

static Path * choose_bitmap_and ( PlannerInfo root,
RelOptInfo rel,
List paths 
)
static

Definition at line 1287 of file indxpath.c.

1288 {
1289  int npaths = list_length(paths);
1290  PathClauseUsage **pathinfoarray;
1291  PathClauseUsage *pathinfo;
1292  List *clauselist;
1293  List *bestpaths = NIL;
1294  Cost bestcost = 0;
1295  int i,
1296  j;
1297  ListCell *l;
1298 
1299  Assert(npaths > 0); /* else caller error */
1300  if (npaths == 1)
1301  return (Path *) linitial(paths); /* easy case */
1302 
1303  /*
1304  * In theory we should consider every nonempty subset of the given paths.
1305  * In practice that seems like overkill, given the crude nature of the
1306  * estimates, not to mention the possible effects of higher-level AND and
1307  * OR clauses. Moreover, it's completely impractical if there are a large
1308  * number of paths, since the work would grow as O(2^N).
1309  *
1310  * As a heuristic, we first check for paths using exactly the same sets of
1311  * WHERE clauses + index predicate conditions, and reject all but the
1312  * cheapest-to-scan in any such group. This primarily gets rid of indexes
1313  * that include the interesting columns but also irrelevant columns. (In
1314  * situations where the DBA has gone overboard on creating variant
1315  * indexes, this can make for a very large reduction in the number of
1316  * paths considered further.)
1317  *
1318  * We then sort the surviving paths with the cheapest-to-scan first, and
1319  * for each path, consider using that path alone as the basis for a bitmap
1320  * scan. Then we consider bitmap AND scans formed from that path plus
1321  * each subsequent (higher-cost) path, adding on a subsequent path if it
1322  * results in a reduction in the estimated total scan cost. This means we
1323  * consider about O(N^2) rather than O(2^N) path combinations, which is
1324  * quite tolerable, especially given than N is usually reasonably small
1325  * because of the prefiltering step. The cheapest of these is returned.
1326  *
1327  * We will only consider AND combinations in which no two indexes use the
1328  * same WHERE clause. This is a bit of a kluge: it's needed because
1329  * costsize.c and clausesel.c aren't very smart about redundant clauses.
1330  * They will usually double-count the redundant clauses, producing a
1331  * too-small selectivity that makes a redundant AND step look like it
1332  * reduces the total cost. Perhaps someday that code will be smarter and
1333  * we can remove this limitation. (But note that this also defends
1334  * against flat-out duplicate input paths, which can happen because
1335  * match_join_clauses_to_index will find the same OR join clauses that
1336  * extract_restriction_or_clauses has pulled OR restriction clauses out
1337  * of.)
1338  *
1339  * For the same reason, we reject AND combinations in which an index
1340  * predicate clause duplicates another clause. Here we find it necessary
1341  * to be even stricter: we'll reject a partial index if any of its
1342  * predicate clauses are implied by the set of WHERE clauses and predicate
1343  * clauses used so far. This covers cases such as a condition "x = 42"
1344  * used with a plain index, followed by a clauseless scan of a partial
1345  * index "WHERE x >= 40 AND x < 50". The partial index has been accepted
1346  * only because "x = 42" was present, and so allowing it would partially
1347  * double-count selectivity. (We could use predicate_implied_by on
1348  * regular qual clauses too, to have a more intelligent, but much more
1349  * expensive, check for redundancy --- but in most cases simple equality
1350  * seems to suffice.)
1351  */
1352 
1353  /*
1354  * Extract clause usage info and detect any paths that use exactly the
1355  * same set of clauses; keep only the cheapest-to-scan of any such groups.
1356  * The surviving paths are put into an array for qsort'ing.
1357  */
1358  pathinfoarray = (PathClauseUsage **)
1359  palloc(npaths * sizeof(PathClauseUsage *));
1360  clauselist = NIL;
1361  npaths = 0;
1362  foreach(l, paths)
1363  {
1364  Path *ipath = (Path *) lfirst(l);
1365 
1366  pathinfo = classify_index_clause_usage(ipath, &clauselist);
1367 
1368  /* If it's unclassifiable, treat it as distinct from all others */
1369  if (pathinfo->unclassifiable)
1370  {
1371  pathinfoarray[npaths++] = pathinfo;
1372  continue;
1373  }
1374 
1375  for (i = 0; i < npaths; i++)
1376  {
1377  if (!pathinfoarray[i]->unclassifiable &&
1378  bms_equal(pathinfo->clauseids, pathinfoarray[i]->clauseids))
1379  break;
1380  }
1381  if (i < npaths)
1382  {
1383  /* duplicate clauseids, keep the cheaper one */
1384  Cost ncost;
1385  Cost ocost;
1386  Selectivity nselec;
1387  Selectivity oselec;
1388 
1389  cost_bitmap_tree_node(pathinfo->path, &ncost, &nselec);
1390  cost_bitmap_tree_node(pathinfoarray[i]->path, &ocost, &oselec);
1391  if (ncost < ocost)
1392  pathinfoarray[i] = pathinfo;
1393  }
1394  else
1395  {
1396  /* not duplicate clauseids, add to array */
1397  pathinfoarray[npaths++] = pathinfo;
1398  }
1399  }
1400 
1401  /* If only one surviving path, we're done */
1402  if (npaths == 1)
1403  return pathinfoarray[0]->path;
1404 
1405  /* Sort the surviving paths by index access cost */
1406  qsort(pathinfoarray, npaths, sizeof(PathClauseUsage *),
1408 
1409  /*
1410  * For each surviving index, consider it as an "AND group leader", and see
1411  * whether adding on any of the later indexes results in an AND path with
1412  * cheaper total cost than before. Then take the cheapest AND group.
1413  *
1414  * Note: paths that are either clauseless or unclassifiable will have
1415  * empty clauseids, so that they will not be rejected by the clauseids
1416  * filter here, nor will they cause later paths to be rejected by it.
1417  */
1418  for (i = 0; i < npaths; i++)
1419  {
1420  Cost costsofar;
1421  List *qualsofar;
1422  Bitmapset *clauseidsofar;
1423 
1424  pathinfo = pathinfoarray[i];
1425  paths = list_make1(pathinfo->path);
1426  costsofar = bitmap_scan_cost_est(root, rel, pathinfo->path);
1427  qualsofar = list_concat_copy(pathinfo->quals, pathinfo->preds);
1428  clauseidsofar = bms_copy(pathinfo->clauseids);
1429 
1430  for (j = i + 1; j < npaths; j++)
1431  {
1432  Cost newcost;
1433 
1434  pathinfo = pathinfoarray[j];
1435  /* Check for redundancy */
1436  if (bms_overlap(pathinfo->clauseids, clauseidsofar))
1437  continue; /* consider it redundant */
1438  if (pathinfo->preds)
1439  {
1440  bool redundant = false;
1441 
1442  /* we check each predicate clause separately */
1443  foreach(l, pathinfo->preds)
1444  {
1445  Node *np = (Node *) lfirst(l);
1446 
1447  if (predicate_implied_by(list_make1(np), qualsofar, false))
1448  {
1449  redundant = true;
1450  break; /* out of inner foreach loop */
1451  }
1452  }
1453  if (redundant)
1454  continue;
1455  }
1456  /* tentatively add new path to paths, so we can estimate cost */
1457  paths = lappend(paths, pathinfo->path);
1458  newcost = bitmap_and_cost_est(root, rel, paths);
1459  if (newcost < costsofar)
1460  {
1461  /* keep new path in paths, update subsidiary variables */
1462  costsofar = newcost;
1463  qualsofar = list_concat(qualsofar, pathinfo->quals);
1464  qualsofar = list_concat(qualsofar, pathinfo->preds);
1465  clauseidsofar = bms_add_members(clauseidsofar,
1466  pathinfo->clauseids);
1467  }
1468  else
1469  {
1470  /* reject new path, remove it from paths list */
1471  paths = list_truncate(paths, list_length(paths) - 1);
1472  }
1473  }
1474 
1475  /* Keep the cheapest AND-group (or singleton) */
1476  if (i == 0 || costsofar < bestcost)
1477  {
1478  bestpaths = paths;
1479  bestcost = costsofar;
1480  }
1481 
1482  /* some easy cleanup (we don't try real hard though) */
1483  list_free(qualsofar);
1484  }
1485 
1486  if (list_length(bestpaths) == 1)
1487  return (Path *) linitial(bestpaths); /* no need for AND */
1488  return (Path *) create_bitmap_and_path(root, rel, bestpaths);
1489 }
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:142
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:582
void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec)
Definition: costsize.c:1114
static Cost bitmap_and_cost_est(PlannerInfo *root, RelOptInfo *rel, List *paths)
Definition: indxpath.c:1560
static PathClauseUsage * classify_index_clause_usage(Path *path, List **clauselist)
Definition: indxpath.c:1589
static int path_usage_comparator(const void *a, const void *b)
Definition: indxpath.c:1493
int j
Definition: isn.c:74
List * list_truncate(List *list, int new_size)
Definition: list.c:631
void list_free(List *list)
Definition: list.c:1546
void * palloc(Size size)
Definition: mcxt.c:1316
double Cost
Definition: nodes.h:251
double Selectivity
Definition: nodes.h:250
#define linitial(l)
Definition: pg_list.h:178
#define qsort(a, b, c, d)
Definition: port.h:449
List * quals
Definition: indxpath.c:63
List * preds
Definition: indxpath.c:64
Bitmapset * clauseids
Definition: indxpath.c:65
bool unclassifiable
Definition: indxpath.c:66
Path * path
Definition: indxpath.c:62

References Assert, bitmap_and_cost_est(), bitmap_scan_cost_est(), bms_add_members(), bms_copy(), bms_equal(), bms_overlap(), classify_index_clause_usage(), PathClauseUsage::clauseids, cost_bitmap_tree_node(), create_bitmap_and_path(), i, j, lappend(), lfirst, linitial, list_concat(), list_concat_copy(), list_free(), list_length(), list_make1, list_truncate(), NIL, palloc(), PathClauseUsage::path, path_usage_comparator(), predicate_implied_by(), PathClauseUsage::preds, qsort, PathClauseUsage::quals, root, and PathClauseUsage::unclassifiable.

Referenced by create_index_paths(), and generate_bitmap_or_paths().

◆ classify_index_clause_usage()

static PathClauseUsage * classify_index_clause_usage ( Path path,
List **  clauselist 
)
static

Definition at line 1589 of file indxpath.c.

1590 {
1591  PathClauseUsage *result;
1592  Bitmapset *clauseids;
1593  ListCell *lc;
1594 
1595  result = (PathClauseUsage *) palloc(sizeof(PathClauseUsage));
1596  result->path = path;
1597 
1598  /* Recursively find the quals and preds used by the path */
1599  result->quals = NIL;
1600  result->preds = NIL;
1601  find_indexpath_quals(path, &result->quals, &result->preds);
1602 
1603  /*
1604  * Some machine-generated queries have outlandish numbers of qual clauses.
1605  * To avoid getting into O(N^2) behavior even in this preliminary
1606  * classification step, we want to limit the number of entries we can
1607  * accumulate in *clauselist. Treat any path with more than 100 quals +
1608  * preds as unclassifiable, which will cause calling code to consider it
1609  * distinct from all other paths.
1610  */
1611  if (list_length(result->quals) + list_length(result->preds) > 100)
1612  {
1613  result->clauseids = NULL;
1614  result->unclassifiable = true;
1615  return result;
1616  }
1617 
1618  /* Build up a bitmapset representing the quals and preds */
1619  clauseids = NULL;
1620  foreach(lc, result->quals)
1621  {
1622  Node *node = (Node *) lfirst(lc);
1623 
1624  clauseids = bms_add_member(clauseids,
1625  find_list_position(node, clauselist));
1626  }
1627  foreach(lc, result->preds)
1628  {
1629  Node *node = (Node *) lfirst(lc);
1630 
1631  clauseids = bms_add_member(clauseids,
1632  find_list_position(node, clauselist));
1633  }
1634  result->clauseids = clauseids;
1635  result->unclassifiable = false;
1636 
1637  return result;
1638 }
static void find_indexpath_quals(Path *bitmapqual, List **quals, List **preds)
Definition: indxpath.c:1657
static int find_list_position(Node *node, List **nodelist)
Definition: indxpath.c:1704

References bms_add_member(), PathClauseUsage::clauseids, find_indexpath_quals(), find_list_position(), lfirst, list_length(), NIL, palloc(), PathClauseUsage::path, PathClauseUsage::preds, PathClauseUsage::quals, and PathClauseUsage::unclassifiable.

Referenced by choose_bitmap_and().

◆ consider_index_join_clauses()

static void consider_index_join_clauses ( PlannerInfo root,
RelOptInfo rel,
IndexOptInfo index,
IndexClauseSet rclauseset,
IndexClauseSet jclauseset,
IndexClauseSet eclauseset,
List **  bitindexpaths 
)
static

Definition at line 431 of file indxpath.c.

437 {
438  int considered_clauses = 0;
439  List *considered_relids = NIL;
440  int indexcol;
441 
442  /*
443  * The strategy here is to identify every potentially useful set of outer
444  * rels that can provide indexable join clauses. For each such set,
445  * select all the join clauses available from those outer rels, add on all
446  * the indexable restriction clauses, and generate plain and/or bitmap
447  * index paths for that set of clauses. This is based on the assumption
448  * that it's always better to apply a clause as an indexqual than as a
449  * filter (qpqual); which is where an available clause would end up being
450  * applied if we omit it from the indexquals.
451  *
452  * This looks expensive, but in most practical cases there won't be very
453  * many distinct sets of outer rels to consider. As a safety valve when
454  * that's not true, we use a heuristic: limit the number of outer rel sets
455  * considered to a multiple of the number of clauses considered. (We'll
456  * always consider using each individual join clause, though.)
457  *
458  * For simplicity in selecting relevant clauses, we represent each set of
459  * outer rels as a maximum set of clause_relids --- that is, the indexed
460  * relation itself is also included in the relids set. considered_relids
461  * lists all relids sets we've already tried.
462  */
463  for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
464  {
465  /* Consider each applicable simple join clause */
466  considered_clauses += list_length(jclauseset->indexclauses[indexcol]);
468  rclauseset, jclauseset, eclauseset,
469  bitindexpaths,
470  jclauseset->indexclauses[indexcol],
471  considered_clauses,
472  &considered_relids);
473  /* Consider each applicable eclass join clause */
474  considered_clauses += list_length(eclauseset->indexclauses[indexcol]);
476  rclauseset, jclauseset, eclauseset,
477  bitindexpaths,
478  eclauseset->indexclauses[indexcol],
479  considered_clauses,
480  &considered_relids);
481  }
482 }
static void consider_index_join_outer_rels(PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *rclauseset, IndexClauseSet *jclauseset, IndexClauseSet *eclauseset, List **bitindexpaths, List *indexjoinclauses, int considered_clauses, List **considered_relids)
Definition: indxpath.c:497

References consider_index_join_outer_rels(), IndexClauseSet::indexclauses, list_length(), NIL, and root.

Referenced by create_index_paths().

◆ consider_index_join_outer_rels()

static void consider_index_join_outer_rels ( PlannerInfo root,
RelOptInfo rel,
IndexOptInfo index,
IndexClauseSet rclauseset,
IndexClauseSet jclauseset,
IndexClauseSet eclauseset,
List **  bitindexpaths,
List indexjoinclauses,
int  considered_clauses,
List **  considered_relids 
)
static

Definition at line 497 of file indxpath.c.

506 {
507  ListCell *lc;
508 
509  /* Examine relids of each joinclause in the given list */
510  foreach(lc, indexjoinclauses)
511  {
512  IndexClause *iclause = (IndexClause *) lfirst(lc);
513  Relids clause_relids = iclause->rinfo->clause_relids;
514  EquivalenceClass *parent_ec = iclause->rinfo->parent_ec;
515  int num_considered_relids;
516 
517  /* If we already tried its relids set, no need to do so again */
518  if (list_member(*considered_relids, clause_relids))
519  continue;
520 
521  /*
522  * Generate the union of this clause's relids set with each
523  * previously-tried set. This ensures we try this clause along with
524  * every interesting subset of previous clauses. However, to avoid
525  * exponential growth of planning time when there are many clauses,
526  * limit the number of relid sets accepted to 10 * considered_clauses.
527  *
528  * Note: get_join_index_paths appends entries to *considered_relids,
529  * but we do not need to visit such newly-added entries within this
530  * loop, so we don't use foreach() here. No real harm would be done
531  * if we did visit them, since the subset check would reject them; but
532  * it would waste some cycles.
533  */
534  num_considered_relids = list_length(*considered_relids);
535  for (int pos = 0; pos < num_considered_relids; pos++)
536  {
537  Relids oldrelids = (Relids) list_nth(*considered_relids, pos);
538 
539  /*
540  * If either is a subset of the other, no new set is possible.
541  * This isn't a complete test for redundancy, but it's easy and
542  * cheap. get_join_index_paths will check more carefully if we
543  * already generated the same relids set.
544  */
545  if (bms_subset_compare(clause_relids, oldrelids) != BMS_DIFFERENT)
546  continue;
547 
548  /*
549  * If this clause was derived from an equivalence class, the
550  * clause list may contain other clauses derived from the same
551  * eclass. We should not consider that combining this clause with
552  * one of those clauses generates a usefully different
553  * parameterization; so skip if any clause derived from the same
554  * eclass would already have been included when using oldrelids.
555  */
556  if (parent_ec &&
557  eclass_already_used(parent_ec, oldrelids,
558  indexjoinclauses))
559  continue;
560 
561  /*
562  * If the number of relid sets considered exceeds our heuristic
563  * limit, stop considering combinations of clauses. We'll still
564  * consider the current clause alone, though (below this loop).
565  */
566  if (list_length(*considered_relids) >= 10 * considered_clauses)
567  break;
568 
569  /* OK, try the union set */
571  rclauseset, jclauseset, eclauseset,
572  bitindexpaths,
573  bms_union(clause_relids, oldrelids),
574  considered_relids);
575  }
576 
577  /* Also try this set of relids by itself */
579  rclauseset, jclauseset, eclauseset,
580  bitindexpaths,
581  clause_relids,
582  considered_relids);
583  }
584 }
BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:445
@ BMS_DIFFERENT
Definition: bitmapset.h:65
static void get_join_index_paths(PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *rclauseset, IndexClauseSet *jclauseset, IndexClauseSet *eclauseset, List **bitindexpaths, Relids relids, List **considered_relids)
Definition: indxpath.c:600
static bool eclass_already_used(EquivalenceClass *parent_ec, Relids oldrelids, List *indexjoinclauses)
Definition: indxpath.c:678
bool list_member(const List *list, const void *datum)
Definition: list.c:661
Bitmapset * Relids
Definition: pathnodes.h:30
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299

References BMS_DIFFERENT, bms_subset_compare(), bms_union(), eclass_already_used(), get_join_index_paths(), lfirst, list_length(), list_member(), list_nth(), IndexClause::rinfo, and root.

Referenced by consider_index_join_clauses().

◆ create_index_paths()

void create_index_paths ( PlannerInfo root,
RelOptInfo rel 
)

Definition at line 234 of file indxpath.c.

235 {
236  List *indexpaths;
237  List *bitindexpaths;
238  List *bitjoinpaths;
239  List *joinorclauses;
240  IndexClauseSet rclauseset;
241  IndexClauseSet jclauseset;
242  IndexClauseSet eclauseset;
243  ListCell *lc;
244 
245  /* Skip the whole mess if no indexes */
246  if (rel->indexlist == NIL)
247  return;
248 
249  /* Bitmap paths are collected and then dealt with at the end */
250  bitindexpaths = bitjoinpaths = joinorclauses = NIL;
251 
252  /* Examine each index in turn */
253  foreach(lc, rel->indexlist)
254  {
256 
257  /* Protect limited-size array in IndexClauseSets */
258  Assert(index->nkeycolumns <= INDEX_MAX_KEYS);
259 
260  /*
261  * Ignore partial indexes that do not match the query.
262  * (generate_bitmap_or_paths() might be able to do something with
263  * them, but that's of no concern here.)
264  */
265  if (index->indpred != NIL && !index->predOK)
266  continue;
267 
268  /*
269  * Identify the restriction clauses that can match the index.
270  */
271  MemSet(&rclauseset, 0, sizeof(rclauseset));
273 
274  /*
275  * Build index paths from the restriction clauses. These will be
276  * non-parameterized paths. Plain paths go directly to add_path(),
277  * bitmap paths are added to bitindexpaths to be handled below.
278  */
279  get_index_paths(root, rel, index, &rclauseset,
280  &bitindexpaths);
281 
282  /*
283  * Identify the join clauses that can match the index. For the moment
284  * we keep them separate from the restriction clauses. Note that this
285  * step finds only "loose" join clauses that have not been merged into
286  * EquivalenceClasses. Also, collect join OR clauses for later.
287  */
288  MemSet(&jclauseset, 0, sizeof(jclauseset));
290  &jclauseset, &joinorclauses);
291 
292  /*
293  * Look for EquivalenceClasses that can generate joinclauses matching
294  * the index.
295  */
296  MemSet(&eclauseset, 0, sizeof(eclauseset));
298  &eclauseset);
299 
300  /*
301  * If we found any plain or eclass join clauses, build parameterized
302  * index paths using them.
303  */
304  if (jclauseset.nonempty || eclauseset.nonempty)
306  &rclauseset,
307  &jclauseset,
308  &eclauseset,
309  &bitjoinpaths);
310  }
311 
312  /*
313  * Generate BitmapOrPaths for any suitable OR-clauses present in the
314  * restriction list. Add these to bitindexpaths.
315  */
316  indexpaths = generate_bitmap_or_paths(root, rel,
317  rel->baserestrictinfo, NIL);
318  bitindexpaths = list_concat(bitindexpaths, indexpaths);
319 
320  /*
321  * Likewise, generate BitmapOrPaths for any suitable OR-clauses present in
322  * the joinclause list. Add these to bitjoinpaths.
323  */
324  indexpaths = generate_bitmap_or_paths(root, rel,
325  joinorclauses, rel->baserestrictinfo);
326  bitjoinpaths = list_concat(bitjoinpaths, indexpaths);
327 
328  /*
329  * If we found anything usable, generate a BitmapHeapPath for the most
330  * promising combination of restriction bitmap index paths. Note there
331  * will be only one such path no matter how many indexes exist. This
332  * should be sufficient since there's basically only one figure of merit
333  * (total cost) for such a path.
334  */
335  if (bitindexpaths != NIL)
336  {
337  Path *bitmapqual;
338  BitmapHeapPath *bpath;
339 
340  bitmapqual = choose_bitmap_and(root, rel, bitindexpaths);
341  bpath = create_bitmap_heap_path(root, rel, bitmapqual,
342  rel->lateral_relids, 1.0, 0);
343  add_path(rel, (Path *) bpath);
344 
345  /* create a partial bitmap heap path */
346  if (rel->consider_parallel && rel->lateral_relids == NULL)
347  create_partial_bitmap_paths(root, rel, bitmapqual);
348  }
349 
350  /*
351  * Likewise, if we found anything usable, generate BitmapHeapPaths for the
352  * most promising combinations of join bitmap index paths. Our strategy
353  * is to generate one such path for each distinct parameterization seen
354  * among the available bitmap index paths. This may look pretty
355  * expensive, but usually there won't be very many distinct
356  * parameterizations. (This logic is quite similar to that in
357  * consider_index_join_clauses, but we're working with whole paths not
358  * individual clauses.)
359  */
360  if (bitjoinpaths != NIL)
361  {
362  List *all_path_outers;
363 
364  /* Identify each distinct parameterization seen in bitjoinpaths */
365  all_path_outers = NIL;
366  foreach(lc, bitjoinpaths)
367  {
368  Path *path = (Path *) lfirst(lc);
369  Relids required_outer = PATH_REQ_OUTER(path);
370 
371  all_path_outers = list_append_unique(all_path_outers,
372  required_outer);
373  }
374 
375  /* Now, for each distinct parameterization set ... */
376  foreach(lc, all_path_outers)
377  {
378  Relids max_outers = (Relids) lfirst(lc);
379  List *this_path_set;
380  Path *bitmapqual;
381  Relids required_outer;
382  double loop_count;
383  BitmapHeapPath *bpath;
384  ListCell *lcp;
385 
386  /* Identify all the bitmap join paths needing no more than that */
387  this_path_set = NIL;
388  foreach(lcp, bitjoinpaths)
389  {
390  Path *path = (Path *) lfirst(lcp);
391 
392  if (bms_is_subset(PATH_REQ_OUTER(path), max_outers))
393  this_path_set = lappend(this_path_set, path);
394  }
395 
396  /*
397  * Add in restriction bitmap paths, since they can be used
398  * together with any join paths.
399  */
400  this_path_set = list_concat(this_path_set, bitindexpaths);
401 
402  /* Select best AND combination for this parameterization */
403  bitmapqual = choose_bitmap_and(root, rel, this_path_set);
404 
405  /* And push that path into the mix */
406  required_outer = PATH_REQ_OUTER(bitmapqual);
407  loop_count = get_loop_count(root, rel->relid, required_outer);
408  bpath = create_bitmap_heap_path(root, rel, bitmapqual,
409  required_outer, loop_count, 0);
410  add_path(rel, (Path *) bpath);
411  }
412  }
413 }
void create_partial_bitmap_paths(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual)
Definition: allpaths.c:4179
static Path * choose_bitmap_and(PlannerInfo *root, RelOptInfo *rel, List *paths)
Definition: indxpath.c:1287
static void match_join_clauses_to_index(PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *clauseset, List **joinorclauses)
Definition: indxpath.c:1983
static void match_eclass_clauses_to_index(PlannerInfo *root, IndexOptInfo *index, IndexClauseSet *clauseset)
Definition: indxpath.c:2013
static void get_index_paths(PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *clauses, List **bitindexpaths)
Definition: indxpath.c:710
static void consider_index_join_clauses(PlannerInfo *root, RelOptInfo *rel, IndexOptInfo *index, IndexClauseSet *rclauseset, IndexClauseSet *jclauseset, IndexClauseSet *eclauseset, List **bitindexpaths)
Definition: indxpath.c:431
static void match_restriction_clauses_to_index(PlannerInfo *root, IndexOptInfo *index, IndexClauseSet *clauseset)
Definition: indxpath.c:1968
static List * generate_bitmap_or_paths(PlannerInfo *root, RelOptInfo *rel, List *clauses, List *other_clauses)
Definition: indxpath.c:1180
List * list_append_unique(List *list, void *datum)
Definition: list.c:1343
void add_path(RelOptInfo *parent_rel, Path *new_path)
Definition: pathnode.c:420
BitmapHeapPath * create_bitmap_heap_path(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count, int parallel_degree)
Definition: pathnode.c:1042
#define INDEX_MAX_KEYS

References add_path(), Assert, RelOptInfo::baserestrictinfo, bms_is_subset(), choose_bitmap_and(), consider_index_join_clauses(), RelOptInfo::consider_parallel, create_bitmap_heap_path(), create_partial_bitmap_paths(), generate_bitmap_or_paths(), get_index_paths(), get_loop_count(), INDEX_MAX_KEYS, RelOptInfo::indexlist, lappend(), RelOptInfo::lateral_relids, lfirst, list_append_unique(), list_concat(), match_eclass_clauses_to_index(), match_join_clauses_to_index(), match_restriction_clauses_to_index(), MemSet, NIL, IndexClauseSet::nonempty, PATH_REQ_OUTER, RelOptInfo::relid, and root.

Referenced by set_plain_rel_pathlist().

◆ ec_member_matches_indexcol()

static bool ec_member_matches_indexcol ( PlannerInfo root,
RelOptInfo rel,
EquivalenceClass ec,
EquivalenceMember em,
void *  arg 
)
static

Definition at line 3382 of file indxpath.c.

3385 {
3386  IndexOptInfo *index = ((ec_member_matches_arg *) arg)->index;
3387  int indexcol = ((ec_member_matches_arg *) arg)->indexcol;
3388  Oid curFamily;
3389  Oid curCollation;
3390 
3391  Assert(indexcol < index->nkeycolumns);
3392 
3393  curFamily = index->opfamily[indexcol];
3394  curCollation = index->indexcollations[indexcol];
3395 
3396  /*
3397  * If it's a btree index, we can reject it if its opfamily isn't
3398  * compatible with the EC, since no clause generated from the EC could be
3399  * used with the index. For non-btree indexes, we can't easily tell
3400  * whether clauses generated from the EC could be used with the index, so
3401  * don't check the opfamily. This might mean we return "true" for a
3402  * useless EC, so we have to recheck the results of
3403  * generate_implied_equalities_for_column; see
3404  * match_eclass_clauses_to_index.
3405  */
3406  if (index->relam == BTREE_AM_OID &&
3407  !list_member_oid(ec->ec_opfamilies, curFamily))
3408  return false;
3409 
3410  /* We insist on collation match for all index types, though */
3411  if (!IndexCollMatchesExprColl(curCollation, ec->ec_collation))
3412  return false;
3413 
3414  return match_index_to_operand((Node *) em->em_expr, indexcol, index);
3415 }
#define IndexCollMatchesExprColl(idxcollation, exprcollation)
Definition: indxpath.c:40
bool match_index_to_operand(Node *operand, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:3704
bool list_member_oid(const List *list, Oid datum)
Definition: list.c:722
void * arg
unsigned int Oid
Definition: postgres_ext.h:31
List * ec_opfamilies
Definition: pathnodes.h:1379

References arg, Assert, EquivalenceClass::ec_collation, EquivalenceClass::ec_opfamilies, EquivalenceMember::em_expr, IndexCollMatchesExprColl, list_member_oid(), and match_index_to_operand().

Referenced by match_eclass_clauses_to_index().

◆ eclass_already_used()

static bool eclass_already_used ( EquivalenceClass parent_ec,
Relids  oldrelids,
List indexjoinclauses 
)
static

Definition at line 678 of file indxpath.c.

680 {
681  ListCell *lc;
682 
683  foreach(lc, indexjoinclauses)
684  {
685  IndexClause *iclause = (IndexClause *) lfirst(lc);
686  RestrictInfo *rinfo = iclause->rinfo;
687 
688  if (rinfo->parent_ec == parent_ec &&
689  bms_is_subset(rinfo->clause_relids, oldrelids))
690  return true;
691  }
692  return false;
693 }

References bms_is_subset(), lfirst, and IndexClause::rinfo.

Referenced by consider_index_join_outer_rels().

◆ expand_indexqual_rowcompare()

static IndexClause * expand_indexqual_rowcompare ( PlannerInfo root,
RestrictInfo rinfo,
int  indexcol,
IndexOptInfo index,
Oid  expr_op,
bool  var_on_left 
)
static

Definition at line 2798 of file indxpath.c.

2804 {
2805  IndexClause *iclause = makeNode(IndexClause);
2806  RowCompareExpr *clause = (RowCompareExpr *) rinfo->clause;
2807  int op_strategy;
2808  Oid op_lefttype;
2809  Oid op_righttype;
2810  int matching_cols;
2811  List *expr_ops;
2812  List *opfamilies;
2813  List *lefttypes;
2814  List *righttypes;
2815  List *new_ops;
2816  List *var_args;
2817  List *non_var_args;
2818 
2819  iclause->rinfo = rinfo;
2820  iclause->indexcol = indexcol;
2821 
2822  if (var_on_left)
2823  {
2824  var_args = clause->largs;
2825  non_var_args = clause->rargs;
2826  }
2827  else
2828  {
2829  var_args = clause->rargs;
2830  non_var_args = clause->largs;
2831  }
2832 
2833  get_op_opfamily_properties(expr_op, index->opfamily[indexcol], false,
2834  &op_strategy,
2835  &op_lefttype,
2836  &op_righttype);
2837 
2838  /* Initialize returned list of which index columns are used */
2839  iclause->indexcols = list_make1_int(indexcol);
2840 
2841  /* Build lists of ops, opfamilies and operator datatypes in case needed */
2842  expr_ops = list_make1_oid(expr_op);
2843  opfamilies = list_make1_oid(index->opfamily[indexcol]);
2844  lefttypes = list_make1_oid(op_lefttype);
2845  righttypes = list_make1_oid(op_righttype);
2846 
2847  /*
2848  * See how many of the remaining columns match some index column in the
2849  * same way. As in match_clause_to_indexcol(), the "other" side of any
2850  * potential index condition is OK as long as it doesn't use Vars from the
2851  * indexed relation.
2852  */
2853  matching_cols = 1;
2854 
2855  while (matching_cols < list_length(var_args))
2856  {
2857  Node *varop = (Node *) list_nth(var_args, matching_cols);
2858  Node *constop = (Node *) list_nth(non_var_args, matching_cols);
2859  int i;
2860 
2861  expr_op = list_nth_oid(clause->opnos, matching_cols);
2862  if (!var_on_left)
2863  {
2864  /* indexkey is on right, so commute the operator */
2865  expr_op = get_commutator(expr_op);
2866  if (expr_op == InvalidOid)
2867  break; /* operator is not usable */
2868  }
2869  if (bms_is_member(index->rel->relid, pull_varnos(root, constop)))
2870  break; /* no good, Var on wrong side */
2871  if (contain_volatile_functions(constop))
2872  break; /* no good, volatile comparison value */
2873 
2874  /*
2875  * The Var side can match any key column of the index.
2876  */
2877  for (i = 0; i < index->nkeycolumns; i++)
2878  {
2879  if (match_index_to_operand(varop, i, index) &&
2880  get_op_opfamily_strategy(expr_op,
2881  index->opfamily[i]) == op_strategy &&
2882  IndexCollMatchesExprColl(index->indexcollations[i],
2883  list_nth_oid(clause->inputcollids,
2884  matching_cols)))
2885  break;
2886  }
2887  if (i >= index->nkeycolumns)
2888  break; /* no match found */
2889 
2890  /* Add column number to returned list */
2891  iclause->indexcols = lappend_int(iclause->indexcols, i);
2892 
2893  /* Add operator info to lists */
2894  get_op_opfamily_properties(expr_op, index->opfamily[i], false,
2895  &op_strategy,
2896  &op_lefttype,
2897  &op_righttype);
2898  expr_ops = lappend_oid(expr_ops, expr_op);
2899  opfamilies = lappend_oid(opfamilies, index->opfamily[i]);
2900  lefttypes = lappend_oid(lefttypes, op_lefttype);
2901  righttypes = lappend_oid(righttypes, op_righttype);
2902 
2903  /* This column matches, keep scanning */
2904  matching_cols++;
2905  }
2906 
2907  /* Result is non-lossy if all columns are usable as index quals */
2908  iclause->lossy = (matching_cols != list_length(clause->opnos));
2909 
2910  /*
2911  * We can use rinfo->clause as-is if we have var on left and it's all
2912  * usable as index quals.
2913  */
2914  if (var_on_left && !iclause->lossy)
2915  iclause->indexquals = list_make1(rinfo);
2916  else
2917  {
2918  /*
2919  * We have to generate a modified rowcompare (possibly just one
2920  * OpExpr). The painful part of this is changing < to <= or > to >=,
2921  * so deal with that first.
2922  */
2923  if (!iclause->lossy)
2924  {
2925  /* very easy, just use the commuted operators */
2926  new_ops = expr_ops;
2927  }
2928  else if (op_strategy == BTLessEqualStrategyNumber ||
2929  op_strategy == BTGreaterEqualStrategyNumber)
2930  {
2931  /* easy, just use the same (possibly commuted) operators */
2932  new_ops = list_truncate(expr_ops, matching_cols);
2933  }
2934  else
2935  {
2936  ListCell *opfamilies_cell;
2937  ListCell *lefttypes_cell;
2938  ListCell *righttypes_cell;
2939 
2940  if (op_strategy == BTLessStrategyNumber)
2941  op_strategy = BTLessEqualStrategyNumber;
2942  else if (op_strategy == BTGreaterStrategyNumber)
2943  op_strategy = BTGreaterEqualStrategyNumber;
2944  else
2945  elog(ERROR, "unexpected strategy number %d", op_strategy);
2946  new_ops = NIL;
2947  forthree(opfamilies_cell, opfamilies,
2948  lefttypes_cell, lefttypes,
2949  righttypes_cell, righttypes)
2950  {
2951  Oid opfam = lfirst_oid(opfamilies_cell);
2952  Oid lefttype = lfirst_oid(lefttypes_cell);
2953  Oid righttype = lfirst_oid(righttypes_cell);
2954 
2955  expr_op = get_opfamily_member(opfam, lefttype, righttype,
2956  op_strategy);
2957  if (!OidIsValid(expr_op)) /* should not happen */
2958  elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",
2959  op_strategy, lefttype, righttype, opfam);
2960  new_ops = lappend_oid(new_ops, expr_op);
2961  }
2962  }
2963 
2964  /* If we have more than one matching col, create a subset rowcompare */
2965  if (matching_cols > 1)
2966  {
2968 
2969  rc->rctype = (RowCompareType) op_strategy;
2970  rc->opnos = new_ops;
2971  rc->opfamilies = list_copy_head(clause->opfamilies,
2972  matching_cols);
2973  rc->inputcollids = list_copy_head(clause->inputcollids,
2974  matching_cols);
2975  rc->largs = list_copy_head(var_args, matching_cols);
2976  rc->rargs = list_copy_head(non_var_args, matching_cols);
2978  (Expr *) rc));
2979  }
2980  else
2981  {
2982  Expr *op;
2983 
2984  /* We don't report an index column list in this case */
2985  iclause->indexcols = NIL;
2986 
2987  op = make_opclause(linitial_oid(new_ops), BOOLOID, false,
2988  copyObject(linitial(var_args)),
2989  copyObject(linitial(non_var_args)),
2990  InvalidOid,
2991  linitial_oid(clause->inputcollids));
2993  }
2994  }
2995 
2996  return iclause;
2997 }
#define OidIsValid(objectId)
Definition: c.h:775
bool contain_volatile_functions(Node *clause)
Definition: clauses.c:538
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
List * lappend_int(List *list, int datum)
Definition: list.c:357
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
Definition: lsyscache.c:136
int get_op_opfamily_strategy(Oid opno, Oid opfamily)
Definition: lsyscache.c:83
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
Definition: lsyscache.c:166
Oid get_commutator(Oid opno)
Definition: lsyscache.c:1509
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
Definition: makefuncs.c:628
#define copyObject(obj)
Definition: nodes.h:224
#define makeNode(_type_)
Definition: nodes.h:155
static Oid list_nth_oid(const List *list, int n)
Definition: pg_list.h:321
#define list_make1_oid(x1)
Definition: pg_list.h:242
#define forthree(cell1, list1, cell2, list2, cell3, list3)
Definition: pg_list.h:563
#define list_make1_int(x1)
Definition: pg_list.h:227
#define linitial_oid(l)
Definition: pg_list.h:180
#define lfirst_oid(lc)
Definition: pg_list.h:174
#define InvalidOid
Definition: postgres_ext.h:36
RowCompareType
Definition: primnodes.h:1423
#define make_simple_restrictinfo(root, clause)
Definition: restrictinfo.h:21
#define BTGreaterStrategyNumber
Definition: stratnum.h:33
#define BTLessStrategyNumber
Definition: stratnum.h:29
#define BTLessEqualStrategyNumber
Definition: stratnum.h:30
#define BTGreaterEqualStrategyNumber
Definition: stratnum.h:32
AttrNumber indexcol
Definition: pathnodes.h:1750
List * indexcols
Definition: pathnodes.h:1751
List * indexquals
Definition: pathnodes.h:1748
RowCompareType rctype
Definition: primnodes.h:1438
Relids pull_varnos(PlannerInfo *root, Node *node)
Definition: var.c:108

References bms_is_member(), BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, RestrictInfo::clause, contain_volatile_functions(), copyObject, elog, ERROR, forthree, get_commutator(), get_op_opfamily_properties(), get_op_opfamily_strategy(), get_opfamily_member(), i, if(), IndexClause::indexcol, IndexCollMatchesExprColl, IndexClause::indexcols, IndexClause::indexquals, InvalidOid, lappend_int(), lappend_oid(), RowCompareExpr::largs, lfirst_oid, linitial, linitial_oid, list_copy_head(), list_length(), list_make1, list_make1_int, list_make1_oid, list_nth(), list_nth_oid(), list_truncate(), IndexClause::lossy, make_opclause(), make_simple_restrictinfo, makeNode, match_index_to_operand(), NIL, OidIsValid, pull_varnos(), RowCompareExpr::rargs, RowCompareExpr::rctype, IndexClause::rinfo, and root.

Referenced by match_rowcompare_to_indexcol().

◆ find_indexpath_quals()

static void find_indexpath_quals ( Path bitmapqual,
List **  quals,
List **  preds 
)
static

Definition at line 1657 of file indxpath.c.

1658 {
1659  if (IsA(bitmapqual, BitmapAndPath))
1660  {
1661  BitmapAndPath *apath = (BitmapAndPath *) bitmapqual;
1662  ListCell *l;
1663 
1664  foreach(l, apath->bitmapquals)
1665  {
1666  find_indexpath_quals((Path *) lfirst(l), quals, preds);
1667  }
1668  }
1669  else if (IsA(bitmapqual, BitmapOrPath))
1670  {
1671  BitmapOrPath *opath = (BitmapOrPath *) bitmapqual;
1672  ListCell *l;
1673 
1674  foreach(l, opath->bitmapquals)
1675  {
1676  find_indexpath_quals((Path *) lfirst(l), quals, preds);
1677  }
1678  }
1679  else if (IsA(bitmapqual, IndexPath))
1680  {
1681  IndexPath *ipath = (IndexPath *) bitmapqual;
1682  ListCell *l;
1683 
1684  foreach(l, ipath->indexclauses)
1685  {
1686  IndexClause *iclause = (IndexClause *) lfirst(l);
1687 
1688  *quals = lappend(*quals, iclause->rinfo->clause);
1689  }
1690  *preds = list_concat(*preds, ipath->indexinfo->indpred);
1691  }
1692  else
1693  elog(ERROR, "unrecognized node type: %d", nodeTag(bitmapqual));
1694 }
#define nodeTag(nodeptr)
Definition: nodes.h:133
List * bitmapquals
Definition: pathnodes.h:1786
List * bitmapquals
Definition: pathnodes.h:1799
List * indpred
Definition: pathnodes.h:1161
List * indexclauses
Definition: pathnodes.h:1700
IndexOptInfo * indexinfo
Definition: pathnodes.h:1699

References BitmapAndPath::bitmapquals, BitmapOrPath::bitmapquals, RestrictInfo::clause, elog, ERROR, IndexPath::indexclauses, IndexPath::indexinfo, IndexOptInfo::indpred, IsA, lappend(), lfirst, list_concat(), nodeTag, and IndexClause::rinfo.

Referenced by classify_index_clause_usage().

◆ find_list_position()

static int find_list_position ( Node node,
List **  nodelist 
)
static

Definition at line 1704 of file indxpath.c.

1705 {
1706  int i;
1707  ListCell *lc;
1708 
1709  i = 0;
1710  foreach(lc, *nodelist)
1711  {
1712  Node *oldnode = (Node *) lfirst(lc);
1713 
1714  if (equal(node, oldnode))
1715  return i;
1716  i++;
1717  }
1718 
1719  *nodelist = lappend(*nodelist, node);
1720 
1721  return i;
1722 }
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223

References equal(), i, lappend(), and lfirst.

Referenced by classify_index_clause_usage().

◆ generate_bitmap_or_paths()

static List * generate_bitmap_or_paths ( PlannerInfo root,
RelOptInfo rel,
List clauses,
List other_clauses 
)
static

Definition at line 1180 of file indxpath.c.

1182 {
1183  List *result = NIL;
1184  List *all_clauses;
1185  ListCell *lc;
1186 
1187  /*
1188  * We can use both the current and other clauses as context for
1189  * build_paths_for_OR; no need to remove ORs from the lists.
1190  */
1191  all_clauses = list_concat_copy(clauses, other_clauses);
1192 
1193  foreach(lc, clauses)
1194  {
1195  RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
1196  List *pathlist;
1197  Path *bitmapqual;
1198  ListCell *j;
1199 
1200  /* Ignore RestrictInfos that aren't ORs */
1201  if (!restriction_is_or_clause(rinfo))
1202  continue;
1203 
1204  /*
1205  * We must be able to match at least one index to each of the arms of
1206  * the OR, else we can't use it.
1207  */
1208  pathlist = NIL;
1209  foreach(j, ((BoolExpr *) rinfo->orclause)->args)
1210  {
1211  Node *orarg = (Node *) lfirst(j);
1212  List *indlist;
1213 
1214  /* OR arguments should be ANDs or sub-RestrictInfos */
1215  if (is_andclause(orarg))
1216  {
1217  List *andargs = ((BoolExpr *) orarg)->args;
1218 
1219  indlist = build_paths_for_OR(root, rel,
1220  andargs,
1221  all_clauses);
1222 
1223  /* Recurse in case there are sub-ORs */
1224  indlist = list_concat(indlist,
1226  andargs,
1227  all_clauses));
1228  }
1229  else
1230  {
1231  RestrictInfo *ri = castNode(RestrictInfo, orarg);
1232  List *orargs;
1233 
1235  orargs = list_make1(ri);
1236 
1237  indlist = build_paths_for_OR(root, rel,
1238  orargs,
1239  all_clauses);
1240  }
1241 
1242  /*
1243  * If nothing matched this arm, we can't do anything with this OR
1244  * clause.
1245  */
1246  if (indlist == NIL)
1247  {
1248  pathlist = NIL;
1249  break;
1250  }
1251 
1252  /*
1253  * OK, pick the most promising AND combination, and add it to
1254  * pathlist.
1255  */
1256  bitmapqual = choose_bitmap_and(root, rel, indlist);
1257  pathlist = lappend(pathlist, bitmapqual);
1258  }
1259 
1260  /*
1261  * If we have a match for every arm, then turn them into a
1262  * BitmapOrPath, and add to result list.
1263  */
1264  if (pathlist != NIL)
1265  {
1266  bitmapqual = (Path *) create_bitmap_or_path(root, rel, pathlist);
1267  result = lappend(result, bitmapqual);
1268  }
1269  }
1270 
1271  return result;
1272 }
static List * build_paths_for_OR(PlannerInfo *root, RelOptInfo *rel, List *clauses, List *other_clauses)
Definition: indxpath.c:1086
static bool is_andclause(const void *clause)
Definition: nodeFuncs.h:105
#define castNode(_type_, nodeptr)
Definition: nodes.h:176
BitmapOrPath * create_bitmap_or_path(PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
Definition: pathnode.c:1127
#define lfirst_node(type, lc)
Definition: pg_list.h:176
bool restriction_is_or_clause(RestrictInfo *restrictinfo)
Definition: restrictinfo.c:416

References Assert, build_paths_for_OR(), castNode, choose_bitmap_and(), create_bitmap_or_path(), is_andclause(), j, lappend(), lfirst, lfirst_node, list_concat(), list_concat_copy(), list_make1, NIL, restriction_is_or_clause(), and root.

Referenced by create_index_paths().

◆ get_index_clause_from_support()

static IndexClause * get_index_clause_from_support ( PlannerInfo root,
RestrictInfo rinfo,
Oid  funcid,
int  indexarg,
int  indexcol,
IndexOptInfo index 
)
static

Definition at line 2557 of file indxpath.c.

2563 {
2564  Oid prosupport = get_func_support(funcid);
2566  List *sresult;
2567 
2568  if (!OidIsValid(prosupport))
2569  return NULL;
2570 
2571  req.type = T_SupportRequestIndexCondition;
2572  req.root = root;
2573  req.funcid = funcid;
2574  req.node = (Node *) rinfo->clause;
2575  req.indexarg = indexarg;
2576  req.index = index;
2577  req.indexcol = indexcol;
2578  req.opfamily = index->opfamily[indexcol];
2579  req.indexcollation = index->indexcollations[indexcol];
2580 
2581  req.lossy = true; /* default assumption */
2582 
2583  sresult = (List *)
2584  DatumGetPointer(OidFunctionCall1(prosupport,
2585  PointerGetDatum(&req)));
2586 
2587  if (sresult != NIL)
2588  {
2589  IndexClause *iclause = makeNode(IndexClause);
2590  List *indexquals = NIL;
2591  ListCell *lc;
2592 
2593  /*
2594  * The support function API says it should just give back bare
2595  * clauses, so here we must wrap each one in a RestrictInfo.
2596  */
2597  foreach(lc, sresult)
2598  {
2599  Expr *clause = (Expr *) lfirst(lc);
2600 
2601  indexquals = lappend(indexquals,
2602  make_simple_restrictinfo(root, clause));
2603  }
2604 
2605  iclause->rinfo = rinfo;
2606  iclause->indexquals = indexquals;
2607  iclause->lossy = req.lossy;
2608  iclause->indexcol = indexcol;
2609  iclause->indexcols = NIL;
2610 
2611  return iclause;
2612  }
2613 
2614  return NULL;
2615 }
#define OidFunctionCall1(functionId, arg1)
Definition: fmgr.h:680
RegProcedure get_func_support(Oid funcid)
Definition: lsyscache.c:1858
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
struct IndexOptInfo * index
Definition: supportnodes.h:232
struct PlannerInfo * root
Definition: supportnodes.h:228

References RestrictInfo::clause, DatumGetPointer(), SupportRequestIndexCondition::funcid, get_func_support(), SupportRequestIndexCondition::index, SupportRequestIndexCondition::indexarg, IndexClause::indexcol, SupportRequestIndexCondition::indexcol, SupportRequestIndexCondition::indexcollation, IndexClause::indexcols, IndexClause::indexquals, lappend(), lfirst, IndexClause::lossy, SupportRequestIndexCondition::lossy, make_simple_restrictinfo, makeNode, NIL, SupportRequestIndexCondition::node, OidFunctionCall1, OidIsValid, SupportRequestIndexCondition::opfamily, PointerGetDatum(), IndexClause::rinfo, root, SupportRequestIndexCondition::root, and SupportRequestIndexCondition::type.

Referenced by match_funcclause_to_indexcol(), and match_opclause_to_indexcol().

◆ get_index_paths()

static void get_index_paths ( PlannerInfo root,
RelOptInfo rel,
IndexOptInfo index,
IndexClauseSet clauses,
List **  bitindexpaths 
)
static

Definition at line 710 of file indxpath.c.

713 {
714  List *indexpaths;
715  bool skip_nonnative_saop = false;
716  ListCell *lc;
717 
718  /*
719  * Build simple index paths using the clauses. Allow ScalarArrayOpExpr
720  * clauses only if the index AM supports them natively.
721  */
722  indexpaths = build_index_paths(root, rel,
723  index, clauses,
724  index->predOK,
725  ST_ANYSCAN,
726  &skip_nonnative_saop);
727 
728  /*
729  * Submit all the ones that can form plain IndexScan plans to add_path. (A
730  * plain IndexPath can represent either a plain IndexScan or an
731  * IndexOnlyScan, but for our purposes here that distinction does not
732  * matter. However, some of the indexes might support only bitmap scans,
733  * and those we mustn't submit to add_path here.)
734  *
735  * Also, pick out the ones that are usable as bitmap scans. For that, we
736  * must discard indexes that don't support bitmap scans, and we also are
737  * only interested in paths that have some selectivity; we should discard
738  * anything that was generated solely for ordering purposes.
739  */
740  foreach(lc, indexpaths)
741  {
742  IndexPath *ipath = (IndexPath *) lfirst(lc);
743 
744  if (index->amhasgettuple)
745  add_path(rel, (Path *) ipath);
746 
747  if (index->amhasgetbitmap &&
748  (ipath->path.pathkeys == NIL ||
749  ipath->indexselectivity < 1.0))
750  *bitindexpaths = lappend(*bitindexpaths, ipath);
751  }
752 
753  /*
754  * If there were ScalarArrayOpExpr clauses that the index can't handle
755  * natively, generate bitmap scan paths relying on executor-managed
756  * ScalarArrayOpExpr.
757  */
758  if (skip_nonnative_saop)
759  {
760  indexpaths = build_index_paths(root, rel,
761  index, clauses,
762  false,
764  NULL);
765  *bitindexpaths = list_concat(*bitindexpaths, indexpaths);
766  }
767 }
Selectivity indexselectivity
Definition: pathnodes.h:1705

References add_path(), build_index_paths(), IndexPath::indexselectivity, lappend(), lfirst, list_concat(), NIL, IndexPath::path, Path::pathkeys, root, ST_ANYSCAN, and ST_BITMAPSCAN.

Referenced by create_index_paths(), and get_join_index_paths().

◆ get_join_index_paths()

static void get_join_index_paths ( PlannerInfo root,
RelOptInfo rel,
IndexOptInfo index,
IndexClauseSet rclauseset,
IndexClauseSet jclauseset,
IndexClauseSet eclauseset,
List **  bitindexpaths,
Relids  relids,
List **  considered_relids 
)
static

Definition at line 600 of file indxpath.c.

608 {
609  IndexClauseSet clauseset;
610  int indexcol;
611 
612  /* If we already considered this relids set, don't repeat the work */
613  if (list_member(*considered_relids, relids))
614  return;
615 
616  /* Identify indexclauses usable with this relids set */
617  MemSet(&clauseset, 0, sizeof(clauseset));
618 
619  for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
620  {
621  ListCell *lc;
622 
623  /* First find applicable simple join clauses */
624  foreach(lc, jclauseset->indexclauses[indexcol])
625  {
626  IndexClause *iclause = (IndexClause *) lfirst(lc);
627 
628  if (bms_is_subset(iclause->rinfo->clause_relids, relids))
629  clauseset.indexclauses[indexcol] =
630  lappend(clauseset.indexclauses[indexcol], iclause);
631  }
632 
633  /*
634  * Add applicable eclass join clauses. The clauses generated for each
635  * column are redundant (cf generate_implied_equalities_for_column),
636  * so we need at most one. This is the only exception to the general
637  * rule of using all available index clauses.
638  */
639  foreach(lc, eclauseset->indexclauses[indexcol])
640  {
641  IndexClause *iclause = (IndexClause *) lfirst(lc);
642 
643  if (bms_is_subset(iclause->rinfo->clause_relids, relids))
644  {
645  clauseset.indexclauses[indexcol] =
646  lappend(clauseset.indexclauses[indexcol], iclause);
647  break;
648  }
649  }
650 
651  /* Add restriction clauses */
652  clauseset.indexclauses[indexcol] =
653  list_concat(clauseset.indexclauses[indexcol],
654  rclauseset->indexclauses[indexcol]);
655 
656  if (clauseset.indexclauses[indexcol] != NIL)
657  clauseset.nonempty = true;
658  }
659 
660  /* We should have found something, else caller passed silly relids */
661  Assert(clauseset.nonempty);
662 
663  /* Build index path(s) using the collected set of clauses */
664  get_index_paths(root, rel, index, &clauseset, bitindexpaths);
665 
666  /*
667  * Remember we considered paths for this set of relids.
668  */
669  *considered_relids = lappend(*considered_relids, relids);
670 }

References Assert, bms_is_subset(), get_index_paths(), IndexClauseSet::indexclauses, lappend(), lfirst, list_concat(), list_member(), MemSet, NIL, IndexClauseSet::nonempty, IndexClause::rinfo, and root.

Referenced by consider_index_join_outer_rels().

◆ get_loop_count()

static double get_loop_count ( PlannerInfo root,
Index  cur_relid,
Relids  outer_relids 
)
static

Definition at line 1829 of file indxpath.c.

1830 {
1831  double result;
1832  int outer_relid;
1833 
1834  /* For a non-parameterized path, just return 1.0 quickly */
1835  if (outer_relids == NULL)
1836  return 1.0;
1837 
1838  result = 0.0;
1839  outer_relid = -1;
1840  while ((outer_relid = bms_next_member(outer_relids, outer_relid)) >= 0)
1841  {
1842  RelOptInfo *outer_rel;
1843  double rowcount;
1844 
1845  /* Paranoia: ignore bogus relid indexes */
1846  if (outer_relid >= root->simple_rel_array_size)
1847  continue;
1848  outer_rel = root->simple_rel_array[outer_relid];
1849  if (outer_rel == NULL)
1850  continue;
1851  Assert(outer_rel->relid == outer_relid); /* sanity check on array */
1852 
1853  /* Other relation could be proven empty, if so ignore */
1854  if (IS_DUMMY_REL(outer_rel))
1855  continue;
1856 
1857  /* Otherwise, rel's rows estimate should be valid by now */
1858  Assert(outer_rel->rows > 0);
1859 
1860  /* Check to see if rel is on the inside of any semijoins */
1862  cur_relid,
1863  outer_relid,
1864  outer_rel->rows);
1865 
1866  /* Remember smallest row count estimate among the outer rels */
1867  if (result == 0.0 || result > rowcount)
1868  result = rowcount;
1869  }
1870  /* Return 1.0 if we found no valid relations (shouldn't happen) */
1871  return (result > 0.0) ? result : 1.0;
1872 }
static double adjust_rowcount_for_semijoins(PlannerInfo *root, Index cur_relid, Index outer_relid, double rowcount)
Definition: indxpath.c:1882

References adjust_rowcount_for_semijoins(), Assert, bms_next_member(), IS_DUMMY_REL, RelOptInfo::relid, root, and RelOptInfo::rows.

Referenced by bitmap_scan_cost_est(), build_index_paths(), and create_index_paths().

◆ indexcol_is_bool_constant_for_query()

bool indexcol_is_bool_constant_for_query ( PlannerInfo root,
IndexOptInfo index,
int  indexcol 
)

Definition at line 3653 of file indxpath.c.

3656 {
3657  ListCell *lc;
3658 
3659  /* If the index isn't boolean, we can't possibly get a match */
3660  if (!IsBooleanOpfamily(index->opfamily[indexcol]))
3661  return false;
3662 
3663  /* Check each restriction clause for the index's rel */
3664  foreach(lc, index->rel->baserestrictinfo)
3665  {
3666  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
3667 
3668  /*
3669  * As in match_clause_to_indexcol, never match pseudoconstants to
3670  * indexes. (It might be semantically okay to do so here, but the
3671  * odds of getting a match are negligible, so don't waste the cycles.)
3672  */
3673  if (rinfo->pseudoconstant)
3674  continue;
3675 
3676  /* See if we can match the clause's expression to the index column */
3677  if (match_boolean_index_clause(root, rinfo, indexcol, index))
3678  return true;
3679  }
3680 
3681  return false;
3682 }
static bool IsBooleanOpfamily(Oid opfamily)
Definition: indxpath.c:2280
static IndexClause * match_boolean_index_clause(PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:2305

References IsBooleanOpfamily(), lfirst, match_boolean_index_clause(), and root.

Referenced by build_index_pathkeys().

◆ is_pseudo_constant_for_index()

bool is_pseudo_constant_for_index ( PlannerInfo root,
Node expr,
IndexOptInfo index 
)

Definition at line 3790 of file indxpath.c.

3791 {
3792  /* pull_varnos is cheaper than volatility check, so do that first */
3793  if (bms_is_member(index->rel->relid, pull_varnos(root, expr)))
3794  return false; /* no good, contains Var of table */
3795  if (contain_volatile_functions(expr))
3796  return false; /* no good, volatile comparison value */
3797  return true;
3798 }

References bms_is_member(), contain_volatile_functions(), pull_varnos(), and root.

◆ IsBooleanOpfamily()

static bool IsBooleanOpfamily ( Oid  opfamily)
static

Definition at line 2280 of file indxpath.c.

2281 {
2282  if (opfamily < FirstNormalObjectId)
2283  return IsBuiltinBooleanOpfamily(opfamily);
2284  else
2285  return op_in_opfamily(BooleanEqualOperator, opfamily);
2286 }
bool op_in_opfamily(Oid opno, Oid opfamily)
Definition: lsyscache.c:66
#define FirstNormalObjectId
Definition: transam.h:197

References FirstNormalObjectId, and op_in_opfamily().

Referenced by indexcol_is_bool_constant_for_query(), and match_clause_to_indexcol().

◆ match_boolean_index_clause()

static IndexClause * match_boolean_index_clause ( PlannerInfo root,
RestrictInfo rinfo,
int  indexcol,
IndexOptInfo index 
)
static

Definition at line 2305 of file indxpath.c.

2309 {
2310  Node *clause = (Node *) rinfo->clause;
2311  Expr *op = NULL;
2312 
2313  /* Direct match? */
2314  if (match_index_to_operand(clause, indexcol, index))
2315  {
2316  /* convert to indexkey = TRUE */
2317  op = make_opclause(BooleanEqualOperator, BOOLOID, false,
2318  (Expr *) clause,
2319  (Expr *) makeBoolConst(true, false),
2321  }
2322  /* NOT clause? */
2323  else if (is_notclause(clause))
2324  {
2325  Node *arg = (Node *) get_notclausearg((Expr *) clause);
2326 
2327  if (match_index_to_operand(arg, indexcol, index))
2328  {
2329  /* convert to indexkey = FALSE */
2330  op = make_opclause(BooleanEqualOperator, BOOLOID, false,
2331  (Expr *) arg,
2332  (Expr *) makeBoolConst(false, false),
2334  }
2335  }
2336 
2337  /*
2338  * Since we only consider clauses at top level of WHERE, we can convert
2339  * indexkey IS TRUE and indexkey IS FALSE to index searches as well. The
2340  * different meaning for NULL isn't important.
2341  */
2342  else if (clause && IsA(clause, BooleanTest))
2343  {
2344  BooleanTest *btest = (BooleanTest *) clause;
2345  Node *arg = (Node *) btest->arg;
2346 
2347  if (btest->booltesttype == IS_TRUE &&
2348  match_index_to_operand(arg, indexcol, index))
2349  {
2350  /* convert to indexkey = TRUE */
2351  op = make_opclause(BooleanEqualOperator, BOOLOID, false,
2352  (Expr *) arg,
2353  (Expr *) makeBoolConst(true, false),
2355  }
2356  else if (btest->booltesttype == IS_FALSE &&
2357  match_index_to_operand(arg, indexcol, index))
2358  {
2359  /* convert to indexkey = FALSE */
2360  op = make_opclause(BooleanEqualOperator, BOOLOID, false,
2361  (Expr *) arg,
2362  (Expr *) makeBoolConst(false, false),
2364  }
2365  }
2366 
2367  /*
2368  * If we successfully made an operator clause from the given qual, we must
2369  * wrap it in an IndexClause. It's not lossy.
2370  */
2371  if (op)
2372  {
2373  IndexClause *iclause = makeNode(IndexClause);
2374 
2375  iclause->rinfo = rinfo;
2377  iclause->lossy = false;
2378  iclause->indexcol = indexcol;
2379  iclause->indexcols = NIL;
2380  return iclause;
2381  }
2382 
2383  return NULL;
2384 }
Node * makeBoolConst(bool value, bool isnull)
Definition: makefuncs.c:359
static Expr * get_notclausearg(const void *notclause)
Definition: nodeFuncs.h:132
static bool is_notclause(const void *clause)
Definition: nodeFuncs.h:123
@ IS_TRUE
Definition: primnodes.h:1948
@ IS_FALSE
Definition: primnodes.h:1948
BoolTestType booltesttype
Definition: primnodes.h:1955
Expr * arg
Definition: primnodes.h:1954

References arg, BooleanTest::arg, BooleanTest::booltesttype, RestrictInfo::clause, get_notclausearg(), if(), IndexClause::indexcol, IndexClause::indexcols, IndexClause::indexquals, InvalidOid, IS_FALSE, is_notclause(), IS_TRUE, IsA, list_make1, IndexClause::lossy, make_opclause(), make_simple_restrictinfo, makeBoolConst(), makeNode, match_index_to_operand(), NIL, IndexClause::rinfo, and root.

Referenced by indexcol_is_bool_constant_for_query(), and match_clause_to_indexcol().

◆ match_clause_to_index()

static void match_clause_to_index ( PlannerInfo root,
RestrictInfo rinfo,
IndexOptInfo index,
IndexClauseSet clauseset 
)
static

Definition at line 2084 of file indxpath.c.

2088 {
2089  int indexcol;
2090 
2091  /*
2092  * Never match pseudoconstants to indexes. (Normally a match could not
2093  * happen anyway, since a pseudoconstant clause couldn't contain a Var,
2094  * but what if someone builds an expression index on a constant? It's not
2095  * totally unreasonable to do so with a partial index, either.)
2096  */
2097  if (rinfo->pseudoconstant)
2098  return;
2099 
2100  /*
2101  * If clause can't be used as an indexqual because it must wait till after
2102  * some lower-security-level restriction clause, reject it.
2103  */
2104  if (!restriction_is_securely_promotable(rinfo, index->rel))
2105  return;
2106 
2107  /* OK, check each index key column for a match */
2108  for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
2109  {
2110  IndexClause *iclause;
2111  ListCell *lc;
2112 
2113  /* Ignore duplicates */
2114  foreach(lc, clauseset->indexclauses[indexcol])
2115  {
2116  iclause = (IndexClause *) lfirst(lc);
2117 
2118  if (iclause->rinfo == rinfo)
2119  return;
2120  }
2121 
2122  /* OK, try to match the clause to the index column */
2123  iclause = match_clause_to_indexcol(root,
2124  rinfo,
2125  indexcol,
2126  index);
2127  if (iclause)
2128  {
2129  /* Success, so record it */
2130  clauseset->indexclauses[indexcol] =
2131  lappend(clauseset->indexclauses[indexcol], iclause);
2132  clauseset->nonempty = true;
2133  return;
2134  }
2135  }
2136 }
static IndexClause * match_clause_to_indexcol(PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:2203
bool restriction_is_securely_promotable(RestrictInfo *restrictinfo, RelOptInfo *rel)
Definition: restrictinfo.c:431

References IndexClauseSet::indexclauses, lappend(), lfirst, match_clause_to_indexcol(), IndexClauseSet::nonempty, restriction_is_securely_promotable(), IndexClause::rinfo, and root.

Referenced by match_clauses_to_index(), and match_join_clauses_to_index().

◆ match_clause_to_indexcol()

static IndexClause * match_clause_to_indexcol ( PlannerInfo root,
RestrictInfo rinfo,
int  indexcol,
IndexOptInfo index 
)
static

Definition at line 2203 of file indxpath.c.

2207 {
2208  IndexClause *iclause;
2209  Expr *clause = rinfo->clause;
2210  Oid opfamily;
2211 
2212  Assert(indexcol < index->nkeycolumns);
2213 
2214  /*
2215  * Historically this code has coped with NULL clauses. That's probably
2216  * not possible anymore, but we might as well continue to cope.
2217  */
2218  if (clause == NULL)
2219  return NULL;
2220 
2221  /* First check for boolean-index cases. */
2222  opfamily = index->opfamily[indexcol];
2223  if (IsBooleanOpfamily(opfamily))
2224  {
2225  iclause = match_boolean_index_clause(root, rinfo, indexcol, index);
2226  if (iclause)
2227  return iclause;
2228  }
2229 
2230  /*
2231  * Clause must be an opclause, funcclause, ScalarArrayOpExpr, or
2232  * RowCompareExpr. Or, if the index supports it, we can handle IS
2233  * NULL/NOT NULL clauses.
2234  */
2235  if (IsA(clause, OpExpr))
2236  {
2237  return match_opclause_to_indexcol(root, rinfo, indexcol, index);
2238  }
2239  else if (IsA(clause, FuncExpr))
2240  {
2241  return match_funcclause_to_indexcol(root, rinfo, indexcol, index);
2242  }
2243  else if (IsA(clause, ScalarArrayOpExpr))
2244  {
2245  return match_saopclause_to_indexcol(root, rinfo, indexcol, index);
2246  }
2247  else if (IsA(clause, RowCompareExpr))
2248  {
2249  return match_rowcompare_to_indexcol(root, rinfo, indexcol, index);
2250  }
2251  else if (index->amsearchnulls && IsA(clause, NullTest))
2252  {
2253  NullTest *nt = (NullTest *) clause;
2254 
2255  if (!nt->argisrow &&
2256  match_index_to_operand((Node *) nt->arg, indexcol, index))
2257  {
2258  iclause = makeNode(IndexClause);
2259  iclause->rinfo = rinfo;
2260  iclause->indexquals = list_make1(rinfo);
2261  iclause->lossy = false;
2262  iclause->indexcol = indexcol;
2263  iclause->indexcols = NIL;
2264  return iclause;
2265  }
2266  }
2267 
2268  return NULL;
2269 }
static IndexClause * match_saopclause_to_indexcol(PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:2623
static IndexClause * match_opclause_to_indexcol(PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:2392
static IndexClause * match_rowcompare_to_indexcol(PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:2691
static IndexClause * match_funcclause_to_indexcol(PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:2511
Expr * arg
Definition: primnodes.h:1930

References NullTest::arg, Assert, RestrictInfo::clause, IndexClause::indexcol, IndexClause::indexcols, IndexClause::indexquals, IsA, IsBooleanOpfamily(), list_make1, IndexClause::lossy, makeNode, match_boolean_index_clause(), match_funcclause_to_indexcol(), match_index_to_operand(), match_opclause_to_indexcol(), match_rowcompare_to_indexcol(), match_saopclause_to_indexcol(), NIL, IndexClause::rinfo, and root.

Referenced by match_clause_to_index().

◆ match_clause_to_ordering_op()

static Expr * match_clause_to_ordering_op ( IndexOptInfo index,
int  indexcol,
Expr clause,
Oid  pk_opfamily 
)
static

Definition at line 3130 of file indxpath.c.

3134 {
3135  Oid opfamily;
3136  Oid idxcollation;
3137  Node *leftop,
3138  *rightop;
3139  Oid expr_op;
3140  Oid expr_coll;
3141  Oid sortfamily;
3142  bool commuted;
3143 
3144  Assert(indexcol < index->nkeycolumns);
3145 
3146  opfamily = index->opfamily[indexcol];
3147  idxcollation = index->indexcollations[indexcol];
3148 
3149  /*
3150  * Clause must be a binary opclause.
3151  */
3152  if (!is_opclause(clause))
3153  return NULL;
3154  leftop = get_leftop(clause);
3155  rightop = get_rightop(clause);
3156  if (!leftop || !rightop)
3157  return NULL;
3158  expr_op = ((OpExpr *) clause)->opno;
3159  expr_coll = ((OpExpr *) clause)->inputcollid;
3160 
3161  /*
3162  * We can forget the whole thing right away if wrong collation.
3163  */
3164  if (!IndexCollMatchesExprColl(idxcollation, expr_coll))
3165  return NULL;
3166 
3167  /*
3168  * Check for clauses of the form: (indexkey operator constant) or
3169  * (constant operator indexkey).
3170  */
3171  if (match_index_to_operand(leftop, indexcol, index) &&
3172  !contain_var_clause(rightop) &&
3173  !contain_volatile_functions(rightop))
3174  {
3175  commuted = false;
3176  }
3177  else if (match_index_to_operand(rightop, indexcol, index) &&
3178  !contain_var_clause(leftop) &&
3179  !contain_volatile_functions(leftop))
3180  {
3181  /* Might match, but we need a commuted operator */
3182  expr_op = get_commutator(expr_op);
3183  if (expr_op == InvalidOid)
3184  return NULL;
3185  commuted = true;
3186  }
3187  else
3188  return NULL;
3189 
3190  /*
3191  * Is the (commuted) operator an ordering operator for the opfamily? And
3192  * if so, does it yield the right sorting semantics?
3193  */
3194  sortfamily = get_op_opfamily_sortfamily(expr_op, opfamily);
3195  if (sortfamily != pk_opfamily)
3196  return NULL;
3197 
3198  /* We have a match. Return clause or a commuted version thereof. */
3199  if (commuted)
3200  {
3201  OpExpr *newclause = makeNode(OpExpr);
3202 
3203  /* flat-copy all the fields of clause */
3204  memcpy(newclause, clause, sizeof(OpExpr));
3205 
3206  /* commute it */
3207  newclause->opno = expr_op;
3208  newclause->opfuncid = InvalidOid;
3209  newclause->args = list_make2(rightop, leftop);
3210 
3211  clause = (Expr *) newclause;
3212  }
3213 
3214  return clause;
3215 }
Oid get_op_opfamily_sortfamily(Oid opno, Oid opfamily)
Definition: lsyscache.c:108
static bool is_opclause(const void *clause)
Definition: nodeFuncs.h:74
static Node * get_rightop(const void *clause)
Definition: nodeFuncs.h:93
static Node * get_leftop(const void *clause)
Definition: nodeFuncs.h:81
#define list_make2(x1, x2)
Definition: pg_list.h:214
Oid opno
Definition: primnodes.h:788
List * args
Definition: primnodes.h:806
bool contain_var_clause(Node *node)
Definition: var.c:403

References OpExpr::args, Assert, contain_var_clause(), contain_volatile_functions(), get_commutator(), get_leftop(), get_op_opfamily_sortfamily(), get_rightop(), IndexCollMatchesExprColl, InvalidOid, is_opclause(), list_make2, makeNode, match_index_to_operand(), and OpExpr::opno.

Referenced by match_pathkeys_to_index().

◆ match_clauses_to_index()

static void match_clauses_to_index ( PlannerInfo root,
List clauses,
IndexOptInfo index,
IndexClauseSet clauseset 
)
static

Definition at line 2051 of file indxpath.c.

2055 {
2056  ListCell *lc;
2057 
2058  foreach(lc, clauses)
2059  {
2060  RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc);
2061 
2062  match_clause_to_index(root, rinfo, index, clauseset);
2063  }
2064 }
static void match_clause_to_index(PlannerInfo *root, RestrictInfo *rinfo, IndexOptInfo *index, IndexClauseSet *clauseset)
Definition: indxpath.c:2084

References lfirst_node, match_clause_to_index(), and root.

Referenced by build_paths_for_OR(), match_eclass_clauses_to_index(), and match_restriction_clauses_to_index().

◆ match_eclass_clauses_to_index()

static void match_eclass_clauses_to_index ( PlannerInfo root,
IndexOptInfo index,
IndexClauseSet clauseset 
)
static

Definition at line 2013 of file indxpath.c.

2015 {
2016  int indexcol;
2017 
2018  /* No work if rel is not in any such ECs */
2019  if (!index->rel->has_eclass_joins)
2020  return;
2021 
2022  for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
2023  {
2025  List *clauses;
2026 
2027  /* Generate clauses, skipping any that join to lateral_referencers */
2028  arg.index = index;
2029  arg.indexcol = indexcol;
2031  index->rel,
2033  (void *) &arg,
2034  index->rel->lateral_referencers);
2035 
2036  /*
2037  * We have to check whether the results actually do match the index,
2038  * since for non-btree indexes the EC's equality operators might not
2039  * be in the index opclass (cf ec_member_matches_indexcol).
2040  */
2041  match_clauses_to_index(root, clauses, index, clauseset);
2042  }
2043 }
List * generate_implied_equalities_for_column(PlannerInfo *root, RelOptInfo *rel, ec_matches_callback_type callback, void *callback_arg, Relids prohibited_rels)
Definition: equivclass.c:2971
static bool ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel, EquivalenceClass *ec, EquivalenceMember *em, void *arg)
Definition: indxpath.c:3382

References arg, ec_member_matches_indexcol(), generate_implied_equalities_for_column(), match_clauses_to_index(), and root.

Referenced by create_index_paths().

◆ match_funcclause_to_indexcol()

static IndexClause * match_funcclause_to_indexcol ( PlannerInfo root,
RestrictInfo rinfo,
int  indexcol,
IndexOptInfo index 
)
static

Definition at line 2511 of file indxpath.c.

2515 {
2516  FuncExpr *clause = (FuncExpr *) rinfo->clause;
2517  int indexarg;
2518  ListCell *lc;
2519 
2520  /*
2521  * We have no built-in intelligence about function clauses, but if there's
2522  * a planner support function, it might be able to do something. But, to
2523  * cut down on wasted planning cycles, only call the support function if
2524  * at least one argument matches the target index column.
2525  *
2526  * Note that we don't insist on the other arguments being pseudoconstants;
2527  * the support function has to check that. This is to allow cases where
2528  * only some of the other arguments need to be included in the indexqual.
2529  */
2530  indexarg = 0;
2531  foreach(lc, clause->args)
2532  {
2533  Node *op = (Node *) lfirst(lc);
2534 
2535  if (match_index_to_operand(op, indexcol, index))
2536  {
2538  rinfo,
2539  clause->funcid,
2540  indexarg,
2541  indexcol,
2542  index);
2543  }
2544 
2545  indexarg++;
2546  }
2547 
2548  return NULL;
2549 }
static IndexClause * get_index_clause_from_support(PlannerInfo *root, RestrictInfo *rinfo, Oid funcid, int indexarg, int indexcol, IndexOptInfo *index)
Definition: indxpath.c:2557
Oid funcid
Definition: primnodes.h:720
List * args
Definition: primnodes.h:738

References FuncExpr::args, RestrictInfo::clause, FuncExpr::funcid, get_index_clause_from_support(), lfirst, match_index_to_operand(), and root.

Referenced by match_clause_to_indexcol().

◆ match_index_to_operand()

bool match_index_to_operand ( Node operand,
int  indexcol,
IndexOptInfo index 
)

Definition at line 3704 of file indxpath.c.

3707 {
3708  int indkey;
3709 
3710  /*
3711  * Ignore any RelabelType node above the operand. This is needed to be
3712  * able to apply indexscanning in binary-compatible-operator cases. Note:
3713  * we can assume there is at most one RelabelType node;
3714  * eval_const_expressions() will have simplified if more than one.
3715  */
3716  if (operand && IsA(operand, RelabelType))
3717  operand = (Node *) ((RelabelType *) operand)->arg;
3718 
3719  indkey = index->indexkeys[indexcol];
3720  if (indkey != 0)
3721  {
3722  /*
3723  * Simple index column; operand must be a matching Var.
3724  */
3725  if (operand && IsA(operand, Var) &&
3726  index->rel->relid == ((Var *) operand)->varno &&
3727  indkey == ((Var *) operand)->varattno &&
3728  ((Var *) operand)->varnullingrels == NULL)
3729  return true;
3730  }
3731  else
3732  {
3733  /*
3734  * Index expression; find the correct expression. (This search could
3735  * be avoided, at the cost of complicating all the callers of this
3736  * routine; doesn't seem worth it.)
3737  */
3738  ListCell *indexpr_item;
3739  int i;
3740  Node *indexkey;
3741 
3742  indexpr_item = list_head(index->indexprs);
3743  for (i = 0; i < indexcol; i++)
3744  {
3745  if (index->indexkeys[i] == 0)
3746  {
3747  if (indexpr_item == NULL)
3748  elog(ERROR, "wrong number of index expressions");
3749  indexpr_item = lnext(index->indexprs, indexpr_item);
3750  }
3751  }
3752  if (indexpr_item == NULL)
3753  elog(ERROR, "wrong number of index expressions");
3754  indexkey = (Node *) lfirst(indexpr_item);
3755 
3756  /*
3757  * Does it match the operand? Again, strip any relabeling.
3758  */
3759  if (indexkey && IsA(indexkey, RelabelType))
3760  indexkey = (Node *) ((RelabelType *) indexkey)->arg;
3761 
3762  if (equal(indexkey, operand))
3763  return true;
3764  }
3765 
3766  return false;
3767 }
static ListCell * list_head(const List *l)
Definition: pg_list.h:128
static ListCell * lnext(const List *l, const ListCell *c)
Definition: pg_list.h:343
Definition: primnodes.h:248

References arg, elog, equal(), ERROR, i, IsA, lfirst, list_head(), and lnext().

Referenced by ec_member_matches_indexcol(), expand_indexqual_rowcompare(), get_actual_variable_range(), match_boolean_index_clause(), match_clause_to_indexcol(), match_clause_to_ordering_op(), match_funcclause_to_indexcol(), match_opclause_to_indexcol(), match_rowcompare_to_indexcol(), match_saopclause_to_indexcol(), and relation_has_unique_index_ext().

◆ match_join_clauses_to_index()

static void match_join_clauses_to_index ( PlannerInfo root,
RelOptInfo rel,
IndexOptInfo index,
IndexClauseSet clauseset,
List **  joinorclauses 
)
static

Definition at line 1983 of file indxpath.c.

1987 {
1988  ListCell *lc;
1989 
1990  /* Scan the rel's join clauses */
1991  foreach(lc, rel->joininfo)
1992  {
1993  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1994 
1995  /* Check if clause can be moved to this rel */
1996  if (!join_clause_is_movable_to(rinfo, rel))
1997  continue;
1998 
1999  /* Potentially usable, so see if it matches the index or is an OR */
2000  if (restriction_is_or_clause(rinfo))
2001  *joinorclauses = lappend(*joinorclauses, rinfo);
2002  else
2003  match_clause_to_index(root, rinfo, index, clauseset);
2004  }
2005 }

References join_clause_is_movable_to(), RelOptInfo::joininfo, lappend(), lfirst, match_clause_to_index(), restriction_is_or_clause(), and root.

Referenced by create_index_paths().

◆ match_opclause_to_indexcol()

static IndexClause * match_opclause_to_indexcol ( PlannerInfo root,
RestrictInfo rinfo,
int  indexcol,
IndexOptInfo index 
)
static

Definition at line 2392 of file indxpath.c.

2396 {
2397  IndexClause *iclause;
2398  OpExpr *clause = (OpExpr *) rinfo->clause;
2399  Node *leftop,
2400  *rightop;
2401  Oid expr_op;
2402  Oid expr_coll;
2403  Index index_relid;
2404  Oid opfamily;
2405  Oid idxcollation;
2406 
2407  /*
2408  * Only binary operators need apply. (In theory, a planner support
2409  * function could do something with a unary operator, but it seems
2410  * unlikely to be worth the cycles to check.)
2411  */
2412  if (list_length(clause->args) != 2)
2413  return NULL;
2414 
2415  leftop = (Node *) linitial(clause->args);
2416  rightop = (Node *) lsecond(clause->args);
2417  expr_op = clause->opno;
2418  expr_coll = clause->inputcollid;
2419 
2420  index_relid = index->rel->relid;
2421  opfamily = index->opfamily[indexcol];
2422  idxcollation = index->indexcollations[indexcol];
2423 
2424  /*
2425  * Check for clauses of the form: (indexkey operator constant) or
2426  * (constant operator indexkey). See match_clause_to_indexcol's notes
2427  * about const-ness.
2428  *
2429  * Note that we don't ask the support function about clauses that don't
2430  * have one of these forms. Again, in principle it might be possible to
2431  * do something, but it seems unlikely to be worth the cycles to check.
2432  */
2433  if (match_index_to_operand(leftop, indexcol, index) &&
2434  !bms_is_member(index_relid, rinfo->right_relids) &&
2435  !contain_volatile_functions(rightop))
2436  {
2437  if (IndexCollMatchesExprColl(idxcollation, expr_coll) &&
2438  op_in_opfamily(expr_op, opfamily))
2439  {
2440  iclause = makeNode(IndexClause);
2441  iclause->rinfo = rinfo;
2442  iclause->indexquals = list_make1(rinfo);
2443  iclause->lossy = false;
2444  iclause->indexcol = indexcol;
2445  iclause->indexcols = NIL;
2446  return iclause;
2447  }
2448 
2449  /*
2450  * If we didn't find a member of the index's opfamily, try the support
2451  * function for the operator's underlying function.
2452  */
2453  set_opfuncid(clause); /* make sure we have opfuncid */
2455  rinfo,
2456  clause->opfuncid,
2457  0, /* indexarg on left */
2458  indexcol,
2459  index);
2460  }
2461 
2462  if (match_index_to_operand(rightop, indexcol, index) &&
2463  !bms_is_member(index_relid, rinfo->left_relids) &&
2464  !contain_volatile_functions(leftop))
2465  {
2466  if (IndexCollMatchesExprColl(idxcollation, expr_coll))
2467  {
2468  Oid comm_op = get_commutator(expr_op);
2469 
2470  if (OidIsValid(comm_op) &&
2471  op_in_opfamily(comm_op, opfamily))
2472  {
2473  RestrictInfo *commrinfo;
2474 
2475  /* Build a commuted OpExpr and RestrictInfo */
2476  commrinfo = commute_restrictinfo(rinfo, comm_op);
2477 
2478  /* Make an IndexClause showing that as a derived qual */
2479  iclause = makeNode(IndexClause);
2480  iclause->rinfo = rinfo;
2481  iclause->indexquals = list_make1(commrinfo);
2482  iclause->lossy = false;
2483  iclause->indexcol = indexcol;
2484  iclause->indexcols = NIL;
2485  return iclause;
2486  }
2487  }
2488 
2489  /*
2490  * If we didn't find a member of the index's opfamily, try the support
2491  * function for the operator's underlying function.
2492  */
2493  set_opfuncid(clause); /* make sure we have opfuncid */
2495  rinfo,
2496  clause->opfuncid,
2497  1, /* indexarg on right */
2498  indexcol,
2499  index);
2500  }
2501 
2502  return NULL;
2503 }
unsigned int Index
Definition: c.h:614
void set_opfuncid(OpExpr *opexpr)
Definition: nodeFuncs.c:1868
#define lsecond(l)
Definition: pg_list.h:183
RestrictInfo * commute_restrictinfo(RestrictInfo *rinfo, Oid comm_op)
Definition: restrictinfo.c:359

References OpExpr::args, bms_is_member(), RestrictInfo::clause, commute_restrictinfo(), contain_volatile_functions(), get_commutator(), get_index_clause_from_support(), if(), IndexClause::indexcol, IndexCollMatchesExprColl, IndexClause::indexcols, IndexClause::indexquals, linitial, list_length(), list_make1, IndexClause::lossy, lsecond, makeNode, match_index_to_operand(), NIL, OidIsValid, op_in_opfamily(), OpExpr::opno, IndexClause::rinfo, root, and set_opfuncid().

Referenced by match_clause_to_indexcol().

◆ match_pathkeys_to_index()

static void match_pathkeys_to_index ( IndexOptInfo index,
List pathkeys,
List **  orderby_clauses_p,
List **  clause_columns_p 
)
static

Definition at line 3020 of file indxpath.c.

3023 {
3024  ListCell *lc1;
3025 
3026  *orderby_clauses_p = NIL; /* set default results */
3027  *clause_columns_p = NIL;
3028 
3029  /* Only indexes with the amcanorderbyop property are interesting here */
3030  if (!index->amcanorderbyop)
3031  return;
3032 
3033  foreach(lc1, pathkeys)
3034  {
3035  PathKey *pathkey = (PathKey *) lfirst(lc1);
3036  bool found = false;
3037  ListCell *lc2;
3038 
3039 
3040  /* Pathkey must request default sort order for the target opfamily */
3041  if (pathkey->pk_strategy != BTLessStrategyNumber ||
3042  pathkey->pk_nulls_first)
3043  return;
3044 
3045  /* If eclass is volatile, no hope of using an indexscan */
3046  if (pathkey->pk_eclass->ec_has_volatile)
3047  return;
3048 
3049  /*
3050  * Try to match eclass member expression(s) to index. Note that child
3051  * EC members are considered, but only when they belong to the target
3052  * relation. (Unlike regular members, the same expression could be a
3053  * child member of more than one EC. Therefore, the same index could
3054  * be considered to match more than one pathkey list, which is OK
3055  * here. See also get_eclass_for_sort_expr.)
3056  */
3057  foreach(lc2, pathkey->pk_eclass->ec_members)
3058  {
3059  EquivalenceMember *member = (EquivalenceMember *) lfirst(lc2);
3060  int indexcol;
3061 
3062  /* No possibility of match if it references other relations */
3063  if (!bms_equal(member->em_relids, index->rel->relids))
3064  continue;
3065 
3066  /*
3067  * We allow any column of the index to match each pathkey; they
3068  * don't have to match left-to-right as you might expect. This is
3069  * correct for GiST, and it doesn't matter for SP-GiST because
3070  * that doesn't handle multiple columns anyway, and no other
3071  * existing AMs support amcanorderbyop. We might need different
3072  * logic in future for other implementations.
3073  */
3074  for (indexcol = 0; indexcol < index->nkeycolumns; indexcol++)
3075  {
3076  Expr *expr;
3077 
3079  indexcol,
3080  member->em_expr,
3081  pathkey->pk_opfamily);
3082  if (expr)
3083  {
3084  *orderby_clauses_p = lappend(*orderby_clauses_p, expr);
3085  *clause_columns_p = lappend_int(*clause_columns_p, indexcol);
3086  found = true;
3087  break;
3088  }
3089  }
3090 
3091  if (found) /* don't want to look at remaining members */
3092  break;
3093  }
3094 
3095  /*
3096  * Return the matches found so far when this pathkey couldn't be
3097  * matched to the index.
3098  */
3099  if (!found)
3100  return;
3101  }
3102 }
static Expr * match_clause_to_ordering_op(IndexOptInfo *index, int indexcol, Expr *clause, Oid pk_opfamily)
Definition: indxpath.c:3130
bool pk_nulls_first
Definition: pathnodes.h:1467
int pk_strategy
Definition: pathnodes.h:1466
Oid pk_opfamily
Definition: pathnodes.h:1465

References bms_equal(), BTLessStrategyNumber, EquivalenceMember::em_expr, EquivalenceMember::em_relids, lappend(), lappend_int(), lfirst, match_clause_to_ordering_op(), NIL, PathKey::pk_nulls_first, PathKey::pk_opfamily, and PathKey::pk_strategy.

Referenced by build_index_paths().

◆ match_restriction_clauses_to_index()

static void match_restriction_clauses_to_index ( PlannerInfo root,
IndexOptInfo index,
IndexClauseSet clauseset 
)
static

Definition at line 1968 of file indxpath.c.

1971 {
1972  /* We can ignore clauses that are implied by the index predicate */
1973  match_clauses_to_index(root, index->indrestrictinfo, index, clauseset);
1974 }

References match_clauses_to_index(), and root.

Referenced by create_index_paths().

◆ match_rowcompare_to_indexcol()

static IndexClause * match_rowcompare_to_indexcol ( PlannerInfo root,
RestrictInfo rinfo,
int  indexcol,
IndexOptInfo index 
)
static

Definition at line 2691 of file indxpath.c.

2695 {
2696  RowCompareExpr *clause = (RowCompareExpr *) rinfo->clause;
2697  Index index_relid;
2698  Oid opfamily;
2699  Oid idxcollation;
2700  Node *leftop,
2701  *rightop;
2702  bool var_on_left;
2703  Oid expr_op;
2704  Oid expr_coll;
2705 
2706  /* Forget it if we're not dealing with a btree index */
2707  if (index->relam != BTREE_AM_OID)
2708  return NULL;
2709 
2710  index_relid = index->rel->relid;
2711  opfamily = index->opfamily[indexcol];
2712  idxcollation = index->indexcollations[indexcol];
2713 
2714  /*
2715  * We could do the matching on the basis of insisting that the opfamily
2716  * shown in the RowCompareExpr be the same as the index column's opfamily,
2717  * but that could fail in the presence of reverse-sort opfamilies: it'd be
2718  * a matter of chance whether RowCompareExpr had picked the forward or
2719  * reverse-sort family. So look only at the operator, and match if it is
2720  * a member of the index's opfamily (after commutation, if the indexkey is
2721  * on the right). We'll worry later about whether any additional
2722  * operators are matchable to the index.
2723  */
2724  leftop = (Node *) linitial(clause->largs);
2725  rightop = (Node *) linitial(clause->rargs);
2726  expr_op = linitial_oid(clause->opnos);
2727  expr_coll = linitial_oid(clause->inputcollids);
2728 
2729  /* Collations must match, if relevant */
2730  if (!IndexCollMatchesExprColl(idxcollation, expr_coll))
2731  return NULL;
2732 
2733  /*
2734  * These syntactic tests are the same as in match_opclause_to_indexcol()
2735  */
2736  if (match_index_to_operand(leftop, indexcol, index) &&
2737  !bms_is_member(index_relid, pull_varnos(root, rightop)) &&
2738  !contain_volatile_functions(rightop))
2739  {
2740  /* OK, indexkey is on left */
2741  var_on_left = true;
2742  }
2743  else if (match_index_to_operand(rightop, indexcol, index) &&
2744  !bms_is_member(index_relid, pull_varnos(root, leftop)) &&
2745  !contain_volatile_functions(leftop))
2746  {
2747  /* indexkey is on right, so commute the operator */
2748  expr_op = get_commutator(expr_op);
2749  if (expr_op == InvalidOid)
2750  return NULL;
2751  var_on_left = false;
2752  }
2753  else
2754  return NULL;
2755 
2756  /* We're good if the operator is the right type of opfamily member */
2757  switch (get_op_opfamily_strategy(expr_op, opfamily))
2758  {
2759  case BTLessStrategyNumber:
2764  rinfo,
2765  indexcol,
2766  index,
2767  expr_op,
2768  var_on_left);
2769  }
2770 
2771  return NULL;
2772 }
static IndexClause * expand_indexqual_rowcompare(PlannerInfo *root, RestrictInfo *rinfo, int indexcol, IndexOptInfo *index, Oid expr_op, bool var_on_left)
Definition: indxpath.c:2798

References bms_is_member(), BTGreaterEqualStrategyNumber, BTGreaterStrategyNumber, BTLessEqualStrategyNumber, BTLessStrategyNumber, RestrictInfo::clause, contain_volatile_functions(), expand_indexqual_rowcompare(), get_commutator(), get_op_opfamily_strategy(), if(), IndexCollMatchesExprColl, InvalidOid, RowCompareExpr::largs, linitial, linitial_oid, match_index_to_operand(), pull_varnos(), RowCompareExpr::rargs, and root.

Referenced by match_clause_to_indexcol().

◆ match_saopclause_to_indexcol()

static IndexClause * match_saopclause_to_indexcol ( PlannerInfo root,
RestrictInfo rinfo,
int  indexcol,
IndexOptInfo index 
)
static

Definition at line 2623 of file indxpath.c.

2627 {
2628  ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) rinfo->clause;
2629  Node *leftop,
2630  *rightop;
2631  Relids right_relids;
2632  Oid expr_op;
2633  Oid expr_coll;
2634  Index index_relid;
2635  Oid opfamily;
2636  Oid idxcollation;
2637 
2638  /* We only accept ANY clauses, not ALL */
2639  if (!saop->useOr)
2640  return NULL;
2641  leftop = (Node *) linitial(saop->args);
2642  rightop = (Node *) lsecond(saop->args);
2643  right_relids = pull_varnos(root, rightop);
2644  expr_op = saop->opno;
2645  expr_coll = saop->inputcollid;
2646 
2647  index_relid = index->rel->relid;
2648  opfamily = index->opfamily[indexcol];
2649  idxcollation = index->indexcollations[indexcol];
2650 
2651  /*
2652  * We must have indexkey on the left and a pseudo-constant array argument.
2653  */
2654  if (match_index_to_operand(leftop, indexcol, index) &&
2655  !bms_is_member(index_relid, right_relids) &&
2656  !contain_volatile_functions(rightop))
2657  {
2658  if (IndexCollMatchesExprColl(idxcollation, expr_coll) &&
2659  op_in_opfamily(expr_op, opfamily))
2660  {
2661  IndexClause *iclause = makeNode(IndexClause);
2662 
2663  iclause->rinfo = rinfo;
2664  iclause->indexquals = list_make1(rinfo);
2665  iclause->lossy = false;
2666  iclause->indexcol = indexcol;
2667  iclause->indexcols = NIL;
2668  return iclause;
2669  }
2670 
2671  /*
2672  * We do not currently ask support functions about ScalarArrayOpExprs,
2673  * though in principle we could.
2674  */
2675  }
2676 
2677  return NULL;
2678 }

References ScalarArrayOpExpr::args, bms_is_member(), RestrictInfo::clause, contain_volatile_functions(), if(), IndexClause::indexcol, IndexCollMatchesExprColl, IndexClause::indexcols, IndexClause::indexquals, linitial, list_make1, IndexClause::lossy, lsecond, makeNode, match_index_to_operand(), NIL, op_in_opfamily(), ScalarArrayOpExpr::opno, pull_varnos(), IndexClause::rinfo, root, and ScalarArrayOpExpr::useOr.

Referenced by match_clause_to_indexcol().

◆ path_usage_comparator()

static int path_usage_comparator ( const void *  a,
const void *  b 
)
static

Definition at line 1493 of file indxpath.c.

1494 {
1495  PathClauseUsage *pa = *(PathClauseUsage *const *) a;
1496  PathClauseUsage *pb = *(PathClauseUsage *const *) b;
1497  Cost acost;
1498  Cost bcost;
1499  Selectivity aselec;
1500  Selectivity bselec;
1501 
1502  cost_bitmap_tree_node(pa->path, &acost, &aselec);
1503  cost_bitmap_tree_node(pb->path, &bcost, &bselec);
1504 
1505  /*
1506  * If costs are the same, sort by selectivity.
1507  */
1508  if (acost < bcost)
1509  return -1;
1510  if (acost > bcost)
1511  return 1;
1512 
1513  if (aselec < bselec)
1514  return -1;
1515  if (aselec > bselec)
1516  return 1;
1517 
1518  return 0;
1519 }
int b
Definition: isn.c:70
int a
Definition: isn.c:69

References a, b, cost_bitmap_tree_node(), and PathClauseUsage::path.

Referenced by choose_bitmap_and().

◆ relation_has_unique_index_ext()

bool relation_has_unique_index_ext ( PlannerInfo root,
RelOptInfo rel,
List restrictlist,
List exprlist,
List oprlist,
List **  extra_clauses 
)

Definition at line 3455 of file indxpath.c.

3459 {
3460  ListCell *ic;
3461 
3462  Assert(list_length(exprlist) == list_length(oprlist));
3463 
3464  /* Short-circuit if no indexes... */
3465  if (rel->indexlist == NIL)
3466  return false;
3467 
3468  /*
3469  * Examine the rel's restriction clauses for usable var = const clauses
3470  * that we can add to the restrictlist.
3471  */
3472  foreach(ic, rel->baserestrictinfo)
3473  {
3474  RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(ic);
3475 
3476  /*
3477  * Note: can_join won't be set for a restriction clause, but
3478  * mergeopfamilies will be if it has a mergejoinable operator and
3479  * doesn't contain volatile functions.
3480  */
3481  if (restrictinfo->mergeopfamilies == NIL)
3482  continue; /* not mergejoinable */
3483 
3484  /*
3485  * The clause certainly doesn't refer to anything but the given rel.
3486  * If either side is pseudoconstant then we can use it.
3487  */
3488  if (bms_is_empty(restrictinfo->left_relids))
3489  {
3490  /* righthand side is inner */
3491  restrictinfo->outer_is_left = true;
3492  }
3493  else if (bms_is_empty(restrictinfo->right_relids))
3494  {
3495  /* lefthand side is inner */
3496  restrictinfo->outer_is_left = false;
3497  }
3498  else
3499  continue;
3500 
3501  /* OK, add to list */
3502  restrictlist = lappend(restrictlist, restrictinfo);
3503  }
3504 
3505  /* Short-circuit the easy case */
3506  if (restrictlist == NIL && exprlist == NIL)
3507  return false;
3508 
3509  /* Examine each index of the relation ... */
3510  foreach(ic, rel->indexlist)
3511  {
3512  IndexOptInfo *ind = (IndexOptInfo *) lfirst(ic);
3513  int c;
3514  List *exprs = NIL;
3515 
3516  /*
3517  * If the index is not unique, or not immediately enforced, or if it's
3518  * a partial index, it's useless here. We're unable to make use of
3519  * predOK partial unique indexes due to the fact that
3520  * check_index_predicates() also makes use of join predicates to
3521  * determine if the partial index is usable. Here we need proofs that
3522  * hold true before any joins are evaluated.
3523  */
3524  if (!ind->unique || !ind->immediate || ind->indpred != NIL)
3525  continue;
3526 
3527  /*
3528  * Try to find each index column in the lists of conditions. This is
3529  * O(N^2) or worse, but we expect all the lists to be short.
3530  */
3531  for (c = 0; c < ind->nkeycolumns; c++)
3532  {
3533  bool matched = false;
3534  ListCell *lc;
3535  ListCell *lc2;
3536 
3537  foreach(lc, restrictlist)
3538  {
3539  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
3540  Node *rexpr;
3541 
3542  /*
3543  * The condition's equality operator must be a member of the
3544  * index opfamily, else it is not asserting the right kind of
3545  * equality behavior for this index. We check this first
3546  * since it's probably cheaper than match_index_to_operand().
3547  */
3548  if (!list_member_oid(rinfo->mergeopfamilies, ind->opfamily[c]))
3549  continue;
3550 
3551  /*
3552  * XXX at some point we may need to check collations here too.
3553  * For the moment we assume all collations reduce to the same
3554  * notion of equality.
3555  */
3556 
3557  /* OK, see if the condition operand matches the index key */
3558  if (rinfo->outer_is_left)
3559  rexpr = get_rightop(rinfo->clause);
3560  else
3561  rexpr = get_leftop(rinfo->clause);
3562 
3563  if (match_index_to_operand(rexpr, c, ind))
3564  {
3565  matched = true; /* column is unique */
3566 
3567  if (bms_membership(rinfo->clause_relids) == BMS_SINGLETON)
3568  {
3569  MemoryContext oldMemCtx =
3570  MemoryContextSwitchTo(root->planner_cxt);
3571 
3572  /*
3573  * Add filter clause into a list allowing caller to
3574  * know if uniqueness have made not only by join
3575  * clauses.
3576  */
3577  Assert(bms_is_empty(rinfo->left_relids) ||
3578  bms_is_empty(rinfo->right_relids));
3579  if (extra_clauses)
3580  exprs = lappend(exprs, rinfo);
3581  MemoryContextSwitchTo(oldMemCtx);
3582  }
3583 
3584  break;
3585  }
3586  }
3587 
3588  if (matched)
3589  continue;
3590 
3591  forboth(lc, exprlist, lc2, oprlist)
3592  {
3593  Node *expr = (Node *) lfirst(lc);
3594  Oid opr = lfirst_oid(lc2);
3595 
3596  /* See if the expression matches the index key */
3597  if (!match_index_to_operand(expr, c, ind))
3598  continue;
3599 
3600  /*
3601  * The equality operator must be a member of the index
3602  * opfamily, else it is not asserting the right kind of
3603  * equality behavior for this index. We assume the caller
3604  * determined it is an equality operator, so we don't need to
3605  * check any more tightly than this.
3606  */
3607  if (!op_in_opfamily(opr, ind->opfamily[c]))
3608  continue;
3609 
3610  /*
3611  * XXX at some point we may need to check collations here too.
3612  * For the moment we assume all collations reduce to the same
3613  * notion of equality.
3614  */
3615 
3616  matched = true; /* column is unique */
3617  break;
3618  }
3619 
3620  if (!matched)
3621  break; /* no match; this index doesn't help us */
3622  }
3623 
3624  /* Matched all key columns of this index? */
3625  if (c == ind->nkeycolumns)
3626  {
3627  if (extra_clauses)
3628  *extra_clauses = exprs;
3629  return true;
3630  }
3631  }
3632 
3633  return false;
3634 }
BMS_Membership bms_membership(const Bitmapset *a)
Definition: bitmapset.c:781
@ BMS_SINGLETON
Definition: bitmapset.h:72
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:518
char * c
MemoryContextSwitchTo(old_ctx)

References Assert, RelOptInfo::baserestrictinfo, bms_is_empty, bms_membership(), BMS_SINGLETON, RestrictInfo::clause, forboth, get_leftop(), get_rightop(), RelOptInfo::indexlist, lappend(), lfirst, lfirst_oid, list_length(), list_member_oid(), match_index_to_operand(), MemoryContextSwitchTo(), NIL, op_in_opfamily(), and root.

Referenced by rel_is_distinct_for(), and relation_has_unique_index_for().

◆ relation_has_unique_index_for()

bool relation_has_unique_index_for ( PlannerInfo root,
RelOptInfo rel,
List restrictlist,
List exprlist,
List oprlist 
)

Definition at line 3440 of file indxpath.c.

3443 {
3444  return relation_has_unique_index_ext(root, rel, restrictlist,
3445  exprlist, oprlist, NULL);
3446 }
bool relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist, List **extra_clauses)
Definition: indxpath.c:3455

References relation_has_unique_index_ext(), and root.

Referenced by create_unique_path().