Bug #2786 incorrect precedence for XOR operator
Submitted: 13 Feb 2004 20:03 Modified: 17 Feb 2004 2:03
Reporter: Matthias Fripp Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.13 OS:Microsoft Windows (Windows XP)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[13 Feb 2004 20:03] Matthias Fripp
Description:
When evaluating expressions, MySQL seems to give XOR the same precedence as LIKE, while it gives OR a lower precedence. That is,
1 LIKE 2 XOR 2 LIKE 1 is evaluated as
((1 LIKE 2) XOR 2) LIKE 1) and comes out true, instead of being evaluated as 
(1 LIKE 2) XOR (2 LIKE 1), which is false, or even as 
1 LIKE (2 XOR 2) LIKE 1, which is also false.

However, 1 LIKE 2 OR 2 LIKE 1 is evaluated as (1 LIKE 2) OR (2 LIKE 1), and comes out false.

How to repeat:
use the queries:
SELECT 1 LIKE 2 XOR 2 LIKE 1;
SELECT ((1 LIKE 2) XOR 2) LIKE 1;
SELECT (1 LIKE 2) XOR (2 LIKE 1);
SELECT 1 LIKE (2 XOR 2) LIKE 1;

SELECT 1 LIKE 2 OR 2 LIKE 1;
SELECT ((1 LIKE 2) OR 2) LIKE 1;
SELECT (1 LIKE 2) OR (2 LIKE 1);
SELECT 1 LIKE (2 OR 2) LIKE 1;

Suggested fix:
I believe the correct approach would be to give XOR the same precedence as OR, and both should have a lower precedence than LIKE. That is, 1 LIKE 2 XOR 2 LIKE 1 should be evaluated as (1 LIKE 2) XOR (2 LIKE 1).
[17 Feb 2004 2:03] Ramil Kalimullin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html