* 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
| 849 | * truncate_useless_pathkeys() to possibly remove more pathkeys. |
| 850 | */ |
| 851 | List * |
| 852 | build_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 |
no test coverage detected