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

后端 未结 5 2051
庸人自扰
庸人自扰 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:52

    Yes, this is a common optimization. Any query that would benefit from the index on A,B can also benefit just as well from the index on A,B,C.

    In the MySQL community, there's even a tool to search your whole schema for redundant indexes: http://www.percona.com/doc/percona-toolkit/pt-duplicate-key-checker.html

    The possible exception case would be if the index on A,B were more compact and used much more frequently, and you wanted to control which index was kept loaded in memory.

提交回复
热议问题