Bug #1428 Incorrect handling of UNION ALL
Submitted: 29 Sep 2003 2:13 Modified: 23 Mar 2004 7:43
Reporter: Dirk Thomsen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1 OS:Windows (Win)
Assigned to: Sergei Golubchik CPU Architecture:Any

[29 Sep 2003 2:13] Dirk Thomsen
Description:
 The handling of UNION ALL is incorrect with more than one UNION in a sql-statement.

How to repeat:
create table t (i int);
insert into t values (1);

select * from t UNION select * from t      -> 1 line  -> correct
select * from t UNION ALL select * from t  -> 2 lines -> correct

BUT

select * from t UNION select * from t UNION ALL select * from t  
-> 3 lines -> INCORRECT

Any statements where UNION is mixed with UNION ALL may have incorrect results!

Suggested fix:
The reason for this incorrect handling is that the information about the ALL is stored in lex->union_option which is used for all UNIONs rather than to be stored for each of the UNIONs...
[10 Dec 2003 18:41] Michael Widenius
To be fixed in 4.1.x tree.
(Too big code change to fix in 4.0; I have for now documented this bug in the MySQL manual)
[6 Feb 2004 10:51] MySQL Verification Team
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

Additional info:

A fix will come in 4.1.2.
[6 Feb 2004 10:54] MySQL Verification Team
Sorry, wrong bug record.
[20 Mar 2004 6:01] MySQL Verification Team
A patch in 4.1.2 was proposed for the resolution of this bug.
[23 Mar 2004 7:43] Sergei Golubchik
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

Additional info:

fixed in 4.1.2