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

前端 未结 8 616
长发绾君心
长发绾君心 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:48

    A sophisticated DBMS should be able to decide on its own which where condition to evaluate first. Some Databases provide tools to display the "strategy" how a query is executed. In MySQL, e.g. you can enter EXPLAIN in front of a query. The DBMS then prints the actions it performed for executing the query, as e.g. index or full-table scan. So you could see at a glance whether or not it uses the index for 'company' in both cases.

提交回复
热议问题