Q8.5: How do I force an index to be used?


Sybase 4.x and Sybase System 10

All indexes have an ordinal value assigned to them. For example, the following query will return the ordinal value of all the indexes on my_table: select name, indid from sysindexes where id = object_id("my_table") Assuming that we wanted to force the usuage of index numbered three: select ... from my_table(3) note that using a value of zero is equivalent to a table scan.
You should heavily document any indexed that are forced.

System 11

In System 11, the binding of the internal ordinal value is alleviated so that instead of using the ordinal index value, the index name can be used instead:
select ... from my_table (index my_first_index)
Note that you should still document that the index is being forced.