MySQL indices and order

前端 未结 3 997
长发绾君心
长发绾君心 2020-12-02 11:44

This is a question that I\'ve had forever.

As far as I know the order of indices matter. So an index like [first_name, last_name] is not the same as

3条回答
  •  生来不讨喜
    2020-12-02 12:07

    ChssPly76 is correct that the order of boolean expressions does not have to match the order of columns in the index. Boolean operators are commutative, and the MySQL optimizer is smart enough to know how to match the expression to the index in most cases.

    I also want to add that you should learn how to use the EXPLAIN feature of MySQL so you can see for yourself which indexes the optimizer will choose for a given query.

提交回复
热议问题