Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
12.1
-
None
-
Not for Release Notes
-
Q3/2025 Maintenance
Description
If in the query there is a checking for null of non-null column then it uses wrong query plan and returns wrong result.
In testcase below the query plan for oracle join ( + ) is like INNER JOIN, not LEFT JOIN:
Testcase:
create table t1 (a int default NULL); |
create table t2 (a int not null); |
insert into t1 values (1), (2), (3), (4), (5), (6), (NULL); |
insert into t2 values (1), (4), (5), (6), (7); |
|
select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; |
explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; |
|
select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; |
explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; |
|
select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1; |
explain extended select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1; |
|
drop table t1,t2; |
Results:
select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; |
a a
|
|
explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; |
id select_type table type possible_keys key key_len ref rows Extra |
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE |
select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; |
a a
|
2 NULL |
3 NULL |
NULL NULL |
explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; |
|
id select_type table type possible_keys key key_len ref rows Extra |
1 SIMPLE t1 ALL NULL NULL NULL NULL 7 |
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) |
select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1; |
a a
|
|
explain extended select t1.*,t2.* from t1,t2 where t1.a=t2.a(+) and isnull(t2.a)=1; |
id select_type table type possible_keys key key_len ref rows filtered Extra |
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE |
Warnings:
|
Note 1003 select "test"."t1"."a" AS "a","test"."t2"."a" AS "a" from "test"."t1" left join "test"."t2" on(multiple equal("test"."t1"."a", "test"."t2"."a")) where 0 |
Attachments
Issue Links
- is caused by
-
MDEV-13817 add support for oracle outer join syntax - the ( + )
-
- Closed
-
- is duplicated by
-
MDEV-36895 Oracle outer join syntax (+): some NULLs missing from result of the query with derived tables and limit
-
- Closed
-
- relates to
-
MDEV-36908 Oracle outer join syntax (+): query with condition IN and NOT IN (SELECT ...) (with view in defenition of subquery) has wrong query plan and returns wrong result
-
- Closed
-