MCPcopy Create free account
hub / github.com/apache/cloudberry / build_index_paths

Function build_index_paths

src/backend/optimizer/path/indxpath.c:896–1174  ·  view source on GitHub ↗

* build_index_paths * Given an index and a set of index clauses for it, construct zero * or more IndexPaths. It also constructs zero or more partial IndexPaths. * * We return a list of paths because (1) this routine checks some cases * that should cause us to not generate any IndexPath, and (2) in some * cases we want to consider both a forward and a backward scan, so as * to obtain bot

Source from the content-addressed store, hash-verified

894 * 'skip_lower_saop' indicates whether to accept non-first-column SAOP
895 */
896static List *
897build_index_paths(PlannerInfo *root, RelOptInfo *rel,
898 IndexOptInfo *index, IndexClauseSet *clauses,
899 bool useful_predicate,
900 ScanTypeControl scantype,
901 bool *skip_nonnative_saop,
902 bool *skip_lower_saop)
903{
904 List *result = NIL;
905 IndexPath *ipath;
906 List *index_clauses;
907 Relids outer_relids;
908 double loop_count;
909 List *orderbyclauses;
910 List *orderbyclausecols;
911 List *index_pathkeys;
912 List *useful_pathkeys;
913 bool found_lower_saop_clause;
914 bool pathkeys_possibly_useful;
915 bool index_is_ordered;
916 bool index_only_scan;
917 int indexcol;
918
919 /*
920 * Check that index supports the desired scan type(s)
921 */
922 switch (scantype)
923 {
924 case ST_INDEXSCAN:
925 if (!index->amhasgettuple)
926 return NIL;
927 break;
928 case ST_BITMAPSCAN:
929 if (!index->amhasgetbitmap)
930 return NIL;
931 break;
932 case ST_ANYSCAN:
933 /* either or both are OK */
934 break;
935 }
936
937 /*
938 * 1. Combine the per-column IndexClause lists into an overall list.
939 *
940 * In the resulting list, clauses are ordered by index key, so that the
941 * column numbers form a nondecreasing sequence. (This order is depended
942 * on by btree and possibly other places.) The list can be empty, if the
943 * index AM allows that.
944 *
945 * found_lower_saop_clause is set true if we accept a ScalarArrayOpExpr
946 * index clause for a non-first index column. This prevents us from
947 * assuming that the scan result is ordered. (Actually, the result is
948 * still ordered if there are equality constraints for all earlier
949 * columns, but it seems too expensive and non-modular for this code to be
950 * aware of that refinement.)
951 *
952 * We also build a Relids set showing which outer rels are required by the
953 * selected clauses. Any lateral_relids are included in that, but not

Callers 2

get_index_pathsFunction · 0.85
build_paths_for_ORFunction · 0.85

Calls 15

bms_copyFunction · 0.85
lappendFunction · 0.85
bms_add_membersFunction · 0.85
bms_del_memberFunction · 0.85
bms_is_emptyFunction · 0.85
get_loop_countFunction · 0.85
has_useful_pathkeysFunction · 0.85
build_index_pathkeysFunction · 0.85
match_pathkeys_to_indexFunction · 0.85
check_index_onlyFunction · 0.85
create_index_pathFunction · 0.85

Tested by

no test coverage detected