Bug #75668 Use of Distinct, Group_concat, and Group by together produces 1 NULL row result.

Submitted: 28 Jan 2015 16:21 Modified: 28 Jan 2015 20:06
Reporter: Jonathan Moore Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:5.6.22/5.7 OS:FreeBSD (FreeBSD 8.4)
Assigned to: CPU Architecture:Any
Tags: regression

[28 Jan 2015 16:21] Jonathan Moore
Description:
Current Output:
mysql> select distinct trim(group_concat(A)) from TEST_JM group by B;
+-----------------------+
| trim(group_concat(A)) |
+-----------------------+
| NULL                  |
+-----------------------+
1 row in set (0.00 sec)

Expected output:
mysql> SELECT DISTINCT TRIM(GROUP_CONCAT(id)) FROM test GROUP BY id;
+------------------------+
| TRIM(GROUP_CONCAT(id)) |
+------------------------+
| 1                      |
| 2                      |
+------------------------+
2 rows in set (0.00 sec)

The expected output is from a MySQl 5.1.42 server.

How to repeat:
CREATE TABLE IF NOT EXISTS `test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=myisam DEFAULT CHARSET=latin1;

INSERT INTO test values(1), (2);

SELECT DISTINCT TRIM(GROUP_CONCAT(id)) FROM test GROUP BY id
[28 Jan 2015 20:03] MySQL Verification Team
C:\dbs>c:\dbs\5.5\bin\mysql -uroot --port=3550 --prompt="mysql 5.5 > "
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.43 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 5.5 > use test
Database changed
mysql 5.5 > CREATE TABLE IF NOT EXISTS `test` (
    ->   `id` int(11) NOT NULL AUTO_INCREMENT,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=myisam DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.03 sec)

mysql 5.5 >
mysql 5.5 > INSERT INTO test values(1), (2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql 5.5 >
mysql 5.5 > SELECT DISTINCT TRIM(GROUP_CONCAT(id)) FROM test GROUP BY id;
+------------------------+
| TRIM(GROUP_CONCAT(id)) |
+------------------------+
| 1                      |
| 2                      |
+------------------------+
2 rows in set (0.03 sec)

----------------------------------------------------------------------------------

C:\dbs>c:\dbs\5.6\bin\mysql -uroot --port=3560 --debug-info --prompt="mysql 5.6 > "
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 5.6 > use test
Database changed
mysql 5.6 > CREATE TABLE IF NOT EXISTS `test` (
    ->   `id` int(11) NOT NULL AUTO_INCREMENT,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=myisam DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.03 sec)

mysql 5.6 >
mysql 5.6 > INSERT INTO test values(1), (2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql 5.6 >
mysql 5.6 > SELECT DISTINCT TRIM(GROUP_CONCAT(id)) FROM test GROUP BY id;
+------------------------+
| TRIM(GROUP_CONCAT(id)) |
+------------------------+
| NULL                   |
+------------------------+
1 row in set (0.01 sec)
[28 Jan 2015 20:06] MySQL Verification Team
Thank you for the bug report.
[28 Jan 2015 20:07] MySQL Verification Team
C:\dbs>net start mysqld57
The MySQLD57 service is starting.
The MySQLD57 service was started successfully.

C:\dbs>57

C:\dbs>c:\dbs\5.7\bin\mysql -uroot --port=3570 --prompt="mysql 5.7 > "
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.7.6-m16 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 5.7 > use test
Database changed
mysql 5.7 > CREATE TABLE IF NOT EXISTS `test` (
    ->   `id` int(11) NOT NULL AUTO_INCREMENT,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=myisam DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.08 sec)

mysql 5.7 >
mysql 5.7 > INSERT INTO test values(1), (2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql 5.7 >
mysql 5.7 > SELECT DISTINCT TRIM(GROUP_CONCAT(id)) FROM test GROUP BY id;
+------------------------+
| TRIM(GROUP_CONCAT(id)) |
+------------------------+
| NULL                   |
+------------------------+
1 row in set (0.00 sec)

mysql 5.7 >

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.055 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.