|
11 | 11 | * Portions Copyright (c) 1994, Regents of the University of California
|
12 | 12 | *
|
13 | 13 | * IDENTIFICATION
|
14 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.74 2005/11/22 18:17:12 momjian Exp $ |
| 14 | + * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.75 2006/01/29 17:27:42 tgl Exp $ |
15 | 15 | *
|
16 | 16 | *-------------------------------------------------------------------------
|
17 | 17 | */
|
@@ -909,13 +909,20 @@ get_cheapest_fractional_path_for_pathkeys(List *paths,
|
909 | 909 | * If 'scandir' is BackwardScanDirection, attempt to build pathkeys
|
910 | 910 | * representing a backwards scan of the index. Return NIL if can't do it.
|
911 | 911 | *
|
| 912 | + * If 'canonical' is TRUE, we remove duplicate pathkeys (which can occur |
| 913 | + * if two index columns are equijoined, eg WHERE x = 1 AND y = 1). This |
| 914 | + * is required if the result is to be compared directly to a canonical query |
| 915 | + * pathkeys list. However, some callers want a list with exactly one entry |
| 916 | + * per index column, and they must pass FALSE. |
| 917 | + * |
912 | 918 | * We generate the full pathkeys list whether or not all are useful for the
|
913 | 919 | * current query. Caller should do truncate_useless_pathkeys().
|
914 | 920 | */
|
915 | 921 | List *
|
916 | 922 | build_index_pathkeys(PlannerInfo *root,
|
917 | 923 | IndexOptInfo *index,
|
918 |
| - ScanDirection scandir) |
| 924 | + ScanDirection scandir, |
| 925 | + bool canonical) |
919 | 926 | {
|
920 | 927 | List *retval = NIL;
|
921 | 928 | int *indexkeys = index->indexkeys;
|
@@ -956,11 +963,11 @@ build_index_pathkeys(PlannerInfo *root,
|
956 | 963 | item = makePathKeyItem(indexkey, sortop, true);
|
957 | 964 | cpathkey = make_canonical_pathkey(root, item);
|
958 | 965 |
|
959 |
| - /* |
960 |
| - * Eliminate redundant ordering info; could happen if query is such |
961 |
| - * that index keys are equijoined... |
962 |
| - */ |
963 |
| - retval = list_append_unique_ptr(retval, cpathkey); |
| 966 | + /* Eliminate redundant ordering info if requested */ |
| 967 | + if (canonical) |
| 968 | + retval = list_append_unique_ptr(retval, cpathkey); |
| 969 | + else |
| 970 | + retval = lappend(retval, cpathkey); |
964 | 971 |
|
965 | 972 | indexkeys++;
|
966 | 973 | ordering++;
|
|
0 commit comments