Bug #28886 | Union, Sort and Enum | ||
---|---|---|---|
Submitted: | 4 Jun 2007 22:01 | Modified: | 10 Apr 2014 15:41 |
Reporter: | Sherif Zaroubi | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Data Types | Severity: | S3 (Non-critical) |
Version: | 5.1, 5.5, 5.6, 5.7 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | Union sort enum order by |
[4 Jun 2007 22:01]
Sherif Zaroubi
[4 Jun 2007 22:15]
MySQL Verification Team
Thank you for the bug report. The server version you are reporting is pretty older could you please upgrade to most recent released version and try again. If you continue with the same behavior with the new version please provide the complete test script with create table and data insert statements, the result obtained and the expected resulted. Thanks in advance.
[4 Jul 2007 23:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".
[29 May 2009 21:28]
Rich Wales
I can confirm that this bug is still in version 5.0.75. "mysqld --version" on my Ubuntu 9.04 system says: mysqld Ver 5.0.75-0ubuntu10 for debian-linux-gnu on i486 ((Ubuntu)) The described workaround (generating an enum index field in each SELECT and ordering on this index instead of on the original enum value) also appears to work for me.
[10 Apr 2014 12:24]
Paul Lautman
This still appears to be a problem on 5.6.12
[10 Apr 2014 12:25]
Paul Lautman
Also it is on Linux as well as windows
[10 Apr 2014 15:41]
MySQL Verification Team
This is indeed a bug. Sorting by ENUM works just fine in any query that does not utilize UNIONs. However, with any UNIONs the sort is wrong. Only if converted to the integer will sorting by ENUM work in UNIONs. Here is a very descriptive test case: mysql> create table e1 (id int auto_increment, enumcol enum ('c','b','a'), primary key (id)); Query OK, 0 rows affected (0.15 sec) mysql> create table e2 (id int auto_increment, enumcol enum ('c','b','a'), primary key (id)); Query OK, 0 rows affected (0.05 sec) mysql> insert into e1 (enumcol) values ('b'),('c'),('a'); Query OK, 3 rows affected (0.05 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> insert into e2 (enumcol) values ('c'),('b'),('a'); Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> select * from ( (select enumcol, enumcol + 0 as enumindex from e1) UNION ALL (select enumcol, enumcol + 0 as enumindex from e2)) as tbl order by enumcol; +---------+-----------+ | enumcol | enumindex | +---------+-----------+ | a | 3 | | a | 3 | | b | 2 | | b | 2 | | c | 1 | | c | 1 | +---------+-----------+ 6 rows in set (0.09 sec) mysql> select * from ( (select enumcol, enumcol + 0 as enumindex from e1) UNION (select enumcol, enumcol + 0 as enumindex from e2)) as tbl order by enumcol; +---------+-----------+ | enumcol | enumindex | +---------+-----------+ | a | 3 | | b | 2 | | c | 1 | +---------+-----------+ 3 rows in set (0.00 sec) mysql> select * from ( (select enumcol, enumcol + 0 as enumindex from e1) UNION (select enumcol, enumcol + 0 as enumindex from e2)) as tbl order by enumindex; +---------+-----------+ | enumcol | enumindex | +---------+-----------+ | c | 1 | | b | 2 | | a | 3 | +---------+-----------+ 3 rows in set (0.00 sec) mysql> (select enumcol, enumcol + 0 as enumindex from e1) UNION (select enumcol, enumcol + 0 as enumindex from e2) order by enumcol; +---------+-----------+ | enumcol | enumindex | +---------+-----------+ | a | 3 | | b | 2 | | c | 1 | +---------+-----------+ 3 rows in set (0.00 sec) mysql> select enumcol, enumcol + 0 as enumindex from e1 order by enumcol; +---------+-----------+ | enumcol | enumindex | +---------+-----------+ | c | 1 | | b | 2 | | a | 3 | +---------+-----------+ 3 rows in set (0.01 sec) This is a very clearly described bug report.
[10 Apr 2014 15:56]
MySQL Verification Team
http://bugs.mysql.com/bug.php?id=72305 duplicate of this one.