Commit 1ee02f2c authored by Varun Gupta's avatar Varun Gupta

fixing sort_nest.test

parent f221f10a
This diff is collapsed.
This diff is collapsed.
--echo #
--echo # Testing SORT-NEST with non-flattened Subqueries
--echo #
--echo #
--echo # Dependent subquery attached to table t3 outside the sort-nest(t1,t2)
--echo #
set use_sort_nest=1;
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 a,a from t0 where a <5; # 5 rows
create table t2 as select * from t1 where a < 5; # 5 rows
create table t3(a int, b int, c int);
insert into t3 select A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a from t0 A, t0 B; # 100 rows
create table t4(a int, b int, c int, key(b));
insert into t4 select A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a from t0 A, t0 B; # 100 rows
--echo # ref access inside the dependent subquery should be with sort-nest.b instead of t1.b
--echo # subquery is attached to table t3 which is outside the sort-nest
let $query= SELECT * FROM t1,t2,t3
WHERE t1.b=t2.b and
EXISTS (select 1 from t4 where t4.b=t1.b and t4.b < 4 group by t4.c having t3.b=max(t4.a))
ORDER BY t2.a desc,t1.a desc
LIMIT 5;
eval EXPLAIN $query;
eval EXPLAIN FORMAT=JSON $query;
eval $query;
--echo # same as above but exists to in transformation not allowed
--echo # subquery is attached to table t3 which is outside the sort-nest
set optimizer_switch='exists_to_in=off';
eval EXPLAIN $query;
eval EXPLAIN FORMAT=JSON $query;
eval $query;
set optimizer_switch=default;
drop table t0,t1,t2,t3,t4;
--echo # DEPENDENT SUBQUERIES
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 a,a from t0 where a <5;
create table t2 as select * from t1 where a < 5;
create table t3 as select (A.a + 10*B.a+C.a*100) as a, (A.a + 10*B.a+C.a*100) as b,
(A.a + 10*B.a+C.a*100) as c from t0 A, t0 B,t0 C; # 1000 rows
set optimizer_switch='exists_to_in=off';
--echo # sort-nest(t2,t1) and subquery should be attached to table ot1
let $query= select * from t2,t1,t3
where exists (select max(t3.a) from t3 t4 where t4.b=t1.b group by t4.c having t3.a= max(t4.a))
order by t2.a desc,t1.a desc limit 5;
eval explain $query;
eval explain format=json $query;
eval $query;
set optimizer_switch=default;
--echo # sort-nest(t2,t1) and subquery should be attached to table ot1 (same as above)
let $query= select * from t2,t1,t3
where t3.a in (select max(t4.a) from t3 t4 where t4.b=t1.b group by t4.c)
order by t2.a desc,t1.a desc limit 5;
eval explain $query;
eval explain format=json $query;
eval $query;
--echo # sort-nest(t2,t1) and dependent subquery in the select list
let $query= select (select t4.a from t3 t4 where t4.a > t1.b limit 1) as x, t2.b, t1.b, t3.a from t1,t2,t3
where t1.a = t2.a order by t2.b desc, t1.b desc limit 5;
eval explain $query;
eval explain format=json $query;
eval $query;
--echo #
--echo # sort-nest(t2,t1) and sort-nest fields substitution in the having clause of the subquery
--echo # after IN -> EXISTS transformation
--echo #
let $query= select * from t2,t1,t3 ot1
where t2.a+ot1.a in (select max(t3.a) from t3 where t3.b=t1.b group by t3.c)
order by t2.a desc,t1.a desc limit 5;
eval explain $query;
eval explain format=json $query;
eval $query;
drop table t0,t1,t2,t3;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment