Bug #5555 "GROUP BY enum_field" returns incorrect results
Submitted: 14 Sep 2004 0:23 Modified: 5 Oct 2004 11:52
Reporter: Jim Winstead Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.4-gamma-standard-log OS:Linux (Linux 2.6)
Assigned to: Sergei Glukhov CPU Architecture:Any

[14 Sep 2004 0:23] Jim Winstead
Description:
when doing a group by on an enum field, the results are all grouped and counted as if they had 
the same value. doing a 'GROUP BY field+0' returns the expected results. (see below.)

How to repeat:
CREATE TABLE groupbyenum (
  id int(10) unsigned NOT NULL auto_increment,
  val enum('one','two','three') NOT NULL default 'one',
  PRIMARY KEY  (id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO groupbyenum VALUES
(1,'one'),(2,'two'),(3,'three'),(4,'one'),(5,'two');

mysql> select val, count(*) from groupbyenum group by val;
+-----+----------+
| val | count(*) |
+-----+----------+
| one |        5 |
+-----+----------+
1 row in set (0.00 sec)

mysql> select val, count(*) from groupbyenum group by val+0;
+-------+----------+
| val   | count(*) |
+-------+----------+
| one   |        2 |
| two   |        2 |
| three |        1 |
+-------+----------+
3 rows in set (0.00 sec)
[14 Sep 2004 0:32] Jim Winstead
this has been verified on two different machines running 4.1.4, but the bug does not appear to be 
present in 4.1.3.
[14 Sep 2004 8:29] Alexander Keremidarski
Test with ChangeSet@1.1996.1.6, 2004-09-13 16:26:01+04:00, sergefp@mysql.com
 returns correct results

mysql> select val, count(*) from groupbyenum group by val;
+-------+----------+
| val   | count(*) |
+-------+----------+
| one   |        2 |
| two   |        2 |
| three |        1 |
+-------+----------+
3 rows in set (0.02 sec)
 
mysql> select val, count(*) from groupbyenum group by val+0;
+-------+----------+
| val   | count(*) |
+-------+----------+
| one   |        2 |
| two   |        2 |
| three |        1 |
+-------+----------+
[14 Sep 2004 20:27] Jani Tolonen
Just did a fresh bk pull on 4.0 source and was able to repeat the problem (14.09.2004)

4.1.5-gamma-debug-log

Compiled with ./BUILD/compile-pentium-debug

OS: Linux SuSE 9.0
[14 Sep 2004 21:51] Alexander Keremidarski
I can repeat the bug now with both
BUILD/compile-pentium-debug 
and
BUILD/compile-pentium-debug-max

ChangeSet@1.2007.2.1, 2004-09-14 13:09:51+05:00, ram@gw.mysql.r18.ru
[16 Sep 2004 16:10] Sergei Glukhov
ChangeSet
  1.2016 04/09/16
  Fix for bug #5555: GROUP BY enum_field" returns incorrect results
[5 Oct 2004 11:52] Sergei Glukhov
Fixed in 4.1 source tree