Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1b7e70

Browse files
committed
Fix code that checks to see if an index can be considered to match the query's
requested sort order. It was assuming that build_index_pathkeys alwaysgenerates a pathkey per index column, which was not true if implied equalitydeduction had determined that two index columns were effectively equated toeach other. Simplest fix seems to be to install an option that causesbuild_index_pathkeys to support this behavior as well as the original one.Per report from Brian Hirt.
1 parent4400ca2 commita1b7e70

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

‎src/backend/optimizer/path/indxpath.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.198 2006/01/26 02:35:49 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.199 2006/01/29 17:27:42 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -343,7 +343,8 @@ find_usable_indexes(PlannerInfo *root, RelOptInfo *rel,
343343
if (istoplevel&&index_is_ordered&& !isjoininner)
344344
{
345345
index_pathkeys=build_index_pathkeys(root,index,
346-
ForwardScanDirection);
346+
ForwardScanDirection,
347+
true);
347348
useful_pathkeys=truncate_useless_pathkeys(root,rel,
348349
index_pathkeys);
349350
}
@@ -1705,7 +1706,7 @@ match_index_to_query_keys(PlannerInfo *root,
17051706
ListCell*r;
17061707

17071708
/* Get the pathkeys that exactly describe the index */
1708-
index_pathkeys=build_index_pathkeys(root,index,indexscandir);
1709+
index_pathkeys=build_index_pathkeys(root,index,indexscandir, false);
17091710

17101711
/*
17111712
* Can we match to the query's requested pathkeys? The inner loop skips

‎src/backend/optimizer/path/pathkeys.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* 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/2917:27:42 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -909,13 +909,20 @@ get_cheapest_fractional_path_for_pathkeys(List *paths,
909909
* If 'scandir' is BackwardScanDirection, attempt to build pathkeys
910910
* representing a backwards scan of the index.Return NIL if can't do it.
911911
*
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+
*
912918
* We generate the full pathkeys list whether or not all are useful for the
913919
* current query. Caller should do truncate_useless_pathkeys().
914920
*/
915921
List*
916922
build_index_pathkeys(PlannerInfo*root,
917923
IndexOptInfo*index,
918-
ScanDirectionscandir)
924+
ScanDirectionscandir,
925+
boolcanonical)
919926
{
920927
List*retval=NIL;
921928
int*indexkeys=index->indexkeys;
@@ -956,11 +963,11 @@ build_index_pathkeys(PlannerInfo *root,
956963
item=makePathKeyItem(indexkey,sortop, true);
957964
cpathkey=make_canonical_pathkey(root,item);
958965

959-
/*
960-
* Eliminate redundant ordering info; could happenifquery 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);
964971

965972
indexkeys++;
966973
ordering++;

‎src/include/optimizer/paths.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.90 2005/12/20 02:30:36 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.91 2006/01/29 17:27:42 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -114,7 +114,7 @@ extern Path *get_cheapest_fractional_path_for_pathkeys(List *paths,
114114
List*pathkeys,
115115
doublefraction);
116116
externList*build_index_pathkeys(PlannerInfo*root,IndexOptInfo*index,
117-
ScanDirectionscandir);
117+
ScanDirectionscandir,boolcanonical);
118118
externList*convert_subquery_pathkeys(PlannerInfo*root,RelOptInfo*rel,
119119
List*subquery_pathkeys);
120120
externList*build_join_pathkeys(PlannerInfo*root,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp