Bug #1828 "OR" SQL operator is not cumutative under specific index
Submitted: 13 Nov 2003 6:36 Modified: 28 Nov 2003 5:31
Reporter: Nickolai Berezin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.0.10 OS:Microsoft Windows (Windows XP)
Assigned to: Alexey Botchkov

[13 Nov 2003 6:36] Nickolai Berezin
Description:
"OR" SQL operator sometimes is not cumutative under index. 

 

 

How to repeat:
I have a table “transaction” with fields: ID, accountSource, accountDest, storn 
and also with index(storn, accountSource, accountDest)
 

The result of the query 

Select count(*) from transaction where (storn=0 and accountSource=34) or (storn=0 and accountDest=34)

Is 50.

And the result of the query 

Select count(*) from transaction where (storn=0 and accountDest=34) or (storn=0 and accountSource=34)

Is 2933

Or is not commutative under the index!!!!
ignoring this index it works correctly.
[13 Nov 2003 7:46] Dean Ellis
Verified in 4.0.17 (Windows XP, Linux).

Thank you.

CREATE TABLE testing (
  a int,
  b int,
  c int
) TYPE=MyISAM;

INSERT INTO testing VALUES (1,0,0),(1,0,0),(1,0,0);
INSERT INTO testing VALUES (0,1,0),(0,1,0),(0,1,0);

-- Both report 6
SELECT COUNT(*) FROM testing WHERE (c=0 and a=1) or (c=0 and b=1);
SELECT COUNT(*) FROM testing WHERE (c=0 and b=1) or (c=0 and a=1);

ALTER TABLE testing ADD INDEX (c,a,b);

-- First reports 3; second reports 6
SELECT COUNT(*) FROM testing WHERE (c=0 and a=1) or (c=0 and b=1);
SELECT COUNT(*) FROM testing WHERE (c=0 and b=1) or (c=0 and a=1);
[21 Nov 2003 5:06] Alexey Botchkov
bk commit - 4.1 tree (hf:1.1627)
[28 Nov 2003 5:31] Michael Widenius
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

Fix will be in 4.0.17 and 4.1.1 binary releases