Multiple and single indexes

后端 未结 4 917
忘了有多久
忘了有多久 2021-01-30 17:08

I\'m kinda ashamed of asking this since I\'ve been working with MySQL for years, but oh well.

I have a table with two fields, a and b. I will b

4条回答
  •  醉酒成梦
    2021-01-30 17:46

    SQL will choose the index that best covers the query. An index on A, B will cover the query for both case 1 and 3, but not for 2 (since the primary index column is A)

    So to cover all three queries you need two indexes:

    ALTER TABLE ... ADD INDEX (a, b); ALTER TABLE ... ADD INDEX (b)
    

提交回复
热议问题