List:General Discussion« Previous MessageNext Message »
From:Martin Ramsch Date:August 16 1999 3:23pm
Subject:Re: AND statements
View as plain text  
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: >
PGP KeyID=0xE8EF4F75 FiPr=52 44 5E F3 B0 B1 38 26  E4 EC 80 58 7B 31 3A D7
AND statementsPaul16 Aug
  • Re: AND statementsMartin Ramsch16 Aug
  • Re: AND statementsRuben I Safir16 Aug
RE: AND statementsPaul16 Aug
RE: AND statementsClinton16 Aug
  • Re: AND statementsMartin Ramsch16 Aug
RE: AND statementsPaul16 Aug
  • RE: AND statementsMichael Widenius21 Aug