diff options
Diffstat (limited to 'mysql-test/main/join_outer.test')
-rw-r--r-- | mysql-test/main/join_outer.test | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/mysql-test/main/join_outer.test b/mysql-test/main/join_outer.test index 6d20c089bd9..82127397bee 100644 --- a/mysql-test/main/join_outer.test +++ b/mysql-test/main/join_outer.test @@ -2042,4 +2042,64 @@ DROP TABLE t1,t2; --echo # end of 5.5 tests +--echo # +--echo # MDEV-17518: Range optimization doesn't use ON expressions from nested outer joins +--echo # +create table t1(a int); +insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t2(a int); +insert into t2 values (0),(1); + +create table t3 (a int, b int, key(a)); +insert into t3 select A.a + B.a* 10 + C.a * 100, 12345 from t1 A, t1 B, t1 C; + +--echo # Uses range for table t3: +explain select * from t1 left join t3 on t1.a=t3.b and t3.a<5; + +--echo # This must use range for table t3, too: +explain select * from t1 left join (t3 join t2) on t1.a=t3.b and t3.a<5; + +--echo # +--echo # .. part 2: make sure condition selectivity can use the condition too. +--echo # +alter table t3 drop key a; +set @tmp1=@@optimizer_use_condition_selectivity; +set @tmp2=@@use_stat_tables; +set @tmp3=@@histogram_size; +set use_stat_tables=preferably; +set optimizer_use_condition_selectivity=4; +set histogram_size=100; + +analyze table t3 persistent for all; + +--echo # t3.filtered is less than 100%: +explain extended select * from t1 left join t3 on t1.a=t3.b and t3.a<5; + +--echo # t3.filtered must less than 100%, too: +explain extended select * from t1 left join (t3 join t2) on t1.a=t3.b and t3.a<5; + +drop table t1,t2,t3; +set optimizer_use_condition_selectivity= @tmp1; +set use_stat_tables= @tmp2; +set histogram_size= @tmp3; + +--echo # Another test +CREATE TABLE t1 (i1 int) ; +CREATE TABLE t2 (pk int NOT NULL PRIMARY KEY) ; +CREATE TABLE t3 (pk int NOT NULL, i1 int, PRIMARY KEY (pk)) ; +INSERT INTO t3 VALUES (2, NULL); + +CREATE TABLE t4 (pk int NOT NULL, i1 int, PRIMARY KEY (pk), KEY i1 (i1)) ; +CREATE VIEW v4 AS SELECT * FROM t4; + +SELECT 1 +FROM t3 RIGHT JOIN t1 ON t3.i1 = t1.i1 + LEFT JOIN v4 + RIGHT JOIN t2 ON v4.i1 = t2.pk ON t1.i1 = t2.pk +WHERE t3.pk IN (2); + +drop view v4; +drop table t1,t2,t3,t4; + SET optimizer_switch=@save_optimizer_switch; |