Reputation: 85056
When I look at the execution plan for a particular query I find that 77% of my cost is in a Clustered Index seek.
Does the fact that I'm using a clustered index mean that I won't see performance issues due to the columns that I am outputting?
Would it be better for me to create a Non-Clustered version of this and include all of the columns that are being output?
UPDATE: The clustered index uses a composite key. Not sure if this makes a difference.
Upvotes: 4
Views: 6024
Reputation: 14832
The reason you use include columns on a non-clustered index is to avoid "bookmark-lookups" into the clustered data. The thing is that if SQL Server could theoretically use a particular non-clustered index but the Optimiser estimates there will be 'too many' bookmark-lookups then said index will be ignored. However, if all selected columns are accessible directly from the index, there'll be no need for a bookmark-lookup.
In your case the fact that you're accessing the data via "clustered index seek" is very promising. It will be very hard to improve on its performance. A non-clustered index including all selected columns may be slightly faster, but only because the raw data is a little less. (But don't forget the cost of increased insert/update time.)
However, you should check the detail...
Finally, to elaborate on davek's comment: "cost is relative". Just because the clustered is 77% of your query cost doesn't mean there's a problem. It is possible to write a trivial 1 table query that returns a sinlge row and clustered index seek cost at 100%. (But of course, being the only 'work' done, it will be 100% of the work... and 100% of instant is still instant.
So: "Don't worry; be happy!"
Upvotes: 4
Reputation: 432271
You have a seek already, so benefits may be minimal.
You can try it though. Options:
Are there other good cluster candidates? Note, you always need a unique clustered index (because of uniquifiers + here SO + here). And of course, what is your PK please?
Upvotes: 1
Reputation: 74270
It depends on how many columns you are talking about, if a couple then yes, a non clustered index will perform better, if you are selecting most of the columns the clustered index is better.
Upvotes: 0