oceanbase
264 строки · 7.9 Кб
1--disable_query_log
2set @@session.explicit_defaults_for_timestamp=off;
3--enable_query_log
4# owner: xiaoyi.xy
5# owner group: SQL3
6# description: 本case是为了测试delete 一个range内的数据
7# tags: delete,dml
8
9####TITLE: range delete
10--disable_warnings
11drop table if exists t1;
12--enable_warnings
13
14
15####CASE: single rowkey, using rowkey, >,>=,<,<=
16create table t1 (a int, b int, primary key (a));
17insert into t1(a,b) values(1,1),(2,1),(3,1),(4,1);
18delete from t1 where a=1;
19delete from t1 where a>0;
20select * from t1;
21
22replace into t1(a,b) values(1,1),(2,1),(3,1),(4,1);
23delete from t1 where a<5;
24select * from t1;
25
26replace into t1(a,b) values(1,1),(2,1),(3,1),(4,1);
27delete from t1 where a>1;
28select * from t1;
29
30replace into t1(a,b) values(2,1),(3,1),(4,1);
31delete from t1 where a<4;
32select * from t1;
33
34replace into t1(a,b) values(1,1),(2,1),(3,1);
35delete from t1 where a>=1;
36select * from t1;
37
38replace into t1(a,b) values(1,1),(2,1),(3,1),(4,1);
39delete from t1 where a<=5;
40select * from t1;
41
42replace into t1(a,b) values(1,1),(2,1),(3,1),(4,1);
43delete from t1 where a>0 and a<2;
44delete from t1 where a>=2 and a<3;
45delete from t1 where a>=3 and a<=4;
46select * from t1;
47
48replace into t1(a,b) values(1,1),(2,1),(3,1),(4,1);
49delete from t1 where a=1 or a=2 or a=3 or a=4;
50select * from t1;
51
52####CASE: single rowkey, using non_rowkey, >, >=, <, <=
53replace into t1(a,b) values(1,1),(2,2),(3,3),(4,4);
54delete from t1 where b>0;
55select * from t1;
56
57replace into t1(a,b) values(1,1),(2,2),(3,3),(4,4);
58delete from t1 where b<6;
59select * from t1;
60
61replace into t1(a,b) values(1,1),(2,2),(3,3),(4,4);
62delete from t1 where b>1;
63select * from t1;
64
65replace into t1(a,b) values(2,2),(3,3),(4,4);
66delete from t1 where b<5;
67select * from t1;
68
69replace into t1(a,b) values(1,1),(2,2),(3,3),(4,4);
70delete from t1 where b>=1;
71select * from t1;
72
73replace into t1(a,b) values(1,1),(2,2),(3,3),(4,4);
74delete from t1 where b<=7;
75select * from t1;
76
77replace into t1(a,b) values(1,1),(2,2),(3,3),(4,4);
78delete from t1 where b>0 and b<2;
79delete from t1 where b>=2 and b<3;
80delete from t1 where b>=3 and b<=4;
81select * from t1;
82
83replace into t1(a,b) values(1,1),(2,2),(3,3),(4,4);
84delete from t1 where b=1 or b=2 or b=3 or b=4;
85select * from t1;
86
87####CASE: single rowkey: using rowkey + non_rowkey, >, >=, <,<=, or
88--disable_warnings
89drop table if exists t1;
90--enable_warnings
91create table t1(a int, b int, c int, primary key(a));
92replace into t1(a,b) values(1,1),(2,2),(3,1),(4,2);
93delete from t1 where a>0 and b>1;
94delete from t1 where a<5 and b<2;
95select * from t1;
96
97replace into t1(a,b) values(1,1),(2,2),(3,1),(4,2);
98delete from t1 where a>=0 and b<=1;
99delete from t1 where a<=5 and b>=2;
100select * from t1;
101
102replace into t1(a,b) values(1,1),(2,2),(3,1),(4,2);
103delete from t1 where a=0 or a=1 or a=2 or b=1;
104select * from t1;
105
106replace into t1(a,b) values(1,1),(2,2),(3,1),(4,2);
107delete from t1 where b=2 or a=1 or a=2;
108select * from t1;
109
110replace into t1(a,b,c) values(1,1,NULL),(2,2,NULL),(3,3,NULL),(4,4,NULL);
111delete from t1 where a<=1 or b>=4;
112select * from t1;
113
114replace into t1(a,b,c) values(1,1,NULL),(2,2,NULL),(3,3,NULL),(4,4,NULL);
115delete from t1 where a>1 or b<4;
116select * from t1;
117
118####CASE: two rowkeys, using rowkey, >, >=, <, <=
119--disable_warnings
120drop table if exists t1;
121--enable_warnings
122create table t1(a int, b int, c int, d int, primary key(a,b));
123replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
124delete from t1 where (a,b) > (0,0);
125select * from t1;
126
127replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
128delete from t1 where (a,b) < (4,4);
129select * from t1;
130
131replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
132delete from t1 where (a,b) >= (1,1);
133select * from t1;
134
135
136replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
137delete from t1 where (a,b) <= (1,1);
138select * from t1;
139
140replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
141delete from t1 where (a,b) in ((NULL,NULL),(0,0),(1,1),(2,2),(3,3),(4,4));
142select * from t1;
143
144replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
145delete from t1 where (a,b)=(1,1) or (a,b)=(2,2) or (a,b)=(3,3);
146select * from t1;
147
148replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
149delete from t1 where (a,b) in ((1,1),(2,2),(3,3));
150select * from t1;
151
152replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
153delete from t1 where (a,b,c,d) >= (1,1,1,1);
154select * from t1;
155
156replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
157delete from t1 where (a,b,c,d) <= (3,3,3,3);
158select * from t1;
159
160replace into t1(a,b,c,d) values(1,1,1,1),(2,2,1,1),(3,3,1,1);
161delete from t1 where (a,b,c,d)=(1,1,1,1) or (a,b,c,d)=(2,2,1,1) or (a,b,c,d)=(3,3,3,3);
162select * from t1;
163
164####CASE: two rowkeys, using one of rowkey, =, >, >=, <, <=
165--disable_warnings
166drop table if exists t1;
167--enable_warnings
168create table t1(a int, b int, c int, d int, primary key(a,b));
169replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
170delete from t1 where a = 1;
171select * from t1;
172
173replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
174delete from t1 where a > 0;
175select * from t1;
176
177replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
178delete from t1 where a >=1 ;
179select * from t1;
180
181replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
182delete from t1 where a < 4;
183select * from t1;
184
185replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
186delete from t1 where a <= 1;
187select * from t1;
188
189replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
190delete from t1 where a=1 or a=2 or a=3;
191select * from t1;
192
193replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
194delete from t1 where (a=1 or a=2 or a=3) and (b=1 or b=2);
195select * from t1;
196
197replace into t1(a,b,c,d) values(1,1,1,1),(1,2,1,1),(1,3,1,1);
198delete from t1 where a>=1 and b>=2;
199select * from t1;
200
201####CASE:two rowkeys, using rowkey + non_rowkey, >, >=, <, <=, =
202--disable_warnings
203drop table if exists t1;
204--enable_warnings
205create table t1(a int, b int, c int, d int, primary key(a,b));
206replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
207delete from t1 where (a,b)>=(1,1) and c=1;
208select * from t1;
209
210replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
211delete from t1 where (a,b)>=(1,1) and c=3;
212select * from t1;
213
214replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
215delete from t1 where (a=1 or a=2 or a=3) and c>=1;
216select * from t1;
217
218replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
219delete from t1 where (a=1 or a=2 or a=3) and c<1;
220select * from t1;
221
222replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
223delete from t1 where (a=1 or a=2 or a=3) and (b=2 or b=3);
224select * from t1;
225
226replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
227delete from t1 where (a=1 or a=2 or a=3) and (b=2 or b=3) and c=3;
228select * from t1;
229
230replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
231delete from t1 where a>=0 and a<=3 and b>1 and b<3;
232select * from t1;
233
234replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
235delete from t1 where (c,d)>=(1,1);
236select * from t1;
237
238replace into t1(a,b,c,d) values(1,1,1,1),(2,2,2,1),(3,3,3,1);
239delete from t1 where (b,a) > (1,1);
240select * from t1;
241
242####CASE:multi rowkeys
243--disable_warnings
244drop table if exists t1, t2, t3;
245--enable_warnings
246#int
247create table t1(a int, b int, c int, d int, primary key(a,b,c));
248insert into t1(a,b,c) values (1,1,1),(2,2,2),(3,3,3);
249delete from t1 where (a,b,c)>(0,0,0) and (a,b,c)<=(3,3,3);
250select * from t1;
251#varchar
252create table t2(a varchar(128), b varchar(128), c varchar(128), d varchar(128), primary key(a,b,c));
253insert into t2(a,b,c) values ('a','a','a'),('b','b','b'),('c','c','c');
254delete from t2 where (a,b,c)>=('a','a','b') and (a,b,c)<('b','b','c');
255select * from t2;
256#timestamp
257create table t3(a int, b varchar(128), c timestamp(6) default "2012-01-01 12:00:00", d int, primary key(a,b,c));
258insert into t3(a,b,c) values (1,'a','2014-02-17'),(2,'b','2014-02-17'),(3,'c','2014-02-18');
259delete from t3 where (a,b,c)>=(1,'a','2014-02-17 00:00:00') and (a,b,c)<=(2,'b','2014-02-18');
260select * from t3;
261
262--disable_warnings
263drop table if exists t1, t2, t3;
264--enable_warnings
265