Is an index on A, B redundant if there is an index on A, B, C?

后端 未结 5 2053
庸人自扰
庸人自扰 2021-02-02 18:30

Having years of experience as a DBA, I do believe I know the answer to the question, but I figured it never hurts to check my bases.

Using SQL Server, assuming I have a

5条回答
  •  天涯浪人
    2021-02-02 18:56

    The first index covers queries that look up on A , A,B and the second index can be used to cover queries that look up on A , A,B or A,B,C which is clearly a superset of the first case.

    If C is very wide however the index on A,B may still be useful as it can satisfy certain queries with fewer reads.

    e.g. if C was a char(800) column the following query may benefit significantly from having the narrower index available.

    SELECT a,b
    FROM YourTable
    ORDER BY a,b
    

提交回复
热议问题