162 lines
9.9 KiB
Plaintext
162 lines
9.9 KiB
Plaintext
--disable_query_log
|
|
set @@session.explicit_defaults_for_timestamp=off;
|
|
--enable_query_log
|
|
|
|
#owner: linlin.xll
|
|
#owner group: sql2
|
|
#description:
|
|
#tags: join,optimizer
|
|
|
|
--disable_warnings
|
|
drop database if exists yy;
|
|
drop table if exists t1;
|
|
drop table if exists t2;
|
|
drop table if exists t4;
|
|
drop table if exists t5;
|
|
drop table if exists t6;
|
|
drop table if exists t11;
|
|
drop table if exists t12;
|
|
drop table if exists t13;
|
|
drop table if exists t15;
|
|
--enable_warnings
|
|
|
|
create database yy;
|
|
use yy;
|
|
create table t1(c1 int(11) , c2 int(11) , c3 int(11), primary key (c2, c3)) partition by range columns(c2, c3) (partition p0 values less than (1,1), partition p1 values less than (100,100));
|
|
create table t2(c1 int(11) not null, c2 int(11) not null, c3 int(11) not null, primary key (c1, c2, c3)) partition by hash(c1) partitions 2;
|
|
create table t11(c1 int primary key, c2 int) partition by hash (c1) partitions 5;
|
|
create table t12(c1 int primary key, c2 int, c3 varchar(32)) partition by hash (c1) partitions 3;
|
|
create table t13(c1 int primary key, c2 int, c3 varchar(32)) partition by hash (c1) partitions 2;
|
|
create index idx_t11_c2 on t11(c2) LOCAL;
|
|
create table t15(c1 int, c2 int, c3 int, primary key(c2,c3)) partition by key(c2, c3) partitions 3;
|
|
create index idx_t15_c2 on t15(c2) LOCAL;
|
|
create index idx_t15_c3 on t15(c3) LOCAL;
|
|
|
|
|
|
##this will not be repart so far, because range columns(c2,c3) will be allowed later
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
|
|
|
|
drop table t1;
|
|
create table t1 (c1 int(11) , c2 int(11) , c3 int(11), primary key (c2, c3)) partition by key(c2) partitions 2;
|
|
##this will not be repart so far, key partition type is not allowed so far will be allowed later
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
|
|
|
|
drop table t1;
|
|
create table t1 (c1 int(11) , c2 int(11) , c3 int(11), c4 date, primary key (c2, c3)) partition by range columns(c2)
|
|
(partition p0 values less than (1), partition p1 values less than (100));
|
|
|
|
|
|
#####below will be not repart
|
|
## not nest loop
|
|
explain select * from t1 join t2 on t1.c2= t2.c2;
|
|
##partition key is not covered by join key
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c3= t2.c3;
|
|
explain select /*+use_bnl(t1 t2)*/ * from t1 join t2 on t1.c3= t2.c3;
|
|
|
|
|
|
####below will be repart
|
|
#right repart both sharding
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2;
|
|
#left repart both sharding
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c1= t2.c1;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c1= t2.c1 and t1.c3= t2.c3;
|
|
#right repart ,left is sharding
|
|
#left repart ,right is sharding
|
|
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c2= t2.c2;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c1= t2.c1;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
|
|
|
|
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select c1 from t11 where c2 not in (select c2 from t11);
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select c1 from t12 where c1 not in (select c1 from t11 where c2 not in (select c2 from t11));
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select * from (select /*+use_nl(t11 t12)*/ t12.c1 from t11,t12 where t11.c1=t12.c1 limit 1) v order by v.c1;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select count(c1) from t11 group by c1 having c1 in (select t12.c1 from t12 where t11.c1=t12.c2);
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select * from t11 where c1 in (select c1 from t12 where (1 = 0 or c1 > 5));
|
|
|
|
#part key is generated column,which will not be true, part key need to be primary key, but primary key is not supported as generate columns so far
|
|
|
|
#####part_level_two
|
|
create table t4 (c1 int, c2 int, c3 date, c4 int, primary key(c1,c2,c3)) partition by hash(c1) subpartition by range columns(c3)
|
|
subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
|
|
subpartition p_2016_11_03_00 values less than ('2016-11-03'),
|
|
subpartition p_max_value values less than (MAXVALUE));
|
|
|
|
create table t5(c1 int, c2 int, c3 date, c4 int, primary key(c1,c2,c3)) partition by hash(c1) subpartition by range columns(c3)
|
|
subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
|
|
subpartition p_2016_11_03_00 values less than ('2016-11-03'),
|
|
subpartition p_max_value values less than (MAXVALUE));
|
|
|
|
create table t6(c1 int, c2 int, c3 date, c4 int, primary key(c1,c2,c3)) partition by hash(c1) subpartition by range columns(c3)
|
|
subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
|
|
subpartition p_2016_11_03_00 values less than ('2016-11-03'),
|
|
subpartition p_max_value values less than (MAXVALUE));
|
|
|
|
####below will be not repart
|
|
explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c2= t5.c2;
|
|
explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c1= t5.c1;
|
|
explain select /*+use_nl(t4 t5)*/ * from t4 join t5 on t4.c2= t5.c2 and t4.c3= t5.c3;
|
|
explain select * from t4 left join t5 on t4.c1= t5.c1 and t4.c3 = t5.c3;
|
|
|
|
|
|
#right repart both sharding
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c1= t5.c2 and t4.c3 = t5.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t4 t1)*/ * from t4 left join t1 on t4.c1= t1.c1 and t4.c3 = t1.c4;
|
|
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t5 t4)*/ * from t5 left join t4 on t4.c1= t5.c2 and t4.c3 = t5.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t1 t4)*/ * from t1 left join t4 on t4.c1= t1.c1 and t4.c3 = t1.c4;
|
|
|
|
#left repart both sharding left repart is prior to right repart, when both is available
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c1= t5.c1 and t4.c3 = t5.c3;
|
|
|
|
#subplan and join
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select * from (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as a join t5 as b on a.c1 = b.c1 and a.c3 = b.c3 join t6 as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select * from t5 as a join (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as b on a.c1 = b.c1 and a.c3 = b.c3 join t6 as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select * from t5 as a join t6 as b on a.c1 = b.c1 and a.c3 = b.c3 join (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(a b) use_nl(b c)*/ * from (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as a join t5 as b on a.c1 = b.c1 and a.c3 = b.c3 join t6 as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(a b) use_nl(b c)*/ * from t5 as a join (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as b on a.c1 = b.c1 and a.c3 = b.c3 join t6 as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(a b) use_nl(b c)*/ * from t5 as a join t6 as b on a.c1 = b.c1 and a.c3 = b.c3 join (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(a b) use_nl(b c)*/ * from (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 2) as a left join t5 as b on a.c1 = b.c1 and a.c3 = b.c3 left join t6 as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(a b) use_nl(b c)*/ * from t5 as a left join (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as b on a.c1 = b.c1 and a.c3 = b.c3 left join t6 as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(a b) use_nl(b c)*/ * from t5 as a left join t6 as b on a.c1 = b.c1 and a.c3 = b.c3 left join (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 1) as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(c)*/ * from t5 as a left join t6 as b on a.c1 = b.c1 and a.c3 = b.c3 left join t4 as c on b.c1=c.c1 and b.c3 = c.c3;
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_nl(c)*/ * from t5 as a left join t6 as b on a.c1 = b.c1 and a.c3 = b.c3 left join t4 as c on b.c1=c.c1 and b.c3 = c.c3 limit 100;
|
|
|
|
|
|
###suplan filter
|
|
##bnl should not be repart
|
|
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
|
|
explain select /*+use_bnl(a b)*/ * from (select c1, c3, sum(c2) as yyy, max(c4) from t4 group by c3 order by yyy limit 2) as a left join t5 as b on a.c1 = b.c1 and a.c3 = b.c3 ;
|
|
drop database yy;
|