summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/join_outer.result23
-rw-r--r--mysql-test/t/join_outer.test22
2 files changed, 45 insertions, 0 deletions
diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result
index 8b4ee17f20e..77932b65857 100644
--- a/mysql-test/r/join_outer.result
+++ b/mysql-test/r/join_outer.result
@@ -2337,4 +2337,27 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
Warnings:
Note 1003 select `test`.`t1`.`i1` AS `i1`,`test`.`t1`.`v1` AS `v1`,`test`.`t2`.`i2` AS `i2`,`test`.`t2`.`v2` AS `v2`,`test`.`t3`.`i3` AS `i3`,`test`.`t3`.`v3` AS `v3` from `test`.`t1` join `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`v3` = 4) and (`test`.`t1`.`i1` = `test`.`t3`.`i3`) and (`test`.`t2`.`i2` = `test`.`t3`.`i3`))
drop table t1,t2,t3;
+#
+# MDEV-8359: WHERE condition referring to inner table of left join can be sargable
+#
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t1 (a int, b int, key(a));
+insert into t1 select A.a+10*B.a+100*C.a, A.a+10*B.a+100*C.a from t0 A, t0 B, t0 C;
+create table t2 (a int, b int);
+insert into t2 select a,a from t0;
+# The following must remain an outer join
+# but it must be able to use range access on table t1:
+explain extended
+select *
+from
+t1 left join t2 on t2.a=t1.a
+where
+t1.a<3 or t2.a<4;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 SIMPLE t1 range a a 5 NULL 4 100.00 Using index condition
+1 SIMPLE t2 ALL NULL NULL NULL NULL 10 100.00 Using where
+Warnings:
+Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t1` left join `test`.`t2` on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where ((`test`.`t1`.`a` < 3) or (`test`.`t2`.`a` < 4))
+drop table t0,t1, t2;
SET optimizer_switch=@save_optimizer_switch;
diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test
index a3a1278ef1e..f0ecbe29149 100644
--- a/mysql-test/t/join_outer.test
+++ b/mysql-test/t/join_outer.test
@@ -1882,4 +1882,26 @@ WHERE v3 = 4;
drop table t1,t2,t3;
+--echo #
+--echo # MDEV-8359: WHERE condition referring to inner table of left join can be sargable
+--echo #
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+create table t1 (a int, b int, key(a));
+insert into t1 select A.a+10*B.a+100*C.a, A.a+10*B.a+100*C.a from t0 A, t0 B, t0 C;
+
+create table t2 (a int, b int);
+insert into t2 select a,a from t0;
+
+--echo # The following must remain an outer join
+--echo # but it must be able to use range access on table t1:
+explain extended
+select *
+from
+ t1 left join t2 on t2.a=t1.a
+where
+ t1.a<3 or t2.a<4;
+
+drop table t0,t1, t2;
SET optimizer_switch=@save_optimizer_switch;