About indexes

Puiu

Well-known member
Joined
Oct 6, 2004
Messages
90
Hello,

I have a database with multiple tables that reference each other using foreign key constraints. On each of these columns i set a different nonclustered index.
However it seems that not everywhere i have a join on those foreign keys the index is used.

My question: Is there a chance that a query uses a nonclustered index and the execution plan doesnt show it?

Ive red somewhere that the nonclustered indexes use the clusterd index to retrieve their data and i was asking myself if this wouldnt hide the use of the nonclustered index in the execution plan.

thank you!
 
Althought its hard to read, the output of the statistics may help. See this thread for the code to use in Query Analyzer. I did a google search and came up with the following link, which looks pretty useful for explaining how to read the output.:
http://blogs.msdn.com/queryoptteam/archive/2006/08/29/730521.aspx

I googled for |sql server "statistics profile"| (between the pipes).

In answer to your question - as far as I know it, if the optimizer picks your nonclustered index, it will show up in the query plan even if that index relies on the clustered index. I believe the clustered index may be used to return data, if the columns used by your query are in the clusterd index. Thats why, in some cases, its good to have multiple columns in a clustered index. Then if a query matches a row and all columns come from the clustered index, the read is that much faster (its a direct read instead of a read of a pointer which then reads the row).

Ive found that digging into the optimizer for day to day stuff is too overwhelming, unless you have a DBA. If you have certain queries that just look right but dont seem to perform well, thats when I dig out these tools.

If you need more help, you may be able to create a script of the relevent tables and index and attach them for us to try. Indexes are funny, though. The optimizer will make decisions based on what it thinks the data looks like. Make sure you run DBCC commands to refresh the statistics and indexes. If the statistics on your DB are not up to date, the optimizer may pick the wrong index.

-ner
 
Back
Top