Take the following expression: FALSE AND (expression)
Will MySQL evaluate the expression or just move on as soon as it sees FALSE
?
Some background context-- I wanted to speed up a query by doing:
JOIN... ON (indexed_column1=indexed_column2 AND non_indexed_column_a=non_indexed_column_b)
For background on why I'm doing this query see this answer
If it's going to always evaluate non_indexed_column_a=non_indexed_column_b
then no time is saved with that.
SQL Server does not short-circuit expressions.
MySQL OR short-circuit evaluationMySQL uses short-circuit evaluation for the OR operator. In other words, MySQL stops evaluating the remaining parts of the statement when it can determine the result. See the following example. Because the expression 1 = 1 always returns true, MySQL does not evaluate the 1 / 0.
The MySQL query optimizer uses indexes whenever possible and to use the most restrictive index in order to eliminate as many rows as possible.
So in case of your query it will always filter the records based on first indexes columns and then filter the records from non-index columns.
Also before query execution, MySQL eliminates the code which is always going to be false (Dead Code) .
For more details see: http://www.informit.com/articles/article.aspx?p=377652&seqNum=2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With