4

I am currently going through all indexes in our data warehouse as a performance tuning exercise. Several of these indexes are not used in the system stats, and I am considering removing them to reduce overhead during batch.

Some of these does not make sense, due to PK columns being used in the middle of other indexes, etc. However, I was wondering how SQL Server handles multi column indexes (with overlapping column).

Examples:

NONCLUSTERED INDEX Index1 (A, B, C)

NONCLUSTERED INDEX Index2 (A, B)

Would SQL Server be able to use Index1 for the same rows as Index2 and Index2 is not needed? I know the rowID are contained in the leaf level node of the B+tree, however all records for C would be valid in Index1.

Can Index2 be removed without impacting performance?
As far as I have understood, indexes can also help with sorts in execution plan. Can Index1 be used for these as well?

2
  • Do the indexes have the same included columns? Mar 8, 2019 at 11:58
  • I wonder in either way, If yes the necessary data would be included at the bottom. If not it would still have the row ID to find t he necessary data. I guess most of my cases does not include the same columns, as many indexes are mostly used to provide data in the 'right order' and not the data itself (big tables with a lot of different use)
    – Creztian
    Mar 8, 2019 at 12:01

1 Answer 1

9

In general you should be able to remove Index2 without any major issues. Index1 can cover any queries that Index2 would currently be handling (assuming there aren't any included column differences between the two).

If column C in Index1 is large, you might end up reading slightly more data into memory with Index1 for queries that would have used Index2 since that third column is taking up more space on each page, but in most scenarios I don't think you would notice any perceptible differences in performance.

2
  • Thank you! What about this case? Would index 2 always be preferred over index1 when only checking colum A due to included columns providing more information at leaf level? (Index2 are tailor made and therefore used, while index1 are never used while it should address general queries for the table) NC Index1 (A, B) NC Index2 (A,C) INCLUDE( X, Y, Z)
    – Creztian
    Mar 8, 2019 at 12:59
  • 2
    Not sure I fully understand, but there's a lot of hypotheticals. Best thing to do would be to code it, try it, and look at the execution plan to see what SQL Server ends up using. Mar 8, 2019 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.