init push
This commit is contained in:
@ -0,0 +1,379 @@
|
||||
drop database if exists bushy_leading_hint_db;
|
||||
create database bushy_leading_hint_db;
|
||||
use bushy_leading_hint_db;
|
||||
drop table if exists nn1;
|
||||
drop table if exists nn2;
|
||||
drop table if exists t1;
|
||||
drop table if exists t2;
|
||||
drop table if exists t3;
|
||||
create table nn1(c1 int, c2 int, c3 varchar(10));
|
||||
create table nn2(d1 int, d2 int, d3 varchar(10));
|
||||
create table t1(a int, b int, c int);
|
||||
create table t2(a int, b int, c int);
|
||||
create table t3(a int, b int, c int);
|
||||
### 1, 基本测试 ###
|
||||
select /*+ leading(c, (b , a) ) */ count(*),sum(a.c1+b.d2*a.c2) from nn1 a join nn2 b on a.c1 = b.d2 join nn1 c on b.d1 = c.c1 where a.c2 < 5 ;
|
||||
count(*) sum(a.c1+b.d2*a.c2)
|
||||
0 NULL
|
||||
select /*+ leading(c, (b , a) ) */ count(a.c1), sum(a.c2+b.d2) from nn1 a join nn2 b on a.c1 = b.d2 join nn1 c on c.c1 = b.d2 + 1 where a.c2 < 15 ;
|
||||
count(a.c1) sum(a.c2+b.d2)
|
||||
0 NULL
|
||||
select /*+ leading((c, d), (a , b) ) */ count(*),sum(a.c1),sum(b.d2) from nn1 a join nn2 b on a.c1 = b.d2
|
||||
join nn1 c on b.d1 = c.c1 join nn1 d on d.c2 = c.c2 where a.c2 < 5 ;
|
||||
count(*) sum(a.c1) sum(b.d2)
|
||||
0 NULL NULL
|
||||
select /*+ leading(c, d, (a , b)) */ count(*),sum(a.c1+b.d1+c.c1-d.c2) from
|
||||
nn1 a, nn2 b , nn1 c, nn1 d
|
||||
where a.c1 = b.d2 and b.d1 = c.c1 and d.c2 = c.c2;
|
||||
count(*) sum(a.c1+b.d1+c.c1-d.c2)
|
||||
0 NULL
|
||||
select /*+ leading(c, (a ,d, b) ) use_hash(c,d) */ count(a.c1),sum(b.d1*b.d2-a.c2) from nn1 a join nn2 b on a.c1 = b.d2
|
||||
join nn1 c on b.d1 = c.c1 join nn1 d on d.c2 = c.c2 where a.c2 < 5 and d.c1 = b.d2
|
||||
and d.c2 = a.c1 ;
|
||||
count(a.c1) sum(b.d1*b.d2-a.c2)
|
||||
0 NULL
|
||||
select /*+ leading(c, (d, b) ) */ count(*)
|
||||
from nn2 b, nn1 c, nn1 d
|
||||
where b.d1 = c.c1 and d.c2 = c.c2 and d.c1 = b.d2;
|
||||
count(*)
|
||||
0
|
||||
select /*+ leading(t2, (t1, t3), t7, (t8, t9), (t4, t5, t6)) */
|
||||
count(*) from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c1 and t8.c1 = t9.c1 and t8.c1 = t2.c1 and t1.c1 = t9.c1
|
||||
and t1.c3 = 'hello11' and t2.c2 < 4 ;
|
||||
count(*)
|
||||
0
|
||||
select /*+ leading(t1,t2,t3,(t4,t5,t6),(t7,t8)) */ count(*),sum(t1.c1+t2.d1+t3.c1+t4.d2-t5.c1+t6.d2-t7.c1-t8.d2)
|
||||
from nn1 t1, nn2 t2, nn1 t3, nn2 t4, nn1 t5 , nn2 t6, nn1 t7, nn2 t8
|
||||
where t1.c1 = t2.d1 and t1.c2 = t3.c1 and
|
||||
t4.d1 = t1.c1 and t5.c1 = t2.d2 and t6.d2 = t3.c1 AND
|
||||
t7.c1 = t2.d1 and t7.c2 = t5.c1 and t8.d1 = t4.d2 and t8.d2 = t6.d2;
|
||||
count(*) sum(t1.c1+t2.d1+t3.c1+t4.d2-t5.c1+t6.d2-t7.c1-t8.d2)
|
||||
0 NULL
|
||||
select /*+ leading(c, (d, (a,b))) */ count(a.c1+b.d2+a.c2) from nn1 a join nn2 b on a.c1 = b.d2
|
||||
join nn1 c on b.d1 = c.c1 join nn1 d on d.c2 = c.c2 where a.c2 < 5 ;
|
||||
count(a.c1+b.d2+a.c2)
|
||||
0
|
||||
select /*+ leading(t2, (t1, (t3 , (t7, (t8, (t9 , (t4, (t5, (t6))))))))) */
|
||||
count(*),sum(t1.c1+t2.c1+t3.c1+t4.c2-t5.c1+t6.c2-t7.c1-t8.c2)+count(t9.c1)
|
||||
from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c1 and t8.c1 = t9.c1 and t8.c1 = t2.c1 and t1.c1 = t9.c1;
|
||||
count(*) sum(t1.c1+t2.c1+t3.c1+t4.c2-t5.c1+t6.c2-t7.c1-t8.c2)+count(t9.c1)
|
||||
0 NULL
|
||||
select /*+ leading(t1, ((t2, t3), t4), (t5, t6)) */ count(t1.c1), count(t2.d1 * t3.c1), sum(t4.d1 + t5.c1)
|
||||
from nn1 t1, nn2 t2, nn1 t3, nn2 t4, nn1 t5, nn2 t6
|
||||
where t1.c1 = t2.d1 and t1.c2 = t3.c1 and t1.c1 + t2.d2 = t4.d1 + t1.c2 and
|
||||
t4.d1 = t5.c1 + t6.d2 and t2.d2 = t5.c1 and t2.d1 = t6.d2 and
|
||||
t1.c1 + t4.d2 = t5.c2 + t6.d2 - 1;
|
||||
count(t1.c1) count(t2.d1 * t3.c1) sum(t4.d1 + t5.c1)
|
||||
0 0 NULL
|
||||
select /*+ leading(t1, ((t2, t3), t4)) */ count(*), sum(t2.d1 * t3.c1 - t4.d2)
|
||||
from nn1 t1, nn2 t2, nn1 t3, nn2 t4
|
||||
where t1.c1 = t2.d1 and t1.c2 = t3.c1 and t1.c1 + t2.d2 = t4.d1 + t1.c2;
|
||||
count(*) sum(t2.d1 * t3.c1 - t4.d2)
|
||||
0 NULL
|
||||
select /*+ leading(t1, (t2, t3)) */ count(*), sum(t2.d1+t3.c2)
|
||||
from nn1 t1, nn2 t2, nn1 t3
|
||||
where t1.c1 = t2.d1 and t1.c2 = t3.c1 and t1.c1 =t3.c1+t2.d2;
|
||||
count(*) sum(t2.d1+t3.c2)
|
||||
0 NULL
|
||||
### 3, 复杂测试(集合、子查询中等) ###
|
||||
SELECT count(*), sum(b.d1) from
|
||||
nn1 a, nn2 b, nn1 c
|
||||
WHERE
|
||||
a.c1 = b.d1 and b.d2 = c.c1 and c.c2 in (
|
||||
select
|
||||
/*+ leading(x, ((y, z), x2, (y2,y3))) no_use_hash(y2, y3) */
|
||||
x.c1
|
||||
from nn1 x, nn2 y, nn1 z, nn1 x2, nn1 y2, nn1 y3
|
||||
where x.c2 = y.d2 and y.d1 = z.c2 and y2.c1 = y3.c1
|
||||
);
|
||||
count(*) sum(b.d1)
|
||||
0 NULL
|
||||
select /*+ leading(t6, (t5, t4), (t3, t1), (t2)) */ count(*), sum(t2.c1) from nn1 t1, nn1 t2 , nn1 t3, nn1 t4, nn1 t5, nn1 t6
|
||||
where t1.c1 = t2.c1 and t2.c2 = t3.c1 and t3.c2 = t4.c1 and t4.c2 = t5.c1 and t5.c2 = t6.c1 and t5.c2 <> 44
|
||||
union ALL
|
||||
select /* leading(t2, t1, (t4, t3, (t6, t5))) */ sum(t1.c1), max(t2.c2)+sum(t5.c1-t6.c2) from nn1 t1, nn1 t2 , nn1 t3, nn1 t4, nn1 t5, nn1 t6
|
||||
where t1.c1 = t2.c1 and t2.c2 = t3.c1 and t3.c2 = t4.c1 and t4.c2 = t5.c1 and t5.c2 = t6.c1 and t5.c2 <> 55;
|
||||
count(*) sum(t2.c1)
|
||||
0 NULL
|
||||
NULL NULL
|
||||
select /*+ leading(t9, (t8, t7, (t6, t5), t4), (t3, t1), t2)*/ count(*),sum(t9.c1-t5.c1+t4.d2-t1.c1) from
|
||||
nn1 t1, nn2 t2, nn1 t3, nn2 t4, nn1 t5, nn2 t6, nn1 t7, nn2 t8, nn1 t9
|
||||
where mod(t1.c1, 3) = mod(t2.d2,2) and mod(t1.c1,5) = mod(t3.c1,4) and mod(t1.c2, 7) = mod(t4.d1, 3) AND
|
||||
mod(t1.c2, 5) = mod(t5.c1, 6) and mod(t1.c1, 3) = mod(t6.d2, 2) and mod(t1.c1, 4) = mod(t7.c1,3) AND
|
||||
mod(t1.c1, 7) = mod(t8.d1, 3) and mod(t1.c2, 5) = mod(t9.c1, 4) AND
|
||||
mod(t2.d1,5) = mod(t3.c1,4) and mod(t2.d2, 7) = mod(t4.d1, 3) AND
|
||||
mod(t2.d2, 5) = mod(t5.c1, 6) and mod(t2.d1, 3) = mod(t6.d2, 2) and mod(t2.d1, 4) = mod(t7.c1,3) AND
|
||||
mod(t2.d1, 7) = mod(t8.d1, 3) and mod(t2.d2, 5) = mod(t9.c1, 4) AND
|
||||
mod(t3.c2, 7) = mod(t4.d1, 3) AND
|
||||
mod(t3.c2, 5) = mod(t5.c1, 6) and mod(t3.c1, 3) = mod(t6.d2, 2) and mod(t3.c1, 4) = mod(t7.c1,3) AND
|
||||
mod(t3.c1, 7) = mod(t8.d1, 3) and mod(t3.c2, 5) = mod(t9.c1, 4) AND
|
||||
mod(t4.d2, 5) = mod(t5.c1, 6) and mod(t4.d1, 3) = mod(t6.d2, 2) and mod(t4.d1, 4) = mod(t7.c1,3) AND
|
||||
mod(t4.d1, 7) = mod(t8.d1, 3) and mod(t4.d2, 5) = mod(t9.c1, 4) and
|
||||
mod(t5.c1, 2) = mod(t6.d2, 5) and mod(t5.c1, 4) = mod(t7.c1,1) AND
|
||||
mod(t5.c1, 7) = mod(t8.d1, 6) and mod(t5.c2, 5) = mod(t9.c1, 4) AND
|
||||
mod(t6.d1, 4) = mod(t7.c1,3) AND
|
||||
mod(t6.d1, 7) = mod(t8.d1, 3) and mod(t6.d2, 5) = mod(t9.c1, 4) AND
|
||||
mod(t7.c1, 7) = mod(t8.d1, 3) and mod(t7.c2, 5) = mod(t9.c1, 4) AND
|
||||
mod(t8.d2, 5) = mod(t9.c1, 14) ;
|
||||
count(*) sum(t9.c1-t5.c1+t4.d2-t1.c1)
|
||||
0 NULL
|
||||
select /*+ leading(a (c ,(b, d))) */ count(*),sum(a.c1) from nn1 a, (select * from nn2) b,
|
||||
(select * from nn1 cc group by c1,c2) c, nn2 d
|
||||
where a.c1 = c.c1 and b.d2 = d.d1 and c.c2 = d.d2;
|
||||
count(*) sum(a.c1)
|
||||
0 NULL
|
||||
select /*+ leading(a (c ,(b, d))) */count(*), sum(b.d2) from nn1 a left join nn2 b
|
||||
on a.c1 = b.d1 left join nn1 c on b.d2 = c.c1 left join nn2 d on c.c2 = d.d2
|
||||
where a.c1 = b.d1 and b.d2 = c.c1 and c.c2 = d.d2;
|
||||
count(*) sum(b.d2)
|
||||
0 NULL
|
||||
select (select /*+ leading(a (c ,(b, d))) */ count(x.c2) from nn1 a left join nn2 b
|
||||
on a.c1 = b.d1 left join nn1 c on b.d2 = c.c1 left join nn2 d on c.c2 = d.d2
|
||||
where a.c1 = b.d1 and b.d2 = c.c1 and c.c2 = d.d2 and x.c1 = a.c1 + b.d1 + c.c2 - d.d2 * 5) as x
|
||||
from nn1 x;
|
||||
x
|
||||
NULL
|
||||
select /* leading(t3 (t2 t1)) */ sum(t1.c1) from nn1 t1 , nn1 t2 , nn1 t3 where t2.c2=t1.c2 and t1.c1 =
|
||||
(select /*+ leading(x,(y z)) */ count(*) from nn1 x, nn2 y, nn1 z where x.c1 = y.d1 and y.d2 = z.c1)
|
||||
and t3.c1 in (1,2);
|
||||
sum(t1.c1)
|
||||
NULL
|
||||
### 4, 错误、无效或冗余的指定测试 ###
|
||||
select /*+ leading((d, c), b , a) */ count(*), sum(b.d1+d.d2) from nn1 a, nn2 b, nn1 c, nn2 d
|
||||
where a.c1 = b.d1 and c.c2 = d.d1;
|
||||
count(*) sum(b.d1+d.d2)
|
||||
0 NULL
|
||||
select /*+ leading((d, (c), (b)) , (a)) */ count(*),sum(a.c1+b.d2+c.c1+d.d2) from nn1 a, nn2 b, nn1 c, nn2 d
|
||||
where a.c1 = b.d2 and c.c2 = d.d2;
|
||||
count(*) sum(a.c1+b.d2+c.c1+d.d2)
|
||||
0 NULL
|
||||
select /*+ leading(b, (c d)) a) */ count(*), sum(b.d1+d.d2) from nn1 a, nn2 b, nn1 c, nn2 d
|
||||
where a.c1 = b.d1 and c.c2 = d.d1;
|
||||
count(*) sum(b.d1+d.d2)
|
||||
0 NULL
|
||||
select /*+ leading(b1, (c1 d1 ) a1) */ count(*), sum(b.d2+d.d1*c.c1-a.c1) from nn1 a, nn2 b, nn1 c, nn2 d
|
||||
where a.c1 = b.d1 and c.c2 = d.d1;
|
||||
count(*) sum(b.d2+d.d1*c.c1-a.c1)
|
||||
0 NULL
|
||||
select /*+ leading((((t2,t1,t4),t3),t5), (t6),(t7))*/ count(*), sum(t6.c1+t7.c1+t4.c2) from
|
||||
nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6, nn1 t7
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1;
|
||||
count(*) sum(t6.c1+t7.c1+t4.c2)
|
||||
0 NULL
|
||||
select /*+ leading(t4,t6,t5) */ count(*), sum(t2.c2+t3.c1)
|
||||
from nn1 t1 left join nn1 t2 on t1.c1 = t2.c1 left JOIN
|
||||
nn1 t3 on t3.c2 IN(1,23,4,2,5,6) join nn1 t4 on t3.c1=t4.c1 join nn1 t5 on t4.c2=t5.c2
|
||||
join nn1 t6 on t5.c1 = t6.c2 left join nn1 t7 on t1.c1=t7.c1;
|
||||
count(*) sum(t2.c2+t3.c1)
|
||||
0 NULL
|
||||
### 6, 嵌套hint和hint的print测试 ###
|
||||
select /*+ leading(c, (a ,(d, b)) ) */ count(a.c1+b.d2) , sum(b.d2+b.d2*a.c1) from nn1 a join nn2 b on a.c1 = b.d2
|
||||
join nn1 c on b.d1 = c.c1 join nn1 d on d.c2 = c.c2 where a.c2 < 5 and d.c1 = b.d2
|
||||
and d.c2 = a.c1 ;
|
||||
count(a.c1+b.d2) sum(b.d2+b.d2*a.c1)
|
||||
0 NULL
|
||||
create view v1 as select /*+ leading(c, b , a ) use_hash(b a) */ a.c1 as a_c1, a.c2 as a_c2, a.c3 as a_c3, b.d1, b.d2, b.d3, c.c1 as c_c1, c.c2 as c_c2, c.c3 as c_c3 from nn1 a join nn2 b on a.c1 = b.d2 join nn1 c on b.d1 = c.c1 where a.c2 < 5;
|
||||
show create view v1;
|
||||
View Create View character_set_client collation_connection
|
||||
v1 CREATE VIEW `v1` AS select /*+ LEADING(c b a) USE_HASH((b) (a)) */`bushy_leading_hint_db`.`a`.`c1` AS `a_c1`,`bushy_leading_hint_db`.`a`.`c2` AS `a_c2`,`bushy_leading_hint_db`.`a`.`c3` AS `a_c3`,`bushy_leading_hint_db`.`b`.`d1` AS `d1`,`bushy_leading_hint_db`.`b`.`d2` AS `d2`,`bushy_leading_hint_db`.`b`.`d3` AS `d3`,`bushy_leading_hint_db`.`c`.`c1` AS `c_c1`,`bushy_leading_hint_db`.`c`.`c2` AS `c_c2`,`bushy_leading_hint_db`.`c`.`c3` AS `c_c3` from ((`bushy_leading_hint_db`.`nn1` `a` join `bushy_leading_hint_db`.`nn2` `b` on ((`bushy_leading_hint_db`.`a`.`c1` = `bushy_leading_hint_db`.`b`.`d2`))) join `bushy_leading_hint_db`.`nn1` `c` on ((`bushy_leading_hint_db`.`b`.`d1` = `bushy_leading_hint_db`.`c`.`c1`))) where (`bushy_leading_hint_db`.`a`.`c2` < 5) utf8mb4 utf8mb4_general_ci
|
||||
create view v2 as select /*+ leading(c, (b , a)) */ a.c1 as a_c1, a.c2 as a_c2, a.c3 as a_c3, b.d1, b.d2, b.d3, c.c1 as c_c1, c.c2 as c_c2, c.c3 as c_c3 from nn1 a join nn2 b on a.c1 = b.d2 join nn1 c on b.d1 = c.c1 where a.c2 < 5 ;
|
||||
show create view v2;
|
||||
View Create View character_set_client collation_connection
|
||||
v2 CREATE VIEW `v2` AS select /*+ LEADING(c (b a)) */`bushy_leading_hint_db`.`a`.`c1` AS `a_c1`,`bushy_leading_hint_db`.`a`.`c2` AS `a_c2`,`bushy_leading_hint_db`.`a`.`c3` AS `a_c3`,`bushy_leading_hint_db`.`b`.`d1` AS `d1`,`bushy_leading_hint_db`.`b`.`d2` AS `d2`,`bushy_leading_hint_db`.`b`.`d3` AS `d3`,`bushy_leading_hint_db`.`c`.`c1` AS `c_c1`,`bushy_leading_hint_db`.`c`.`c2` AS `c_c2`,`bushy_leading_hint_db`.`c`.`c3` AS `c_c3` from ((`bushy_leading_hint_db`.`nn1` `a` join `bushy_leading_hint_db`.`nn2` `b` on ((`bushy_leading_hint_db`.`a`.`c1` = `bushy_leading_hint_db`.`b`.`d2`))) join `bushy_leading_hint_db`.`nn1` `c` on ((`bushy_leading_hint_db`.`b`.`d1` = `bushy_leading_hint_db`.`c`.`c1`))) where (`bushy_leading_hint_db`.`a`.`c2` < 5) utf8mb4 utf8mb4_general_ci
|
||||
create view v3 as select /*+ leading(c, (d, (a,b))) */ a.c1 as a_c1, a.c2 as a_c2, a.c3 as a_c3, b.d1, b.d2, b.d3, c.c1 as c_c1, c.c2 as c_c2, c.c3 as c_c3 from nn1 a join nn2 b
|
||||
on a.c1 = b.d2
|
||||
join nn1 c on b.d1 = c.c1 join nn1 d on d.c2 = c.c2 where a.c2 < 5 ;
|
||||
show create view v3;
|
||||
View Create View character_set_client collation_connection
|
||||
v3 CREATE VIEW `v3` AS select /*+ LEADING(c (d (a b))) */`bushy_leading_hint_db`.`a`.`c1` AS `a_c1`,`bushy_leading_hint_db`.`a`.`c2` AS `a_c2`,`bushy_leading_hint_db`.`a`.`c3` AS `a_c3`,`bushy_leading_hint_db`.`b`.`d1` AS `d1`,`bushy_leading_hint_db`.`b`.`d2` AS `d2`,`bushy_leading_hint_db`.`b`.`d3` AS `d3`,`bushy_leading_hint_db`.`c`.`c1` AS `c_c1`,`bushy_leading_hint_db`.`c`.`c2` AS `c_c2`,`bushy_leading_hint_db`.`c`.`c3` AS `c_c3` from (((`bushy_leading_hint_db`.`nn1` `a` join `bushy_leading_hint_db`.`nn2` `b` on ((`bushy_leading_hint_db`.`a`.`c1` = `bushy_leading_hint_db`.`b`.`d2`))) join `bushy_leading_hint_db`.`nn1` `c` on ((`bushy_leading_hint_db`.`b`.`d1` = `bushy_leading_hint_db`.`c`.`c1`))) join `bushy_leading_hint_db`.`nn1` `d` on ((`bushy_leading_hint_db`.`d`.`c2` = `bushy_leading_hint_db`.`c`.`c2`))) where (`bushy_leading_hint_db`.`a`.`c2` < 5) utf8mb4 utf8mb4_general_ci
|
||||
create view v4 as
|
||||
select /*+ leading(t2, (t1, t3), (t7, (t8, t9)), (t4, t5, t6)) */
|
||||
t1.c1 as x, t3.c2 as y, t5.c2 as z from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c1 and t8.c1 = t9.c1 and t8.c1 = t2.c1 and t1.c1 = t9.c1;
|
||||
show create view v4;
|
||||
View Create View character_set_client collation_connection
|
||||
v4 CREATE VIEW `v4` AS select /*+ LEADING(t2 (t1 t3) (t7 (t8 t9)) (t4 t5 t6)) */`bushy_leading_hint_db`.`t1`.`c1` AS `x`,`bushy_leading_hint_db`.`t3`.`c2` AS `y`,`bushy_leading_hint_db`.`t5`.`c2` AS `z` from `bushy_leading_hint_db`.`nn1` `t1`,`bushy_leading_hint_db`.`nn1` `t2`,`bushy_leading_hint_db`.`nn1` `t3`,`bushy_leading_hint_db`.`nn1` `t4`,`bushy_leading_hint_db`.`nn1` `t5`,`bushy_leading_hint_db`.`nn1` `t6`,`bushy_leading_hint_db`.`nn1` `t7`,`bushy_leading_hint_db`.`nn1` `t8`,`bushy_leading_hint_db`.`nn1` `t9` where (`bushy_leading_hint_db`.`t1`.`c1` = `bushy_leading_hint_db`.`t2`.`c1`) and (`bushy_leading_hint_db`.`t1`.`c1` = `bushy_leading_hint_db`.`t3`.`c2`) and (`bushy_leading_hint_db`.`t2`.`c1` = `bushy_leading_hint_db`.`t3`.`c1`) and (`bushy_leading_hint_db`.`t3`.`c1` = `bushy_leading_hint_db`.`t4`.`c1`) and (`bushy_leading_hint_db`.`t4`.`c1` = `bushy_leading_hint_db`.`t5`.`c1`) and (`bushy_leading_hint_db`.`t5`.`c1` = `bushy_leading_hint_db`.`t6`.`c1`) and (`bushy_leading_hint_db`.`t6`.`c1` = `bushy_leading_hint_db`.`t7`.`c1`) and (`bushy_leading_hint_db`.`t7`.`c1` = `bushy_leading_hint_db`.`t8`.`c1`) and (`bushy_leading_hint_db`.`t8`.`c1` = `bushy_leading_hint_db`.`t9`.`c1`) and (`bushy_leading_hint_db`.`t8`.`c1` = `bushy_leading_hint_db`.`t2`.`c1`) and (`bushy_leading_hint_db`.`t1`.`c1` = `bushy_leading_hint_db`.`t9`.`c1`) utf8mb4 utf8mb4_general_ci
|
||||
select count(*), sum(x+y-z*4) from v4;
|
||||
count(*) sum(x+y-z*4)
|
||||
0 NULL
|
||||
select /*+ leading(t2, (t1, t3), (t7, (t8, t9))) */
|
||||
count(*)+sum(t1.c1+t4.c2+t5.c1+t5.c2-5*t9.c1) from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c1 and t8.c1 = t9.c1 and t8.c1 = t2.c1 and t1.c1 = t9.c1;
|
||||
count(*)+sum(t1.c1+t4.c2+t5.c1+t5.c2-5*t9.c1)
|
||||
NULL
|
||||
select /*+ leading(t2, t1, t3, (t4, (t5, t6)), (t8, (t9, t7))) */
|
||||
count(*), sum(t1.c1+t5.c1+t6.c1-t7.c1-t8.c2*t9.c1) from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 >= t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c2 and t8.c2 = t9.c1 and t8.c1 <= t2.c1 and t1.c1 = t9.c1;
|
||||
count(*) sum(t1.c1+t5.c1+t6.c1-t7.c1-t8.c2*t9.c1)
|
||||
0 NULL
|
||||
select /*+ leading(t2, (t1, t3), (t7, t8, t9), (t4, t5, t6)) */
|
||||
count(*), sum(t1.c1-t7.c2-t8.c1-t9.c2) from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c1 and t8.c1 = t9.c1 and t8.c1 = t2.c1 and t1.c1 = t9.c1;
|
||||
count(*) sum(t1.c1-t7.c2-t8.c1-t9.c2)
|
||||
0 NULL
|
||||
select /*+ leading(t1, (t2 t3), (t4, t5 (t6, t7))) use_hash(t4, t5) use_hash(t6,t7) */
|
||||
count(*), sum(t1.c1-t5.c2+t6.c1) - max(t2.c1*t8.c2) from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c1 and t8.c1 = t9.c1 and t8.c1 = t2.c1 and t1.c1 = t9.c1;
|
||||
count(*) sum(t1.c1-t5.c2+t6.c1) - max(t2.c1*t8.c2)
|
||||
0 NULL
|
||||
select /*+ leading(t2 (t7, t1 (t8, t9))) */
|
||||
count(*) , sum(t1.c1+t5.c1+t8.c2*t9.c1-t3.c1*4) from nn1 t1, nn1 t2, nn1 t3, nn1 t4, nn1 t5, nn1 t6 , nn1 t7, nn1 t8, nn1 t9
|
||||
where t1.c1 = t2.c1 and t1.c1=t3.c2 and t2.c1 = t3.c1 and t3.c1 = t4.c1 and t4.c1 = t5.c1 and t5.c1 = t6.c1 AND
|
||||
t6.c1 = t7.c1 and t7.c1 = t8.c1 and t8.c1 = t9.c1 and t8.c1 = t2.c1 and t1.c1 = t9.c1;
|
||||
count(*) sum(t1.c1+t5.c1+t8.c2*t9.c1-t3.c1*4)
|
||||
0 NULL
|
||||
select /*+ leading(t1,t4,(t2,t3)) */
|
||||
count(*), sum(t1.c1)-sum(t4.c2) from nn1 t1, nn1 t2, nn1 t3, nn1 t4
|
||||
where t1.c1 = t2.c1 and t3.c1 = t4.c1 and t1.c2 = t3.c2;
|
||||
count(*) sum(t1.c1)-sum(t4.c2)
|
||||
0 NULL
|
||||
### 7, 带qb_name的测试 ###
|
||||
select /*+ LEADING(@x2x (c d), (a b)) */
|
||||
* from nn1 x
|
||||
where exists (select /*+ qb_name(x2x) */ 1
|
||||
from nn1 a, nn2 b, nn1 c, nn2 d where a.c1 = b.d1
|
||||
and c.c2 = d.d1) order by x.c1 asc, x.c2 asc, x.c3 desc;
|
||||
c1 c2 c3
|
||||
select /*+ LEADING(@x2x (c d), (a b)) */
|
||||
* from nn1 x
|
||||
where exists (select /*+ qb_name(x2x) LEADING(a c b d)*/ 1
|
||||
from nn1 a, nn2 b, nn1 c, nn2 d where a.c1 = b.d1
|
||||
and c.c2 = d.d1) order by x.c1 desc, x.c2 asc, x.c3 desc;
|
||||
c1 c2 c3
|
||||
select /*+ LEADING(@x3x b d (a c)) */
|
||||
* from nn1 x
|
||||
where exists (select /*+ qb_name(x3x) */ 1
|
||||
from nn1 a, nn2 b, nn1 c, nn2 d where a.c1 = b.d1
|
||||
and c.c2 = d.d1) order by x.c1 desc, x.c3 desc, x.c2 asc ;
|
||||
c1 c2 c3
|
||||
### 8, 通过bushy 扩展能获取较好的计划 ###
|
||||
select /*+ leading(t1,t2,(t4,t5))*/ count(*),min(t2.c1)+max(t5.d2) from nn1 t1, nn1 t2, nn2 t4, nn2 t5
|
||||
where t1.c1 = t2.c1 and
|
||||
t4.d1 = t5.d1 AND
|
||||
t1.c1 + t2.c1 = t4.d1 + t5.d2 ;
|
||||
count(*) min(t2.c1)+max(t5.d2)
|
||||
0 NULL
|
||||
explain select /*+leading(t1 (t2 t3))*/* from t1,t3 where t1.a = t3.a and t1.b not in (select b from t2);
|
||||
Query Plan
|
||||
=====================================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST |
|
||||
-----------------------------------------------------
|
||||
|0 |HASH JOIN | |960597 |2820926886|
|
||||
|1 | NESTED-LOOP ANTI JOIN| |981 |2820256644|
|
||||
|2 | TABLE SCAN |t1 |100000 |66272 |
|
||||
|3 | MATERIAL | |100000 |80235 |
|
||||
|4 | TABLE SCAN |t2 |100000 |61860 |
|
||||
|5 | TABLE SCAN |t3 |100000 |66272 |
|
||||
=====================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.a], [t1.b], [t1.c], [t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
equal_conds([t1.a = t3.a]), other_conds(nil)
|
||||
1 - output([t1.a], [t1.b], [t1.c]), filter(nil),
|
||||
conds([(T_OP_OR, t1.b = t2.b, (T_OP_IS, t1.b, NULL, 0), (T_OP_IS, t2.b, NULL, 0))]), nl_params_(nil)
|
||||
2 - output([t1.a], [t1.b], [t1.c]), filter(nil),
|
||||
access([t1.a], [t1.b], [t1.c]), partitions(p0)
|
||||
3 - output([t2.b]), filter(nil)
|
||||
4 - output([t2.b]), filter(nil),
|
||||
access([t2.b]), partitions(p0)
|
||||
5 - output([t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
access([t3.a], [t3.b], [t3.c]), partitions(p0)
|
||||
|
||||
explain select /*+leading(t2 t3 t1)*/* from t1,t3 where t1.a = t3.a and t1.b not in (select b from t2);
|
||||
Query Plan
|
||||
=====================================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST |
|
||||
-----------------------------------------------------
|
||||
|0 |HASH JOIN | |960597 |2820926886|
|
||||
|1 | NESTED-LOOP ANTI JOIN| |981 |2820256644|
|
||||
|2 | TABLE SCAN |t1 |100000 |66272 |
|
||||
|3 | MATERIAL | |100000 |80235 |
|
||||
|4 | TABLE SCAN |t2 |100000 |61860 |
|
||||
|5 | TABLE SCAN |t3 |100000 |66272 |
|
||||
=====================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.a], [t1.b], [t1.c], [t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
equal_conds([t1.a = t3.a]), other_conds(nil)
|
||||
1 - output([t1.a], [t1.b], [t1.c]), filter(nil),
|
||||
conds([(T_OP_OR, t1.b = t2.b, (T_OP_IS, t1.b, NULL, 0), (T_OP_IS, t2.b, NULL, 0))]), nl_params_(nil)
|
||||
2 - output([t1.a], [t1.b], [t1.c]), filter(nil),
|
||||
access([t1.a], [t1.b], [t1.c]), partitions(p0)
|
||||
3 - output([t2.b]), filter(nil)
|
||||
4 - output([t2.b]), filter(nil),
|
||||
access([t2.b]), partitions(p0)
|
||||
5 - output([t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
access([t3.a], [t3.b], [t3.c]), partitions(p0)
|
||||
|
||||
explain select /*+leading(t3 t1 t2)*/* from t1,t3 where t1.a = t3.a and t1.b not in (select b from t2);
|
||||
Query Plan
|
||||
=======================================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST |
|
||||
-------------------------------------------------------
|
||||
|0 |NESTED-LOOP ANTI JOIN| |960597 |2.764048e+12 |
|
||||
|1 | HASH JOIN | |98010000 |58439627 |
|
||||
|2 | TABLE SCAN |t3 |100000 |66272 |
|
||||
|3 | TABLE SCAN |t1 |100000 |66272 |
|
||||
|4 | MATERIAL | |100000 |80235 |
|
||||
|5 | TABLE SCAN |t2 |100000 |61860 |
|
||||
=======================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.a], [t1.b], [t1.c], [t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
conds([(T_OP_OR, t1.b = t2.b, (T_OP_IS, t1.b, NULL, 0), (T_OP_IS, t2.b, NULL, 0))]), nl_params_(nil)
|
||||
1 - output([t1.a], [t1.b], [t1.c], [t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
equal_conds([t1.a = t3.a]), other_conds(nil)
|
||||
2 - output([t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
access([t3.a], [t3.b], [t3.c]), partitions(p0)
|
||||
3 - output([t1.a], [t1.b], [t1.c]), filter(nil),
|
||||
access([t1.a], [t1.b], [t1.c]), partitions(p0)
|
||||
4 - output([t2.b]), filter(nil)
|
||||
5 - output([t2.b]), filter(nil),
|
||||
access([t2.b]), partitions(p0)
|
||||
|
||||
explain select /*+leading(t1 t2 t3)*/* from t1,t3 where t1.a = t3.a and t1.b not in (select b from t2);
|
||||
Query Plan
|
||||
=====================================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST |
|
||||
-----------------------------------------------------
|
||||
|0 |HASH JOIN | |960597 |2820926886|
|
||||
|1 | NESTED-LOOP ANTI JOIN| |981 |2820256644|
|
||||
|2 | TABLE SCAN |t1 |100000 |66272 |
|
||||
|3 | MATERIAL | |100000 |80235 |
|
||||
|4 | TABLE SCAN |t2 |100000 |61860 |
|
||||
|5 | TABLE SCAN |t3 |100000 |66272 |
|
||||
=====================================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.a], [t1.b], [t1.c], [t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
equal_conds([t1.a = t3.a]), other_conds(nil)
|
||||
1 - output([t1.a], [t1.b], [t1.c]), filter(nil),
|
||||
conds([(T_OP_OR, t1.b = t2.b, (T_OP_IS, t1.b, NULL, 0), (T_OP_IS, t2.b, NULL, 0))]), nl_params_(nil)
|
||||
2 - output([t1.a], [t1.b], [t1.c]), filter(nil),
|
||||
access([t1.a], [t1.b], [t1.c]), partitions(p0)
|
||||
3 - output([t2.b]), filter(nil)
|
||||
4 - output([t2.b]), filter(nil),
|
||||
access([t2.b]), partitions(p0)
|
||||
5 - output([t3.a], [t3.b], [t3.c]), filter(nil),
|
||||
access([t3.a], [t3.b], [t3.c]), partitions(p0)
|
||||
|
||||
drop table nn1;
|
||||
drop table nn2;
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
drop table t3;
|
||||
drop database bushy_leading_hint_db;
|
||||
@ -0,0 +1,381 @@
|
||||
drop table if exists t1, t2, t3;
|
||||
create table t1(c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 int, c8 int, c9 int, c10 int,
|
||||
index k1(c1),
|
||||
index k2(c1,c2),
|
||||
index k3(c1,c2,c3),
|
||||
index k4(c1,c2,c3,c4),
|
||||
index k5(c1,c2,c3,c4,c5));
|
||||
create table t2(c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 int, c8 int, c9 int, c10 int,
|
||||
primary key(c1, c6, c7),
|
||||
index k1(c1),
|
||||
index k2(c1,c2),
|
||||
index k3(c1,c2,c3),
|
||||
index k4(c1,c2,c3,c4),
|
||||
index k5(c1,c2,c3,c4,c5));
|
||||
create table t3(c1 int, c2 int, c3 int, c4 int, c5 int, c6 int, c7 int, c8 int, c9 int, c10 int,
|
||||
primary key(c1, c2, c6),
|
||||
index k1(c1),
|
||||
index k2(c1,c2),
|
||||
index k3(c1,c2,c3),
|
||||
index k4(c1,c2,c3,c4),
|
||||
index k5(c1,c2,c3,c4,c5));
|
||||
explain select count(*) from t1;
|
||||
Query Plan
|
||||
===========================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
-------------------------------------------
|
||||
|0 |SCALAR GROUP BY| |1 |43045|
|
||||
|1 | TABLE SCAN |t1(k1)|100000 |23944|
|
||||
===========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([T_FUN_COUNT(*)]), filter(nil),
|
||||
group(nil), agg_func([T_FUN_COUNT(*)])
|
||||
1 - output([1]), filter(nil),
|
||||
access([t1.c1]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 = 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t1(k1)|990 |6209|
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 < 1;
|
||||
Query Plan
|
||||
======================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
--------------------------------------
|
||||
|0 |TABLE SCAN|t1(k1)|10000 |62113|
|
||||
======================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 > 1;
|
||||
Query Plan
|
||||
======================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
--------------------------------------
|
||||
|0 |TABLE SCAN|t1(k1)|10000 |62113|
|
||||
======================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 > 1 and c1 < 10;
|
||||
Query Plan
|
||||
======================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
--------------------------------------
|
||||
|0 |TABLE SCAN|t1(k1)|5000 |31098|
|
||||
======================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 = 1 and c2 < 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t1(k2)|99 |679 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 = 1 and c2 = 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t1(k2)|10 |142 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 = 1 and c2 = 1 and c3 < 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t1(k3)|1 |89 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select * from t1 where c1 = 1 and c2 = 1 and c3 = 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t1(k3)|1 |89 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), filter(nil),
|
||||
access([t1.c1], [t1.c2], [t1.c3], [t1.c4], [t1.c5], [t1.c6], [t1.c7], [t1.c8], [t1.c9], [t1.c10]), partitions(p0)
|
||||
|
||||
explain select count(*) from t2;
|
||||
Query Plan
|
||||
===========================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
-------------------------------------------
|
||||
|0 |SCALAR GROUP BY| |1 |52640|
|
||||
|1 | TABLE SCAN |t2(k1)|100000 |33539|
|
||||
===========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([T_FUN_COUNT(*)]), filter(nil),
|
||||
group(nil), agg_func([T_FUN_COUNT(*)])
|
||||
1 - output([1]), filter(nil),
|
||||
access([t2.c1]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 = 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t2 |990 |820 |
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 < 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t2 |10000 |7983|
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 > 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t2 |10000 |7983|
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 > 1 and c1 < 10;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t2 |5000 |4010|
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 = 1 and c2 < 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t2(k2)|99 |675 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 = 1 and c2 = 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t2(k2)|10 |142 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 = 1 and c2 = 1 and c3 < 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t2(k3)|1 |89 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select * from t2 where c1 = 1 and c2 = 1 and c3 = 1;
|
||||
Query Plan
|
||||
=====================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST|
|
||||
-------------------------------------
|
||||
|0 |TABLE SCAN|t2(k3)|1 |89 |
|
||||
=====================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), filter(nil),
|
||||
access([t2.c1], [t2.c2], [t2.c3], [t2.c4], [t2.c5], [t2.c6], [t2.c7], [t2.c8], [t2.c9], [t2.c10]), partitions(p0)
|
||||
|
||||
explain select count(*) from t3;
|
||||
Query Plan
|
||||
===========================================
|
||||
|ID|OPERATOR |NAME |EST. ROWS|COST |
|
||||
-------------------------------------------
|
||||
|0 |SCALAR GROUP BY| |1 |52640|
|
||||
|1 | TABLE SCAN |t3(k1)|100000 |33539|
|
||||
===========================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([T_FUN_COUNT(*)]), filter(nil),
|
||||
group(nil), agg_func([T_FUN_COUNT(*)])
|
||||
1 - output([1]), filter(nil),
|
||||
access([t3.c1]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 = 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |990 |820 |
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter(nil),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 < 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |10000 |7983|
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter(nil),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 > 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |10000 |7983|
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter(nil),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 > 1 and c1 < 10;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |5000 |4010|
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter(nil),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 = 1 and c2 < 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |99 |107 |
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter(nil),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 = 1 and c2 = 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |10 |40 |
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter(nil),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 = 1 and c2 = 1 and c3 < 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |1 |41 |
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter([t3.c3 < 1]),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
explain select * from t3 where c1 = 1 and c2 = 1 and c3 = 1;
|
||||
Query Plan
|
||||
===================================
|
||||
|ID|OPERATOR |NAME|EST. ROWS|COST|
|
||||
-----------------------------------
|
||||
|0 |TABLE SCAN|t3 |1 |41 |
|
||||
===================================
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), filter([t3.c3 = 1]),
|
||||
access([t3.c1], [t3.c2], [t3.c3], [t3.c4], [t3.c5], [t3.c6], [t3.c7], [t3.c8], [t3.c9], [t3.c10]), partitions(p0)
|
||||
|
||||
8320
test/mysql_test/test_suite/optimizer/r/mysql/equal_set_mysql.result
Normal file
8320
test/mysql_test/test_suite/optimizer/r/mysql/equal_set_mysql.result
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,302 @@
|
||||
create table test_table(id int primary key, name varchar(64), age int, description varchar(64), index index_1(age) local, index index_2(name) local);
|
||||
insert into test_table(id, name, age, description) values (0, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (1, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (2, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (3, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (4, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (5, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (6, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (7, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (8, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (9, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (10, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (11, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (12, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (13, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (14, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (15, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (16, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (17, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (18, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (19, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (20, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (21, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (22, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (23, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (24, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (25, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (26, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (27, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (28, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (29, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (30, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (31, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (32, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (33, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (34, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (35, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (36, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (37, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (38, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (39, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (40, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (41, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (42, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (43, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (44, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (45, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (46, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (47, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (48, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (49, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (50, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (51, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (52, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (53, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (54, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (55, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (56, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (57, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (58, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (59, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (60, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (61, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (62, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (63, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (64, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (65, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (66, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (67, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (68, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (69, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (70, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (71, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (72, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (73, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (74, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (75, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (76, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (77, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (78, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (79, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (80, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (81, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (82, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (83, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (84, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (85, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (86, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (87, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (88, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (89, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (90, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (91, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (92, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (93, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (94, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (95, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (96, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (97, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (98, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (99, 'name33', 33, 'rd1');
|
||||
insert into test_table(id, name, age, description) values (100, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (101, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (102, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (103, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (104, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (105, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (106, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (107, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (108, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (109, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (110, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (111, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (112, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (113, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (114, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (115, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (116, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (117, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (118, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (119, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (120, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (121, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (122, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (123, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (124, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (125, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (126, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (127, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (128, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (129, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (130, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (131, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (132, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (133, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (134, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (135, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (136, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (137, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (138, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (139, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (140, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (141, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (142, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (143, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (144, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (145, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (146, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (147, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (148, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (149, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (150, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (151, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (152, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (153, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (154, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (155, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (156, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (157, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (158, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (159, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (160, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (161, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (162, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (163, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (164, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (165, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (166, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (167, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (168, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (169, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (170, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (171, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (172, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (173, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (174, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (175, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (176, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (177, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (178, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (179, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (180, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (181, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (182, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (183, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (184, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (185, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (186, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (187, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (188, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (189, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (190, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (191, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (192, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (193, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (194, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (195, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (196, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (197, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (198, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (199, 'name44', 44, 'rd2');
|
||||
insert into test_table(id, name, age, description) values (200, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (201, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (202, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (203, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (204, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (205, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (206, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (207, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (208, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (209, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (210, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (211, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (212, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (213, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (214, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (215, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (216, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (217, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (218, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (219, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (220, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (221, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (222, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (223, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (224, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (225, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (226, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (227, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (228, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (229, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (230, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (231, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (232, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (233, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (234, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (235, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (236, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (237, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (238, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (239, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (240, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (241, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (242, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (243, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (244, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (245, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (246, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (247, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (248, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (249, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (250, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (251, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (252, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (253, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (254, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (255, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (256, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (257, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (258, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (259, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (260, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (261, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (262, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (263, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (264, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (265, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (266, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (267, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (268, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (269, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (270, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (271, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (272, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (273, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (274, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (275, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (276, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (277, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (278, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (279, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (280, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (281, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (282, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (283, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (284, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (285, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (286, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (287, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (288, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (289, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (290, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (291, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (292, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (293, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (294, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (295, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (296, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (297, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (298, 'name22', 22, 'rd3');
|
||||
insert into test_table(id, name, age, description) values (299, 'name22', 22, 'rd3');
|
||||
drop table test_table;
|
||||
@ -0,0 +1,550 @@
|
||||
drop database if exists union_sort_opt_db;
|
||||
create database union_sort_opt_db;
|
||||
use union_sort_opt_db;
|
||||
create table t4(c1 int primary key, c2 int, c3 int);
|
||||
insert into t4 values(10,12,3),(4,5,6),(2,13,4),(3,4,25),(7,18,9);
|
||||
commit;
|
||||
create index idx_t4_c2c3 on t4(c2,c3);
|
||||
### 1, 基本测试 表有PK ###
|
||||
select* from (select * from t4 union select * from t4) as x order by 1,2,3;
|
||||
c1 c2 c3
|
||||
2 13 4
|
||||
3 4 25
|
||||
4 5 6
|
||||
7 18 9
|
||||
10 12 3
|
||||
select * from t4 union select * from t4;
|
||||
c1 c2 c3
|
||||
2 13 4
|
||||
3 4 25
|
||||
4 5 6
|
||||
7 18 9
|
||||
10 12 3
|
||||
#1.2 使用索引c2c3也ok
|
||||
select /*+ index(t4 idx_t4_c2c3) */ * from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ * from t4 order by 1,2,3;
|
||||
c1 c2 c3
|
||||
2 13 4
|
||||
3 4 25
|
||||
4 5 6
|
||||
7 18 9
|
||||
10 12 3
|
||||
#1.3 顺序一致, 原本就支持
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c2,c3 from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c2,c3 from t4 order by 2,1;
|
||||
c2 c3
|
||||
12 3
|
||||
13 4
|
||||
5 6
|
||||
18 9
|
||||
4 25
|
||||
#1.4 顺序不一致, 修改后支持, 5
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c3,c2 from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c3,c2 from t4 order by 1,2;
|
||||
c3 c2
|
||||
3 12
|
||||
4 13
|
||||
6 5
|
||||
9 18
|
||||
25 4
|
||||
#1.5 完全一致
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c2,c3,c1 from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c2,c3,c1 from t4 order by 1,2,3;
|
||||
c2 c3 c1
|
||||
4 25 3
|
||||
5 6 4
|
||||
12 3 10
|
||||
13 4 2
|
||||
18 9 7
|
||||
#1.5.2 左匹配, 原本就支持
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c2 from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c2 from t4 order by 1;
|
||||
c2
|
||||
4
|
||||
5
|
||||
12
|
||||
13
|
||||
18
|
||||
#1.5.3 不能优化
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c3 from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c3 from t4 order by 1;
|
||||
c3
|
||||
3
|
||||
4
|
||||
6
|
||||
9
|
||||
25
|
||||
#1.5.4 不支持
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c1 from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c1 from t4 order by 1;
|
||||
c1
|
||||
2
|
||||
3
|
||||
4
|
||||
7
|
||||
10
|
||||
#1.6 两侧不匹配不能优化, 都加sort 10
|
||||
select /*+ index(x idx_t4_c2c3) */ c3,c1,c2 from t4 x union
|
||||
select /*+ index(y idx_t4_c2c3) */ c3,c2,c1 from t4 y order by 1,2,3;
|
||||
c3 c1 c2
|
||||
3 10 12
|
||||
3 12 10
|
||||
4 2 13
|
||||
4 13 2
|
||||
6 4 5
|
||||
6 5 4
|
||||
9 7 18
|
||||
9 18 7
|
||||
25 3 4
|
||||
25 4 3
|
||||
#1.7 两侧不匹配不能优化, 单侧加sort
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c2,c3,c1 from t4 union
|
||||
select /*+ index(t4 idx_t4_c2c3) */ c3,c2,c1 from t4 order by 1,2,3;
|
||||
c2 c3 c1
|
||||
3 12 10
|
||||
4 13 2
|
||||
4 25 3
|
||||
5 6 4
|
||||
6 5 4
|
||||
9 18 7
|
||||
12 3 10
|
||||
13 4 2
|
||||
18 9 7
|
||||
25 4 3
|
||||
### 2, 不包含PK的简单测试, 单key索引 ###
|
||||
create table t5(c int, c2 int, c3 int);
|
||||
insert into t5 values(1,2,3),(2,3,4),(0,1,2),(3,4,5),(0,2,3),(2,4,5);
|
||||
create index idx_t5_c2 on t5(c2);
|
||||
#2.1 不能优化
|
||||
select /*+ index(t5 idx_t5_c2) */ c2,c3 from t5 union
|
||||
select /*+ index(t5 idx_t5_c2) */ c2,c3 from t5 order by 1,2;
|
||||
c2 c3
|
||||
1 2
|
||||
2 3
|
||||
3 4
|
||||
4 5
|
||||
#2.2 原本就可优化
|
||||
select /*+ index(t5 idx_t5_c2) */ c2 from t5 union
|
||||
select /*+ index(t5 idx_t5_c2) */ c2 from t5 order by 1;
|
||||
c2
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
### 3, 无PK, 数据有重复, 结果正确性验证1
|
||||
create table t6(c1 int, c2 int);
|
||||
create index idx_t6_c1c2 on t6(c1,c2);
|
||||
insert into t6 values(10,20),(10,30),(20,10),(20,5),(10,30),(40,5),(10,8),(10,20),(1,0),(0,1),(20,80),(10,5),(10,5),(30,20),(30,1),(30,5),
|
||||
(10,20),(10,30),(20,10),(20,5),(10,30),(40,5),(10,8),(20,80),(10,5),(10,5),(30,20),(30,1),(1,0),(0,1),(0,0),(30,5);
|
||||
#3.1 可以优化, 14 rows
|
||||
select c1,c2 from t6 union select c1,c2 from t6 order by 1,2;
|
||||
c1 c2
|
||||
0 0
|
||||
0 1
|
||||
1 0
|
||||
10 5
|
||||
10 8
|
||||
10 20
|
||||
10 30
|
||||
20 5
|
||||
20 10
|
||||
20 80
|
||||
30 1
|
||||
30 5
|
||||
30 20
|
||||
40 5
|
||||
#3.2 可以优化, 14 rows
|
||||
select c2,c1 from t6 union select c2,c1 from t6 order by 1,2;
|
||||
c2 c1
|
||||
0 0
|
||||
0 1
|
||||
1 0
|
||||
1 30
|
||||
5 10
|
||||
5 20
|
||||
5 30
|
||||
5 40
|
||||
8 10
|
||||
10 20
|
||||
20 10
|
||||
20 30
|
||||
30 10
|
||||
80 20
|
||||
#3.3 不能优化 23 rows
|
||||
select c2,c1 from t6 union select c1,c2 from t6 order by 1,2;
|
||||
c2 c1
|
||||
0 0
|
||||
0 1
|
||||
1 0
|
||||
1 30
|
||||
5 10
|
||||
5 20
|
||||
5 30
|
||||
5 40
|
||||
8 10
|
||||
10 5
|
||||
10 8
|
||||
10 20
|
||||
10 30
|
||||
20 5
|
||||
20 10
|
||||
20 30
|
||||
20 80
|
||||
30 1
|
||||
30 5
|
||||
30 10
|
||||
30 20
|
||||
40 5
|
||||
80 20
|
||||
#3.4 不能优化, 有计算列的情况, 23 rows, 14
|
||||
select c2,c1 from t6 union select 0+c1,c2 from t6 order by 1,2;
|
||||
c2 c1
|
||||
0 0
|
||||
0 1
|
||||
1 0
|
||||
1 30
|
||||
5 10
|
||||
5 20
|
||||
5 30
|
||||
5 40
|
||||
8 10
|
||||
10 5
|
||||
10 8
|
||||
10 20
|
||||
10 30
|
||||
20 5
|
||||
20 10
|
||||
20 30
|
||||
20 80
|
||||
30 1
|
||||
30 5
|
||||
30 10
|
||||
30 20
|
||||
40 5
|
||||
80 20
|
||||
select c1,c2,c1,c2 from t6 union select 0+c1,c2,c1,c2 from t6 order by 1,2,3,4;
|
||||
c1 c2 c1 c2
|
||||
0 0 0 0
|
||||
0 1 0 1
|
||||
1 0 1 0
|
||||
10 5 10 5
|
||||
10 8 10 8
|
||||
10 20 10 20
|
||||
10 30 10 30
|
||||
20 5 20 5
|
||||
20 10 20 10
|
||||
20 80 20 80
|
||||
30 1 30 1
|
||||
30 5 30 5
|
||||
30 20 30 20
|
||||
40 5 40 5
|
||||
#4 分区表的测试
|
||||
create table t7(c1 varchar(10), c2 decimal(10,2), c3 int, c4 int) partition by hash(c4) partitions 5;
|
||||
insert into t7 values('11', 1.2, 1, 7),('22', 2.3, 2, 6),('33', 3.4, 3, 2), ('44', 4.5, 4, 10), ('55', 5.6, 5, 6),
|
||||
('12', 1.244, 4, 22),('22', 2.3, 3, 13),('3', 3.4, 2, 0), ('44', 4.5, 4, 1), ('56', 56, 1, 6),('44', 4.5, 4, 10);
|
||||
create index idx_t7_c2c1 on t7(c2,c1,c3) local;
|
||||
#4.1 可以优化, 完全匹配, 9 rows
|
||||
select /*+ index(t7 idx_t7_c2c1) */ c2,c1,c3 from t7 union
|
||||
select /*+ index(t7 idx_t7_c2c1) */ c2,c1,c3 from t7 where c2 < 10 order by 1,2,3;
|
||||
c2 c1 c3
|
||||
1.20 11 1
|
||||
1.24 12 4
|
||||
2.30 22 2
|
||||
2.30 22 3
|
||||
3.40 3 2
|
||||
3.40 33 3
|
||||
4.50 44 4
|
||||
5.60 55 5
|
||||
56.00 56 1
|
||||
#4.2 可以优化, 后续有连接, 15 rows
|
||||
select xx.c2,xx.c1 from
|
||||
(select /*+ index(t7 idx_t7_c2c1) */ c2,c1,c3 from t7 union
|
||||
select /*+ index(t7 idx_t7_c2c1) */ c2,c1,c3 from t7 where c2 < 10) xx,
|
||||
t7 yy where xx.c2 = yy.c2 order by 1,2;
|
||||
c2 c1
|
||||
1.20 11
|
||||
1.24 12
|
||||
2.30 22
|
||||
2.30 22
|
||||
2.30 22
|
||||
2.30 22
|
||||
3.40 3
|
||||
3.40 3
|
||||
3.40 33
|
||||
3.40 33
|
||||
4.50 44
|
||||
4.50 44
|
||||
4.50 44
|
||||
5.60 55
|
||||
56.00 56
|
||||
#4.3 可以优化, 9 rows
|
||||
select /*+ index(t7 idx_t7_c2c1) */ c2,c1,c3 from t7 union
|
||||
select /*+ index(t7 idx_t7_c2c1) */ c2,c1,c3 from t7 order by 1,2,3;
|
||||
c2 c1 c3
|
||||
1.20 11 1
|
||||
1.24 12 4
|
||||
2.30 22 2
|
||||
2.30 22 3
|
||||
3.40 3 2
|
||||
3.40 33 3
|
||||
4.50 44 4
|
||||
5.60 55 5
|
||||
56.00 56 1
|
||||
select c1 from t7 union select c1 from t7 order by 1;
|
||||
c1
|
||||
11
|
||||
12
|
||||
22
|
||||
3
|
||||
33
|
||||
44
|
||||
55
|
||||
56
|
||||
select /*+ index(t7 idx_t7_c2c1) */ c1,c2,c3 from t7 union
|
||||
select /*+ index(t7 idx_t7_c2c1) */ c1,c2,c3 from t7 order by 1,2,3;
|
||||
c1 c2 c3
|
||||
11 1.20 1
|
||||
12 1.24 4
|
||||
22 2.30 2
|
||||
22 2.30 3
|
||||
3 3.40 2
|
||||
33 3.40 3
|
||||
44 4.50 4
|
||||
55 5.60 5
|
||||
56 56.00 1
|
||||
#4.4 索引KEY升降序的测试, 目前此功能并不支持, 实际都是ASC
|
||||
drop index idx_t7_c2c1 on t7;
|
||||
create index idx_t7_c3c2c1 on t7(c3 asc,c2 asc,c1 asc) local;
|
||||
create table t72(c1 varchar(10), c2 decimal(10,2), c3 int);
|
||||
insert into t72 values('11', 1.2, 1),('22', 2.3, 2),('33', 3.4, 3), ('44', 4.5, 4), ('55', 5.6, 5),
|
||||
('12', 1.244, 4),('22', 2.3, 3),('3', 3.4, 2), ('44', 4.5, 4), ('56', 56, 1),('44', 4.5, 4);
|
||||
create index idx_t72_c3c2c1 on t72(c3 asc,c2 asc,c1 asc);
|
||||
#4.4.1 两个表上索引升降序一致, 不一一对应但两侧分支匹配, 可以优化, 8 rows
|
||||
select /*+ index(t7 idx_t7_c3c2c1) */ c1,c2,c3 from t7 where c3 < 5 union
|
||||
select /*+ index(t72 idx_t72_c3c2c1) */ c1,c2,c3 from t72 where c3 < 5 order by 1,2,3;
|
||||
c1 c2 c3
|
||||
11 1.20 1
|
||||
12 1.24 4
|
||||
22 2.30 2
|
||||
22 2.30 3
|
||||
3 3.40 2
|
||||
33 3.40 3
|
||||
44 4.50 4
|
||||
56 56.00 1
|
||||
#4.4.2 可以优化, 同上
|
||||
select /*+ index(t7 idx_t7_c3c2c1) */ c3,c2,c1 from t7 where c3 < 5 union
|
||||
select /*+ index(t72 idx_t72_c3c2c1) */ c3,c2,c1 from t72 where c3 < 5 order by 1,2,3;
|
||||
c3 c2 c1
|
||||
1 1.20 11
|
||||
1 56.00 56
|
||||
2 2.30 22
|
||||
2 3.40 3
|
||||
3 2.30 22
|
||||
3 3.40 33
|
||||
4 1.24 12
|
||||
4 4.50 44
|
||||
drop index idx_t72_c3c2c1 on t72;
|
||||
create index idx_t72_c3c2c1 on t72(c3 asc,c2 asc,c1 asc);
|
||||
#4.4.3 A,D不同, 但是实际存储一样, 所以也能优化, 8 rows
|
||||
select /*+ index(t7 idx_t7_c3c2c1) */ c1,c2,c3 from t7 where c3 < 5 union
|
||||
select /*+ index(t72 idx_t72_c3c2c1) */ c1,c2,c3 from t72 where c3 < 5 order by 1,2,3;
|
||||
c1 c2 c3
|
||||
11 1.20 1
|
||||
12 1.24 4
|
||||
22 2.30 2
|
||||
22 2.30 3
|
||||
3 3.40 2
|
||||
33 3.40 3
|
||||
44 4.50 4
|
||||
56 56.00 1
|
||||
#4.4.4 同上, 也能优化
|
||||
select /*+ index(t7 idx_t7_c3c2c1) */ c3,c2,c1 from t7 where c3 < 5 union
|
||||
select /*+ index(t72 idx_t72_c3c2c1) */ c3,c2,c1 from t72 where c3 < 5 order by 1,2,3;
|
||||
c3 c2 c1
|
||||
1 1.20 11
|
||||
1 56.00 56
|
||||
2 2.30 22
|
||||
2 3.40 3
|
||||
3 2.30 22
|
||||
3 3.40 33
|
||||
4 1.24 12
|
||||
4 4.50 44
|
||||
#5 结果正确性测试2
|
||||
create table test1(c1 int, c2 int);
|
||||
create table test2(d1 int, d2 int);
|
||||
insert into test1 values(1,1),(1,2),(2,1),(2,2),(2,0),(1,3),(1,0),(3,0),(3,2),(3,1),(2,1);
|
||||
insert into test2 values(1,1),(1,2),(2,1),(2,2),(2,0),(1,3),(1,0),(3,0),(3,2),(3,1),(2,1);
|
||||
commit;
|
||||
create index idx_test1_c1c2 on test1(c1 asc, c2 asc);
|
||||
create index idx_test2_d1d2 on test2(d1 asc, d2 asc);
|
||||
#5.1 最后加了排序, which can't be optimized...
|
||||
select c2, c1 from test1 union select d2,d1 from test2 order by c2,c1;
|
||||
c2 c1
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
1 1
|
||||
1 2
|
||||
1 3
|
||||
2 1
|
||||
2 2
|
||||
2 3
|
||||
3 1
|
||||
#5.2 最后的排序可以被优化
|
||||
select c2, c1 from test1 union select d2,d1 from test2 order by c1,c2;
|
||||
c2 c1
|
||||
0 1
|
||||
1 1
|
||||
2 1
|
||||
3 1
|
||||
0 2
|
||||
1 2
|
||||
2 2
|
||||
0 3
|
||||
1 3
|
||||
2 3
|
||||
#5.3 最后的排序由于是逆序不能被优化掉
|
||||
select c2, c1 from test1 union select d2,d1 from test2 order by c1 desc,c2 desc;
|
||||
c2 c1
|
||||
2 3
|
||||
1 3
|
||||
0 3
|
||||
2 2
|
||||
1 2
|
||||
0 2
|
||||
3 1
|
||||
2 1
|
||||
1 1
|
||||
0 1
|
||||
#5.4 整数的查询项, 6 rows, 10, 4 rows
|
||||
select 1, c1 from test1 union select 2,d1 from test2 order by 1,2;
|
||||
1 c1
|
||||
1 1
|
||||
1 2
|
||||
1 3
|
||||
2 1
|
||||
2 2
|
||||
2 3
|
||||
select 1, c2 from test1 union select d1,d2 from test2 order by 1,2;
|
||||
1 c2
|
||||
1 0
|
||||
1 1
|
||||
1 2
|
||||
1 3
|
||||
2 0
|
||||
2 1
|
||||
2 2
|
||||
3 0
|
||||
3 1
|
||||
3 2
|
||||
select mod(c1,2),mod(c2,2) from test1 union select mod(d1,2),mod(d2,2) from test2 order by 1,2;
|
||||
mod(c1,2) mod(c2,2)
|
||||
0 0
|
||||
0 1
|
||||
1 0
|
||||
1 1
|
||||
#6 from mysqltest union1, simply recreate
|
||||
create table x1(c1 int, c2 char(10), c3 int);
|
||||
create table x2(d1 int, d2 char(10), d3 int, index ix2(d2, d3));
|
||||
insert into x1 values(1,'xx2',3),(2,'xxx3',4),(3,'aaa4',5);
|
||||
insert into x2 values(11,'xx2',3),(2,'xx3',4),(3,'aaa4',5);
|
||||
select c2, c3 from x1 union select /*+ index(x2 ix2) */ d2, d3 from x2 order by 1,2;
|
||||
c2 c3
|
||||
aaa4 5
|
||||
xx2 3
|
||||
xx3 4
|
||||
xxx3 4
|
||||
select c3, c2 from x1 union select /*+ index(x2 ix2) */ d3, d2 from x2 order by 1,2;
|
||||
c3 c2
|
||||
3 xx2
|
||||
4 xx3
|
||||
4 xxx3
|
||||
5 aaa4
|
||||
CREATE TABLE ts1 (c1 VARCHAR(10) NOT NULL, c2 INT NOT NULL);
|
||||
CREATE TABLE ts2 (c1 VARCHAR(10) NOT NULL, c2 INT NOT NULL);
|
||||
INSERT INTO ts1 (c1, c2) VALUES ('t1a', 1), ('t1a', 2), ('t1a', 3), ('t1b', 2), ('t1b', 1);
|
||||
INSERT INTO ts2 (c1, c2) VALUES ('t2a', 1), ('t2a', 2), ('t2a', 3), ('t2b', 2), ('t2b', 1);
|
||||
SELECT c1, c2 FROM (
|
||||
SELECT c1, c2 FROM ts1
|
||||
UNION
|
||||
(SELECT c1, c2 FROM ts2 ORDER BY c2 DESC, c1 LIMIT 1)
|
||||
) AS res order by 1,2;
|
||||
c1 c2
|
||||
t1a 1
|
||||
t1a 2
|
||||
t1a 3
|
||||
t1b 1
|
||||
t1b 2
|
||||
t2a 3
|
||||
DROP TABLE IF EXISTS T1, T2, T3;
|
||||
CREATE TABLE T1 (PK INT PRIMARY KEY, C1 INT, C2 INT);
|
||||
CREATE TABLE T2 (PK INT PRIMARY KEY, C1 INT, C2 INT);
|
||||
CREATE TABLE T3 (PK INT PRIMARY KEY, C1 INT, C2 INT);
|
||||
SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1 UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
C1 C2 PK
|
||||
5 4 2
|
||||
1 1 1
|
||||
1 1 2
|
||||
CREATE TABLE table2_bigint (
|
||||
col_decimal_20_0_signed decimal(20,0) signed,
|
||||
col_decimal_20_0_unsigned decimal(20,0) unsigned,
|
||||
col_char_20 char(20),
|
||||
col_decimal_20_0 decimal(20,0),
|
||||
pk bigint,
|
||||
col_bigint bigint,
|
||||
col_timestamp_6 timestamp(6) NULL DEFAULT NULL,
|
||||
col_bigint_unsigned bigint unsigned,
|
||||
col_bigint_signed bigint signed,
|
||||
primary key (pk));
|
||||
CREATE TABLE table100_bigint (
|
||||
col_bigint_unsigned bigint unsigned,
|
||||
col_decimal_20_0_unsigned decimal(20,0) unsigned,
|
||||
col_bigint_signed bigint signed,
|
||||
col_bigint bigint,
|
||||
pk bigint,
|
||||
col_decimal_20_0_signed decimal(20,0) signed,
|
||||
col_timestamp_6 timestamp(6) NULL DEFAULT NULL,
|
||||
col_char_20 char(20),
|
||||
col_decimal_20_0 decimal(20,0),
|
||||
/*Indices*/
|
||||
primary key (pk)) ;
|
||||
SELECT col_bigint, col_bigint_signed, col_bigint_unsigned, col_char_20, col_decimal_20_0, col_decimal_20_0_signed, col_decimal_20_0_unsigned, col_timestamp_6, pk
|
||||
FROM
|
||||
(
|
||||
(SELECT col_bigint, col_bigint_signed, col_bigint_unsigned, col_char_20, col_decimal_20_0, col_decimal_20_0_signed, col_decimal_20_0_unsigned, col_timestamp_6, pk
|
||||
FROM table2_bigint
|
||||
WHERE col_decimal_20_0_unsigned <> 99999
|
||||
ORDER BY pk DESC , 6 DESC , pk
|
||||
LIMIT 1,
|
||||
5)
|
||||
UNION DISTINCT SELECT col_bigint, col_bigint_signed, col_bigint_unsigned, col_char_20, col_decimal_20_0, col_decimal_20_0_signed, col_decimal_20_0_unsigned, col_timestamp_6, pk
|
||||
FROM (
|
||||
(SELECT col_bigint, col_bigint_signed, col_bigint_unsigned, col_char_20, col_decimal_20_0, col_decimal_20_0_signed, col_decimal_20_0_unsigned, col_timestamp_6, pk
|
||||
FROM table100_bigint
|
||||
WHERE col_decimal_20_0_signed = ROUND(SIGN(col_decimal_20_0))
|
||||
ORDER BY col_bigint_signed , 6 , col_decimal_20_0 , pk DESC LIMIT 7)
|
||||
UNION DISTINCT
|
||||
(SELECT col_bigint, col_bigint_signed, col_bigint_unsigned, col_char_20, col_decimal_20_0, col_decimal_20_0_signed, col_decimal_20_0_unsigned, col_timestamp_6, pk
|
||||
FROM table2_bigint
|
||||
WHERE SUBSTR('g', 1, LEAST(58, 20)) <> INSERT('lgeswk', 99, 8, TRIM(SUBSTRING(CONVERT(TRIM(SUBSTR(TRIM(SUBSTR(SUBSTRING('nlge', 1, LEAST(58, 20)), 1, 2)
|
||||
FROM SUBSTRING('', 1, LEAST(58, 20))), 1, LEAST(58, 20))), CHAR(50)), 1, LEAST(58, 20))))
|
||||
ORDER BY 3 ,
|
||||
col_bigint_unsigned ,
|
||||
pk DESC)) TUT
|
||||
ORDER BY col_bigint,
|
||||
col_bigint_signed,
|
||||
col_bigint_unsigned,
|
||||
col_char_20,
|
||||
col_decimal_20_0,
|
||||
col_decimal_20_0_signed,
|
||||
col_decimal_20_0_unsigned,
|
||||
col_timestamp_6,
|
||||
pk) TUT WHERE pk in (9727744 ,7826688 ,1657856 , 55039 , 50631)
|
||||
ORDER BY col_bigint, col_bigint_signed, col_bigint_unsigned, col_char_20, col_decimal_20_0, col_decimal_20_0_signed, col_decimal_20_0_unsigned, col_timestamp_6, pk;
|
||||
col_bigint col_bigint_signed col_bigint_unsigned col_char_20 col_decimal_20_0 col_decimal_20_0_signed col_decimal_20_0_unsigned col_timestamp_6 pk
|
||||
NULL NULL NULL NULL NULL NULL 0 NULL 7826688
|
||||
NULL NULL NULL NULL NULL NULL 1 NULL 1657856
|
||||
NULL NULL NULL NULL NULL NULL 11753728 NULL 9727744
|
||||
NULL NULL NULL 0 NULL NULL 999999999 NULL 50631
|
||||
NULL NULL NULL nf NULL NULL 22222222 NULL 55039
|
||||
drop database union_sort_opt_db;
|
||||
Reference in New Issue
Block a user