Does the order of conditions in a WHERE clause affect MySQL performance?

前端 未结 8 639
长发绾君心
长发绾君心 2020-11-29 06:10

Say that I have a long, expensive query, packed with conditions, searching a large number of rows. I also have one particular condition, like a company id, that will limit t

8条回答
  •  一个人的身影
    2020-11-29 06:42

    No, the order should not make a large difference. When finding which rows match the condition, the condition as a whole (all of the sub-conditions combined via boolean logic) is examined for each row.

    Some intelligent DB engines will attempt to guess which parts of the condition can be evaluated faster (for instance, things that don't use built-in functions) and evaluate those first, and more complex (estimatedly) elements get evaluated later. This is something determined by the DB engine though, not the SQL.

提交回复
热议问题