On Mon, 1999-08-16 15:54:10 +0100, Paul wrote:
> SELECT * FROM WINE WHERE ((0) OR (typeID=8))
> Does anyone know of any reason why this should not be done?
Well, if you're compiling the SELECT statement with a program, why not
program it to leave out such dummy parts of the expression?
On the MySQL side, it's not a problem (no noticable performance hit).
It's more a matter of style ...
> When executing the query does MySQL find the answer to the first
> half of the expression first, and only if true then finds the answer
> to the second half of the statement?
Just the other way round, with OR there could be the optimization to
stop evaluation, if one of the OR terms is to be found true, because
then the whole term must be true (lazy evaluation). But this wouldn't
change the semantics, and so no problem for you. (I don't know, if
MySQL actuall does this kind of optimization ...)
For AND terms you would have to add: AND 1.
BTW, if possible it's better practice not to depend on 0 being false,
and 1 being true. Use "(1=0) OR" and "(1=1) AND" instead, because
this will function allright in every DBMS, regardless of the internal
representation of true and false.
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