Bug #116050 The query results are incorrect when using CTE, CONCAT, and IN.

Submitted: 10 Sep 2024 6:14 Modified: 15 Oct 11:33
Reporter: heng yue Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.39, 8.4.2 OS:Linux (centos7)
Assigned to: CPU Architecture:x86

[10 Sep 2024 6:14] heng yue
Description:
When using CTE queries, if CONCAT is used to concatenate results and then the concatenated result is used as a condition for subsequent queries, the results may be incorrect.

How to repeat:
1、git clone https://github.com/yhld456/mysqltestdata.git
2、source test1.sql
3、source test2.sql
4、Execute the following statement to perform the query; the result is incorrect.

with tmp1 as(
  select 
  CONCAT('["',t1.id,'"]') as id
  from test1 t1 where t1.role_code='588408423353684352'
)
select * from test2 t1 where t1.ensure_role in(select id from tmp1);

5、Create the index by executing the following statement, and then the query results will be correct.
CREATE INDEX idx_ensure_role ON test2 (ensure_role);
[10 Sep 2024 6:24] heng yue
sql

Attachment: test1.sql (application/octet-stream, text), 1.70 KiB.

[10 Sep 2024 6:24] heng yue
sql

Attachment: test2.sql (application/octet-stream, text), 69.39 KiB.

[10 Sep 2024 8:39] MySQL Verification Team
Hello heng yue,

Thank you for the report and test case.

regards,
Umesh
[28 Jan 2:13] heng yue
The bug is fixed in 9.5.0, but we are on LTS 8.4.x in production.
Please consider backporting the fix to 8.4.x+ as it affects data correctness
[15 Oct 11:33] heng yue
Thanks for the fix. I've verified that the issue is resolved in version 8.4.11.
Appreciate your help!
Best regards

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

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