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