Bug #99142 The result mismatches when DISTINCT syntax exists

Submitted: 1 Apr 2020 7:39 Modified: 1 Apr 2020 8:18
Reporter: Hope Lee (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.16, 8.0.19, 5.7.29 OS:Any
Assigned to: CPU Architecture:Any

[1 Apr 2020 7:39] Hope Lee
Description:
When the DISTINCT syntax is added to the SQL, the result mismatches.

How to repeat:
CREATE TABLE t1 (  
a INT,  
b INT);

INSERT INTO t1 VALUES(1, 2), (3, 4);

root@localhost:test 8.0.16-rds-dev> SELECT if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) FROM t1 aa LEFT JOIN t1 bb ON aa.a = bb.a GROUP BY bb.b, aa.a;
+--------------------------------------------------------------------------------------+
| if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) |
+--------------------------------------------------------------------------------------+
| 1                                                                                    |
| 3                                                                                    |
+--------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

root@localhost:test 8.0.16-rds-dev> SELECT DISTINCT if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) FROM t1 aa LEFT JOIN t1 bb ON aa.a = bb.a GROUP BY bb.b, aa.a;
+--------------------------------------------------------------------------------------+
| if(COALESCE(aa.a, 'hope') = 'hope', 'hope', group_concat(distinct concat(aa.a, ""))) |
+--------------------------------------------------------------------------------------+
| 1                                                                                    |
+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

The above results of the two queries are obviously inconsistent.
[1 Apr 2020 8:18] MySQL Verification Team
Hello Lee,

Thank you for the report and test case.

regards,
Umesh

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

Page generated in 0.051 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.