开发者

Does a MySQL index on columns (A,B,C) optimize for queries than just select/order by (A,B) only?

开发者 https://www.devze.com 2023-04-10 02:11 出处:网络
Given a table with columns A,B,D,E,F. I have two queries: one that orders by A then B. one that orders by A, then B, then C

Given a table with columns A,B,D,E,F. I have two queries:

  • one that orders by A then B.
  • one that orders by A, then B, then C

I want to add an index on (A,B,C) to speed up the second query. I'm thinking this will also speed up the first query. Is that correct? Or should I add a second index on (A,B)?

Or am I oversimplifyi开发者_如何学编程ng the problem of performance-tuning here?


Just put an index on all three of them. You don't need a second index.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号