Bug #115907 | Incorrect result when condition use concat function | ||
---|---|---|---|
Submitted: | 23 Aug 2024 5:19 | Modified: | 26 Aug 2024 2:36 |
Reporter: | jianhua sun | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 5.7,8.0,8.4 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | concat, incorrect, join |
[23 Aug 2024 5:19]
jianhua sun
[23 Aug 2024 9:02]
MySQL Verification Team
Hi Mr. sun, Thank you for your bug report. However, we do not understand why do you consider this a bug. SQL Standard is quite clear on the join condition. ON condition is there to defined a common column. Hence, if you do not join two columns , from the same domain, that is not a join. Then, that ON statement is converted to WHERE statement. In that case, you do not have a JOIN, but a Cartesian product with filtered results. Not a bug.
[26 Aug 2024 2:36]
jianhua sun
But, even if MySQL does not treat the join as one with a join condition, the result of executing this cartesian product join is still incorrect. mysql> /*Q1' t1.c2 with index, t2.c1 equal to string */ mysql> SELECT t1.*, t2.* -> FROM t1, t2 -> WHERE t1.c2 = 100097 -> AND t1.c1 = concat(t1.c2, '0000', t2.c3) -> AND t2.c1 = '20240820003914360' -> AND t2.c2 = 437817; +-------------------+--------+--------+-------------------+--------+---------+ | c1 | c2 | c3 | c1 | c2 | c3 | +-------------------+--------+--------+-------------------+--------+---------+ | 10009700001000000 | 100097 | 100097 | 20240820003914360 | 437817 | 1000000 | | 10009700001000000 | 100097 | 100097 | 20240820003914360 | 437817 | 1000001 | | 10009700001000001 | 100097 | 100097 | 20240820003914360 | 437817 | 1000000 | | 10009700001000001 | 100097 | 100097 | 20240820003914360 | 437817 | 1000001 | | 10009700001000002 | 100097 | 100097 | 20240820003914360 | 437817 | 1000002 | | 10009700001000003 | 100097 | 100097 | 20240820003914360 | 437817 | 1000003 | | 10009700001000003 | 100097 | 100097 | 20240820003914360 | 437817 | 1000004 | | 10009700001000003 | 100097 | 100097 | 20240820003914360 | 437817 | 1000005 | | 10009700001000004 | 100097 | 100097 | 20240820003914360 | 437817 | 1000003 | | 10009700001000004 | 100097 | 100097 | 20240820003914360 | 437817 | 1000004 | | 10009700001000004 | 100097 | 100097 | 20240820003914360 | 437817 | 1000005 | +-------------------+--------+--------+-------------------+--------+---------+ 11 rows in set (0.00 sec) mysql> mysql> mysql> /*Q5' t1.c2 with index, t2.c1 equal to string, 100097 pushdown to concat */ mysql> SELECT t1.*, t2.* -> FROM t1, t2 -> WHERE t1.c2 = 100097 -> AND t1.c1 = concat(100097, '0000', t2.c3) -> AND t2.c1 = '20240820003914360' -> AND t2.c2 = 437817; +-------------------+--------+--------+-------------------+--------+---------+ | c1 | c2 | c3 | c1 | c2 | c3 | +-------------------+--------+--------+-------------------+--------+---------+ | 10009700001000000 | 100097 | 100097 | 20240820003914360 | 437817 | 1000000 | | 10009700001000001 | 100097 | 100097 | 20240820003914360 | 437817 | 1000001 | | 10009700001000002 | 100097 | 100097 | 20240820003914360 | 437817 | 1000002 | | 10009700001000003 | 100097 | 100097 | 20240820003914360 | 437817 | 1000003 | | 10009700001000004 | 100097 | 100097 | 20240820003914360 | 437817 | 1000004 | +-------------------+--------+--------+-------------------+--------+---------+ 5 rows in set (0.01 sec)
[26 Aug 2024 7:00]
Roy Lyseng
I am a bit confused over what the incorrect results you see are. However, I wonder if the problems is due to the join condition's operands being cast to a DOUBLE. Can you try to cast the CONCAT result into an UNSIGNED value, or cast t1.c1 into a CHAR(17)?
[16 Sep 2024 9:12]
MySQL Verification Team
Thank you , Roy.