On Mon, 1999-08-16 16:36:51 +0100, Clinton wrote:
> So does MySQL use "lazy evaluation" or not (ie , if the left hand
> side of the OR statement is true, then ignore the right hand side)
> Because if it does, this would mean that Paul can prepare 1
> statement which works for all conditions rather than preparing a new
> statement for each query, or prepreparing potentially hundreds of
Sorry, I still can't answer this.
But why does it matter? Even with lazy evaluation the complete SQL
statement would have to have proper syntax, so it's not possible to
write something like "(1=1) OR crap", hoping that MySQL won't complain
about the crap.
So the question is not about working or not working, "just" about
And that's something you easily can test yourself!
| mysql> SELECT BENCHMARK(1000000, 1=1 AND SIN(0.5)>0.5);
| 1 row in set (3.62 sec)
| mysql> SELECT BENCHMARK(1000000, 1=0 AND SIN(0.5)>0.5);
| 1 row in set (1.18 sec)
| mysql> SELECT BENCHMARK(1000000, 1=0 OR SIN(0.5)>0.5);
| 1 row in set (3.74 sec)
| mysql> SELECT BENCHMARK(1000000, 1=1 OR SIN(0.5)>0.5);
| 1 row in set (1.21 sec)
So, yes! MySQL seems to do lazy evaluation.
But I recommend that you do your own testing, too.
Martin Ramsch <m.ramsch@stripped> <URL: http://home.pages.de/~ramsch/ >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26 E4 EC 80 58 7B 31 3A D7