Bug #1428 Incorrect handling of UNION ALL
Submitted: 29 Sep 2003 4:13 Modified: 23 Mar 2004 8:43
Reporter: Dirk Thomsen
Status: Closed
Category:Server Severity:S2 (Serious)
Version:4.1 OS:Microsoft Windows (Win)
Assigned to: Sergei Golubchik Target Version:

[29 Sep 2003 4: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 19: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 11:51] Sinisa Milivojevic
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 11:54] Sinisa Milivojevic
Sorry, wrong bug record.
[20 Mar 2004 7:01] Sinisa Milivojevic
A patch in 4.1.2 was proposed for the resolution of this bug.
[23 Mar 2004 8: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