I have 2 tables, Items and ItemDetails. Generally any query on this data is performed through the Items_join_ItemDetails view, which joins the two tables on the common ItemID field.
Currently ItemDetails has a clustered index on (Date, ItemID) and a non-clustered index on just ItemID. Items has a clustered index on ItemID.
When the view is queried, it is almost always for a date range, which is why the clustered index is on Date for ItemDetails. However, this means that the view has to join using the non-clustered ItemID index for ItemDetails.
Would performance be better if I switched the clustered and non-clustered indexes for ItemDetails? I can see how this would help the join operation, however I can also see how it would hurt the date filtering by queries.
The clustered index is over 2 columns so the join on ItemID should come from this index. The NC index on ItemID alone may be unused, at least for this query.
What is more important is to ensure the indexes are covering: all columns needed are in the indexes.
Do you have any performance issues?
We’d also need the table and view definitions to make further suggestions.