Bug #117852 | Incorrect Handling of NULL Values with FIELD Function in SQL Query | ||
---|---|---|---|
Submitted: | 2 Apr 7:14 | Modified: | 2 Apr 9:30 |
Reporter: | zhiqiang cheng | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S2 (Serious) |
Version: | 9.1.0, 8.0.41, 8.4.4, 9.2.0 | OS: | Ubuntu (20.04) |
Assigned to: | CPU Architecture: | Any |
[2 Apr 7:14]
zhiqiang cheng
[2 Apr 9:30]
MySQL Verification Team
Hello zhiqiang cheng, Thank you for the report and test case. regards, Umesh
[8 Apr 15:00]
huahua xu
Because of the predicate on the inner table that rejects null, the outer join is replaced by an inner join and pushdown the predicate condition to the hash join table. mysql> explain format=tree select -> ref_2.c2 as c_1, -> FIELD('I#', OCT(ref_2.c2)) = 0 as w_1 -> from -> (t1 as ref_1 -> left outer join t2 as ref_2 -> on (ref_1.c1 = ref_2.c2 )) -> where FIELD('I#', OCT(ref_2.c2)) = 0; +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | EXPLAIN | +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | -> Inner hash join (ref_2.c2 = ref_1.c1) (cost=0.8 rows=1) -> Table scan on ref_2 (cost=0.35 rows=2) -> Hash -> Filter: (field('I#',conv(ref_1.c1,10,8)) = 0) (cost=0.35 rows=1) -> Table scan on ref_1 (cost=0.35 rows=1) | +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ In the function `Item_func_field`, null_on_null should be set to false to prevent OUTER JOIN from being converted to a INNER JOIN.