9
9
*
10
10
*
11
11
* 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 $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -187,11 +187,16 @@ create_index_paths(Query *root, RelOptInfo *rel)
187
187
* 3. Compute pathkeys describing index's ordering, if any, then
188
188
* see how many of them are actually useful for this query.
189
189
*/
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 ;
195
200
196
201
/*
197
202
* 4. Generate an indexscan path if there are relevant restriction
@@ -201,10 +206,15 @@ create_index_paths(Query *root, RelOptInfo *rel)
201
206
* If there is a predicate, consider it anyway since the index
202
207
* predicate has already been found to match the query. The
203
208
* 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.)
204
214
*/
205
215
if (restrictclauses != NIL ||
206
216
useful_pathkeys != NIL ||
207
- index -> indpred != NIL )
217
+ ( index -> indpred != NIL && index_is_ordered ) )
208
218
add_path (rel , (Path * )
209
219
create_index_path (root , rel , index ,
210
220
restrictclauses ,
0 commit comments