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

Function build_index_pathkeys

src/backend/optimizer/path/pathkeys.c:851–938  ·  view source on GitHub ↗

* build_index_pathkeys * Build a pathkeys list that describes the ordering induced by an index * scan using the given index. (Note that an unordered index doesn't * induce any ordering, so we return NIL.) * * If 'scandir' is BackwardScanDirection, build pathkeys representing a * backwards scan of the index. * * We iterate only key columns of covering indexes, since non-key columns

Source from the content-addressed store, hash-verified

849 * truncate_useless_pathkeys() to possibly remove more pathkeys.
850 */
851List *
852build_index_pathkeys(PlannerInfo *root,
853 IndexOptInfo *index,
854 ScanDirection scandir)
855{
856 List *retval = NIL;
857 ListCell *lc;
858 int i;
859
860 if (index->sortopfamily == NULL)
861 return NIL; /* non-orderable index */
862
863 i = 0;
864 foreach(lc, index->indextlist)
865 {
866 TargetEntry *indextle = (TargetEntry *) lfirst(lc);
867 Expr *indexkey;
868 bool reverse_sort;
869 bool nulls_first;
870 PathKey *cpathkey;
871
872 /*
873 * INCLUDE columns are stored in index unordered, so they don't
874 * support ordered index scan.
875 */
876 if (i >= index->nkeycolumns)
877 break;
878
879 /* We assume we don't need to make a copy of the tlist item */
880 indexkey = indextle->expr;
881
882 if (ScanDirectionIsBackward(scandir))
883 {
884 reverse_sort = !index->reverse_sort[i];
885 nulls_first = !index->nulls_first[i];
886 }
887 else
888 {
889 reverse_sort = index->reverse_sort[i];
890 nulls_first = index->nulls_first[i];
891 }
892
893 /*
894 * OK, try to make a canonical pathkey for this sort key. Note we're
895 * underneath any outer joins, so nullable_relids should be NULL.
896 */
897 cpathkey = make_pathkey_from_sortinfo(root,
898 indexkey,
899 NULL,
900 index->sortopfamily[i],
901 index->opcintype[i],
902 index->indexcollations[i],
903 reverse_sort,
904 nulls_first,
905 0,
906 index->rel->relids,
907 false);
908

Callers 1

build_index_pathsFunction · 0.85

Calls 5

pathkey_is_redundantFunction · 0.85
lappendFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected