diff options
Diffstat (limited to 'mysql-test/main/subselect4.result')
-rw-r--r-- | mysql-test/main/subselect4.result | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result index 05f65b4f550..783542c7dbf 100644 --- a/mysql-test/main/subselect4.result +++ b/mysql-test/main/subselect4.result @@ -2540,17 +2540,43 @@ drop table t1; 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); -insert into t1 select +insert into t1 select A.a + B.a*10, A.a + B.a*10 from t0 A, t0 B; create table t2 as select * from t1; -# This will not be able to convert to semi-join but will not require filesort: -explain -select * from t1 where exists (select * from t2 where t2.a=t1.a order by t2.b); +# This will be converted to semi-join: +explain +select * from t1 +where exists (select * from t2 where t2.a=t1.a order by t2.b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 100 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 100 +# query with a non-zero constant LIMIT is converted to semi-join, too: +explain +select * from t1 +where exists (select * from t2 where t2.a=t1.a order by t2.b limit 2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 100 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 100 +# Zero LIMIT should prevent the conversion (but it is not visible atm +# due to MDEV-19429) +explain +select * from t1 +where exists (select * from t2 where t2.a=t1.a order by t2.b limit 0); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL # Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 100 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 100 +# LIMIT+OFFSET prevents the conversion: +explain +select * from t1 +where exists (select * from t2 where t2.a=t1.a order by t2.b limit 2,3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 100 Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 100 Using where; Using filesort # This will be merged and converted into a semi-join: -explain +explain select * from t1 where t1.a in (select t2.a from t2 order by t2.b); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 100 |