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

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

    Mathematically Yes It has an effect. Not only in SQL Query. rather in all programming languages whenever there is an expression with and / or . There works a theory of Complete evaluation or partial evaluation. If its an and query and first expression of and evaluates to false it will not check further. as anding false with anything yields false . Similerly in an or expression if first one is true it will not check further.

提交回复
热议问题