Do mysql composite indexes make some other indexes completely redundant?

旧街凉风 提交于 2019-12-05 11:15:41

Your (a,b) index will also handle queries involving only 'a' and there is no need for an index on (a) alone.

From the documentation:

If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer to find rows.

For example, if you have a three-column index on (col1, col2, col3), you have indexed search capabilities on (col1), (col1, col2), and (col1, col2, col3).

My question is whether there is any valid reason to have a single-column index on 'a' if I have the (a, b) index?

No, there is no reason to have an index on (a) if you have one on (a,b)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!