Skip to content

Commit 6fbda16

Browse files
committed
Don't try to run clauseless index scans on index types that don't support
it. Per report from Marinos Yannikos.
1 parent bdb2d69 commit 6fbda16

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/backend/optimizer/path/indxpath.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.112.2.1 2002/08/22 16:20:38 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.112.2.2 2005/04/20 21:48:39 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -187,11 +187,16 @@ create_index_paths(Query *root, RelOptInfo *rel)
187187
* 3. Compute pathkeys describing index's ordering, if any, then
188188
* see how many of them are actually useful for this query.
189189
*/
190-
index_pathkeys = build_index_pathkeys(root, rel, index,
191-
ForwardScanDirection);
192-
index_is_ordered = (index_pathkeys != NIL);
193-
useful_pathkeys = truncate_useless_pathkeys(root, rel,
194-
index_pathkeys);
190+
index_is_ordered = OidIsValid(index->ordering[0]);
191+
if (index_is_ordered)
192+
{
193+
index_pathkeys = build_index_pathkeys(root, rel, index,
194+
ForwardScanDirection);
195+
useful_pathkeys = truncate_useless_pathkeys(root, rel,
196+
index_pathkeys);
197+
}
198+
else
199+
useful_pathkeys = NIL;
195200

196201
/*
197202
* 4. Generate an indexscan path if there are relevant restriction
@@ -201,10 +206,15 @@ create_index_paths(Query *root, RelOptInfo *rel)
201206
* If there is a predicate, consider it anyway since the index
202207
* predicate has already been found to match the query. The
203208
* selectivity of the predicate might alone make the index useful.
209+
*
210+
* Note: not all index AMs support scans with no restriction clauses.
211+
* We assume here that the AM does so if and only if it supports
212+
* ordered scans. (It would probably be better if there were a
213+
* specific flag for this in pg_am, but there's not.)
204214
*/
205215
if (restrictclauses != NIL ||
206216
useful_pathkeys != NIL ||
207-
index->indpred != NIL)
217+
(index->indpred != NIL && index_is_ordered))
208218
add_path(rel, (Path *)
209219
create_index_path(root, rel, index,
210220
restrictclauses,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy