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