aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/pathkeys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/path/pathkeys.c')
-rw-r--r--src/backend/optimizer/path/pathkeys.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index 4216768212c..dc7687916f6 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.74 2005/11/22 18:17:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.75 2006/01/29 17:27:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -909,13 +909,20 @@ get_cheapest_fractional_path_for_pathkeys(List *paths,
* If 'scandir' is BackwardScanDirection, attempt to build pathkeys
* representing a backwards scan of the index. Return NIL if can't do it.
*
+ * If 'canonical' is TRUE, we remove duplicate pathkeys (which can occur
+ * if two index columns are equijoined, eg WHERE x = 1 AND y = 1). This
+ * is required if the result is to be compared directly to a canonical query
+ * pathkeys list. However, some callers want a list with exactly one entry
+ * per index column, and they must pass FALSE.
+ *
* We generate the full pathkeys list whether or not all are useful for the
* current query. Caller should do truncate_useless_pathkeys().
*/
List *
build_index_pathkeys(PlannerInfo *root,
IndexOptInfo *index,
- ScanDirection scandir)
+ ScanDirection scandir,
+ bool canonical)
{
List *retval = NIL;
int *indexkeys = index->indexkeys;
@@ -956,11 +963,11 @@ build_index_pathkeys(PlannerInfo *root,
item = makePathKeyItem(indexkey, sortop, true);
cpathkey = make_canonical_pathkey(root, item);
- /*
- * Eliminate redundant ordering info; could happen if query is such
- * that index keys are equijoined...
- */
- retval = list_append_unique_ptr(retval, cpathkey);
+ /* Eliminate redundant ordering info if requested */
+ if (canonical)
+ retval = list_append_unique_ptr(retval, cpathkey);
+ else
+ retval = lappend(retval, cpathkey);
indexkeys++;
ordering++;