oceanbase

Форк
0
/t
/
dist_nest_loop_simple.test 
161 строка · 9.9 Кб
1
--disable_query_log
2
set @@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
11
drop database if exists yy;
12
drop table if exists t1;
13
drop table if exists t2;
14
drop table if exists t4;
15
drop table if exists t5;
16
drop table if exists t6;
17
drop table if exists t11;
18
drop table if exists t12;
19
drop table if exists t13;
20
drop table if exists t15;
21
--enable_warnings
22

23
create database yy;
24
use yy;
25
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));
26
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;
27
create table t11(c1 int primary key, c2 int) partition by hash (c1) partitions 5;
28
create table t12(c1 int primary key, c2 int, c3 varchar(32)) partition by hash (c1) partitions 3;
29
create table t13(c1 int primary key, c2 int, c3 varchar(32)) partition by hash (c1) partitions 2;
30
create index idx_t11_c2 on t11(c2) LOCAL;
31
create table t15(c1 int, c2 int, c3 int, primary key(c2,c3)) partition by key(c2, c3) partitions 3;
32
create index idx_t15_c2 on t15(c2) LOCAL;
33
create 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
37
explain  select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
38

39
drop table t1;
40
create 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
42
explain  select /*+use_nl(t1 t2)*/ * from t1 left join t2 on t1.c2= t2.c2 and t1.c3= t2.c3;
43

44
drop table t1;
45
create 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
51
explain  select * from t1 join t2 on t1.c2= t2.c2;
52
##partition key is not covered by join key
53
explain  select /*+use_nl(t1 t2)*/ * from t1 join t2 on t1.c3= t2.c3;
54
explain  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/
60
explain  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/
63
explain  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/
65
explain  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/
67
explain  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/
72
explain  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/
74
explain  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/
76
explain  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/
80
explain  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/
82
explain  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/
84
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;
85
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
86
explain  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/
88
explain  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
93
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)
94
subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
95
subpartition p_2016_11_03_00 values less than ('2016-11-03'),
96
subpartition p_max_value values less than (MAXVALUE));
97

98
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)
99
subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
100
subpartition p_2016_11_03_00 values less than ('2016-11-03'),
101
subpartition p_max_value values less than (MAXVALUE));
102

103
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)
104
subpartition template( subpartition p_2016_11_02_00 values less than ('2016-11-02'),
105
subpartition p_2016_11_03_00 values less than ('2016-11-03'),
106
subpartition p_max_value values less than (MAXVALUE));
107

108
####below will be not repart
109
explain  select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c2= t5.c2;
110
explain  select /*+use_nl(t4 t5)*/ * from t4 left join t5 on t4.c1= t5.c1;
111
explain  select /*+use_nl(t4 t5)*/ * from t4 join t5 on t4.c2= t5.c2 and t4.c3= t5.c3;
112
explain  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/
117
explain  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/
119
explain  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/
122
explain  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/
124
explain  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/
128
explain  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/
132
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;
133
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
134
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;
135
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
136
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;
137

138
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
139
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;
140
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
141
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;
142
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
143
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;
144

145
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
146
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;
147
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
148
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;
149
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
150
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;
151
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
152
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;
153
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
154
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;
155

156

157
###suplan filter
158
##bnl should not be repart
159
--replace_regex /repart_table_id_:[0-9]*/repart_table_id_:TABLE_ID/
160
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 ;
161
drop database yy;
162

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.