Hi Roger, Michael, Vlad,

Let me just follow up on this old thread, as it may clarify some things.


On Fri, 2004-12-03 at 02:00, Roger Baklund wrote:
> Michael Stassen wrote:
> > You are overthinking the issue.
> 
> Probably. :)
> 
> > mysql> SELECT VERSION();
> > +-----------+
> > | VERSION() |
> > +-----------+
> > | 4.1.7     |
> > +-----------+
> > 1 row in set (0.00 sec)
> > 
> > mysql> SELECT 1 OR NULL;
> > +-----------+
> > | 1 OR NULL |
> > +-----------+
> > |         1 |
> > +-----------+
> > 1 row in set (0.00 sec)
> > 
> > We do not need to know x to determine that 1 OR x is TRUE (1).  That is 
> > the nature of OR - it only takes one TRUE value to result in TRUE (1).
> 
> I agree.

Oh, boolean logic in SQL has some funny stuff if you look at the truth
tables. However TRUE OR NULL does equal TRUE according to the SQL
standard. So MySQL's implementation is correct, as shown above.


> > Hence, 1 or NULL must evaluate to TRUE (1).  This is a case where we 
> > should correct the definition in the manual, rather than redefining how 
> > OR should behave based on the the manual's poor choice of wording.  
> 
> I agree.
> 
> > Therefore, Vlad has found a bug:
> 
> I agree again. :)
> 
> This is (as I see it) a documentation issue, I was not trying to say 
> that Vlad was "wrong".

The manual does show this example:

mysql> SELECT 1 || NULL;
        -> 1


> >> While we're at it: the term "non-zero"... what does it mean? As we all 
> >> know, NULL != 0, and 0 == zero, consequently NULL must be non-zero.

Flawed logic. Remember Venn diagrams from highschool? The circles with
numbers in them, circles can overlap, etc... the realm of valid data of
a type is enclosed in a circle, like 0-255 for a TINYINT. NULL is not
part of that set, it falls outside the realm.
You can't make any ordinary comparison with NULL, and that's also why
SQL ended up having some funny logic where logical operations that
include NULLs (like the above) sometimes appear to have odd answers.

However, MySQL is doing it correctly (as per the standard).
There used to be a bug in the handling of AND, due to an optimization in
some specific cases, but this was fixed ages ago in a 4.0 release.
If I'm not mistaken, ALL combinations are now tested in the standard
test suite so any bug would block a release going out.


> I would like to have a comment on this as well... or rather: I wonder if 
> anyone agrees with me that "non-zero" is a bad term to use in this 
> context (MySQL documentation, description of logical operator OR), or if 
> I am just overthinking again... :)

You are right. NULL is not a non-zero value. NULL is not a value at all.


Regards,
Arjen.
-- 
Arjen Lentz, Community Relations Manager
MySQL AB, www.mysql.com

MySQL Users Conference (Santa Clara CA, 18-21 April 2005)
Early registration until February 28: http://www.mysqluc.com/
22 days left for early registration, 70 days until the event!



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to