Sybase® SQL ServerPerformance and Tuning Guide
Chapter 9: Advanced Optimizing Techniques


Specifying an Index for a Query

A special clause, (index index_name), for the select, update, and delete statements allows you to specify an index for a particular query. The syntax is:

select select_list
from table_name
    (index index_name)
    [, table_name ...]
where ...
delete table_name 
from table_name (index index_name) ... 
update table_name set col_name = value
    from table_name (index index_name) ...

Here's an example:

select pub_name, title
    from publishers p, titles t (index date_type)
    where p.pub_id = t.pub_id
    and type = "business"
    and pubdate > "1/1/93"

Specifying an index in a query can be helpful when you suspect that the optimizer is choosing a suboptimal query plan. When you use this option:

Use this option only after testing to be certain that the query performs better with the specified index option. Once you include this index option in applications, you should check regularly to be sure that the resulting plan is still superior to other choices that the optimizer makes.

If you want to force a table scan, use the table name in place of index_name.

Note: If you have a nonclustered index with the same name as the table, attempting to specify a table name causes the nonclustered index to be used. You can force a table scan using select select_list from tableA (0).

Risks of Specifying Indexes in Queries

Specifying indexes has these risks:

Things to Try Before Specifying Indexes

Before specifying an index in queries: