问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/10747047/is-mysql-logic-evaluation-lazy-short-circuiting-in-join-clause