oceanbase
161 строка · 9.9 Кб
1--disable_query_log
2set @@session.explicit_defaults_for_timestamp=off;
3--enable_query_log
4
5#owner: linlin.xll
6#owner group: sql2
7#description:
8#tags: join,optimizer
9
10--disable_warnings
11drop database if exists yy;
12drop table if exists t1;
13drop table if exists t2;
14drop table if exists t4;
15drop table if exists t5;
16drop table if exists t6;
17drop table if exists t11;
18drop table if exists t12;
19drop table if exists t13;
20drop table if exists t15;
21--enable_warnings
22
23create database yy;
24use yy;
25create 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));
26create 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;
27create table t11(c1 int primary key, c2 int) partition by hash (c1) partitions 5;
28create table t12(c1 int primary key, c2 int, c3 varchar(32)) partition by hash (c1) partitions 3;
29create table t13(c1 int primary key, c2 int, c3 varchar(32)) partition by hash (c1) partitions 2;
30create index idx_t11_c2 on t11(c2) LOCAL;
31create table t15(c1 int, c2 int, c3 int, primary key(c2,c3)) partition by key(c2, c3) partitions 3;
32create index idx_t15_c2 on t15(c2) LOCAL;
33create index idx_t15_c3 on t15(c3) LOCAL;
34
35
36##this will not be repart so far, because range columns(c2,c3) will be allowed later
37explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
38
39drop table t1;
40create table t1 (c1 int(11) , c2 int(11) , c3 int(11), primary key (c2, c3)) partition by key(c2) partitions 2;
41##this will not be repart so far, key partition type is not allowed so far will be allowed later
42explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
43
44drop table t1;
45create table t1 (c1 int(11) , c2 int(11) , c3 int(11), c4 date, primary key (c2, c3)) partition by range columns(c2)
46(partition p0 values less than (1), partition p1 values less than (100));
47
48
49#####below will be not repart
50## not nest loop
51explain select * from t1 join t2 on t1.c2= t2.c2;
52##partition key is not covered by join key
53explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c3= t2.c3;
54explain select /*+use_bnl(t1 t2)*/ * from t1 join t2 on t1.c3= t2.c3;
55
56
57####below will be repart
58#right repart both sharding
59--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
60explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2;
61#left repart both sharding
62--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
63explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c1= t2.c1;
64--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
65explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
66--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
67explain select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c1= t2.c1 and t1.c3= t2.c3;
68#right repart ,left is sharding
69#left repart ,right is sharding
70
71--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
72explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c2= t2.c2;
73--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
74explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c1= t2.c1;
75--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
76explain select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
77
78
79--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
80explain select c1 from t11 where c2 not in (select c2 from t11);
81--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
82explain select c1 from t12 where c1 not in (select c1 from t11 where c2 not in (select c2 from t11));
83--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
84explain select * from (select /*+use_nl(t11 t12)*/ t12.c1 from t11,t12 where t11.c1=t12.c1 limit 1) v order by v.c1;
85--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
86explain select count(c1) from t11 group by c1 having c1 in (select t12.c1 from t12 where t11.c1=t12.c2);
87--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
88explain select * from t11 where c1 in (select c1 from t12 where (1 = 0 or c1 > 5));
89
90#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
91
92#####part_level_two
93create table t4 (c1 int, c2 int, c3 date, c4 int, primary key(c1,c2,c3)) partition by hash(c1) subpartition by range columns(c3)
94subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
95subpartition p_2016_11_03_00 values less than ('2016-11-03'),
96subpartition p_max_value values less than (MAXVALUE));
97
98create table t5(c1 int, c2 int, c3 date, c4 int, primary key(c1,c2,c3)) partition by hash(c1) subpartition by range columns(c3)
99subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
100subpartition p_2016_11_03_00 values less than ('2016-11-03'),
101subpartition p_max_value values less than (MAXVALUE));
102
103create table t6(c1 int, c2 int, c3 date, c4 int, primary key(c1,c2,c3)) partition by hash(c1) subpartition by range columns(c3)
104subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
105subpartition p_2016_11_03_00 values less than ('2016-11-03'),
106subpartition p_max_value values less than (MAXVALUE));
107
108####below will be not repart
109explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c2= t5.c2;
110explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c1= t5.c1;
111explain select /*+use_nl(t4 t5)*/ * from t4 join t5 on t4.c2= t5.c2 and t4.c3= t5.c3;
112explain select * from t4 left join t5 on t4.c1= t5.c1 and t4.c3 = t5.c3;
113
114
115#right repart both sharding
116--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
117explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c1= t5.c2 and t4.c3 = t5.c3;
118--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
119explain select /*+use_nl(t4 t1)*/ * from t4 left join t1 on t4.c1= t1.c1 and t4.c3 = t1.c4;
120
121--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
122explain select /*+use_nl(t5 t4)*/ * from t5 left join t4 on t4.c1= t5.c2 and t4.c3 = t5.c3;
123--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
124explain select /*+use_nl(t1 t4)*/ * from t1 left join t4 on t4.c1= t1.c1 and t4.c3 = t1.c4;
125
126#left repart both sharding left repart is prior to right repart, when both is available
127--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
128explain select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c1= t5.c1 and t4.c3 = t5.c3;
129
130#subplan and join
131--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
132explain 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;
133--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
134explain 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;
135--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
136explain 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;
137
138--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
139explain 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;
140--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
141explain 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;
142--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
143explain 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;
144
145--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
146explain 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;
147--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
148explain 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;
149--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
150explain 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;
151--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
152explain 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;
153--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
154explain 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;
155
156
157###suplan filter
158##bnl should not be repart
159--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
160explain 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 ;
161drop database yy;
162