Bug #26937 Wrong results when using GROUP BY SUBSTRING(..) and LONGTEXT
Submitted: 7 Mar 2007 21:46 Modified: 9 Mar 2007 15:54
Reporter: Morgan Tocker Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1,5.0,5.1 OS:
Assigned to: Assigned Account CPU Architecture:Any

[7 Mar 2007 21:46] Morgan Tocker
Description:
** As below **

How to repeat:
mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE t1 ( a LONGTEXT );
Query OK, 0 rows affected (0.10 sec)

mysql> INSERT INTO t1 VALUES ('a'),('a '),('a  '),('b'),('a    ');
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT SUBSTRING(a,1) AS x FROM t1 GROUP BY SUBSTRING(a,1);
+------+
| x    |
+------+
|      | 
+------+
1 row in set (0.00 sec)

mysql> SELECT SUBSTRING(a,1,1) AS x FROM t1 GROUP BY SUBSTRING(a,1);
+------+
| x    |
+------+
|      | 
+------+
1 row in set (0.00 sec)

Then with text:

mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE t1 ( a TEXT );
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t1 VALUES ('a'),('a '),('a  '),('b'),('a    ');
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> SELECT SUBSTRING(a,1) AS x FROM t1 GROUP BY SUBSTRING(a,1);
+------+
| x    |
+------+
| a    | 
| b    | 
+------+
2 rows in set (0.01 sec)

mysql> SELECT SUBSTRING(a,1,1) AS x FROM t1 GROUP BY SUBSTRING(a,1);
+------+
| x    |
+------+
| a    | 
| b    | 
+------+
2 rows in set (0.00 sec)

Suggested fix:
Behave as with TEXT.
[9 Mar 2007 15:54] Evgeny Potemkin
Duplicate of the bug#15757.