~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1,t2,t3,t11,t12;
2
CREATE TABLE t1 (a tinyint(3), b tinyint(5));
3
INSERT INTO t1 VALUES (1,1);
4
INSERT LOW_PRIORITY INTO t1 VALUES (1,2);
5
INSERT INTO t1 VALUES (1,3);
6
DELETE from t1 where a=1 limit 1;
7
DELETE LOW_PRIORITY from t1 where a=1;
8
INSERT INTO t1 VALUES (1,1);
9
DELETE from t1;
10
LOCK TABLE t1 write;
11
INSERT INTO t1 VALUES (1,2);
12
DELETE from t1;
13
UNLOCK TABLES;
14
INSERT INTO t1 VALUES (1,2);
15
SET AUTOCOMMIT=0;
16
DELETE from t1;
17
SET AUTOCOMMIT=1;
18
drop table t1;
19
create table t1 (
20
a bigint not null,
21
b bigint not null default 0,
22
c bigint not null default 0,
23
d bigint not null default 0,
24
e bigint not null default 0,
25
f bigint not null default 0,
26
g bigint not null default 0,
27
h bigint not null default 0,
28
i bigint not null default 0,
29
j bigint not null default 0,
30
primary key (a,b,c,d,e,f,g,h,i,j));
31
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23);
32
delete from t1 where a=26;
33
drop table t1;
34
create table t1 (
35
a bigint not null,
36
b bigint not null default 0,
37
c bigint not null default 0,
38
d bigint not null default 0,
39
e bigint not null default 0,
40
f bigint not null default 0,
41
g bigint not null default 0,
42
h bigint not null default 0,
43
i bigint not null default 0,
44
j bigint not null default 0,
45
primary key (a,b,c,d,e,f,g,h,i,j));
46
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27);
47
delete from t1 where a=27;
48
drop table t1;
49
CREATE TABLE `t1` (
50
`i` int(10) NOT NULL default '0',
51
`i2` int(10) NOT NULL default '0',
52
PRIMARY KEY  (`i`)
53
);
54
DELETE FROM t1 USING t1 WHERE post='1';
55
ERROR 42S22: Unknown column 'post' in 'where clause'
56
drop table t1;
57
CREATE TABLE t1 (
58
bool     char(0) default NULL,
59
not_null varchar(20) binary NOT NULL default '',
60
misc     integer not null,
61
PRIMARY KEY  (not_null)
62
) ENGINE=MyISAM;
63
INSERT INTO t1 VALUES (NULL,'a',4), (NULL,'b',5), (NULL,'c',6), (NULL,'d',7);
64
select * from t1 where misc > 5 and bool is null;
65
bool	not_null	misc
66
NULL	c	6
67
NULL	d	7
68
delete   from t1 where misc > 5 and bool is null;
69
select * from t1 where misc > 5 and bool is null;
70
bool	not_null	misc
71
select count(*) from t1;
72
count(*)
73
2
74
delete from t1 where 1 > 2;
75
select count(*) from t1;
76
count(*)
77
2
78
delete from t1 where 3 > 2;
79
select count(*) from t1;
80
count(*)
81
0
82
drop table t1;
83
create table t1 (a int not null auto_increment primary key, b char(32));
84
insert into t1 (b) values ('apple'), ('apple');
85
select * from t1;
86
a	b
87
1	apple
88
2	apple
89
delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a;
90
select * from t1;
91
a	b
92
1	apple
93
drop table t1;
94
create table t11 (a int NOT NULL, b int, primary key (a));
95
create table t12 (a int NOT NULL, b int, primary key (a));
96
create table t2 (a int NOT NULL, b int, primary key (a));
97
insert into t11 values (0, 10),(1, 11),(2, 12);
98
insert into t12 values (33, 10),(0, 11),(2, 12);
99
insert into t2 values (1, 21),(2, 12),(3, 23);
100
select * from t11;
101
a	b
102
0	10
103
1	11
104
2	12
105
select * from t12;
106
a	b
107
33	10
108
0	11
109
2	12
110
select * from t2;
111
a	b
112
1	21
113
2	12
114
3	23
115
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
116
ERROR 21000: Subquery returns more than 1 row
117
select * from t11;
118
a	b
119
0	10
120
1	11
121
2	12
122
select * from t12;
123
a	b
124
33	10
125
0	11
126
2	12
127
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
128
Warnings:
129
Error	1242	Subquery returns more than 1 row
130
Error	1242	Subquery returns more than 1 row
131
select * from t11;
132
a	b
133
0	10
134
1	11
135
select * from t12;
136
a	b
137
33	10
138
0	11
139
insert into t11 values (2, 12);
140
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
141
ERROR 21000: Subquery returns more than 1 row
142
select * from t11;
143
a	b
144
0	10
145
1	11
146
2	12
147
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
148
Warnings:
149
Error	1242	Subquery returns more than 1 row
150
Error	1242	Subquery returns more than 1 row
151
select * from t11;
152
a	b
153
0	10
154
1	11
155
drop table t11, t12, t2;
156
create table t1 (a int, b int, unique key (a), key (b));
157
insert into t1 values (3, 3), (7, 7);
158
delete t1 from t1 where a = 3;
159
check table t1;
160
Table	Op	Msg_type	Msg_text
161
test.t1	check	status	OK
162
select * from t1;
163
a	b
164
7	7
165
drop table t1;
166
CREATE TABLE t1 ( a int PRIMARY KEY );
167
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
168
INSERT INTO t1 VALUES (0),(1),(2);
169
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
170
SELECT * FROM t1;
171
a
172
0
173
2
174
DROP TABLE t1;
175
create table t1 (a int);
176
delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5;
177
delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5;
178
drop table t1;
179
create table t1(f1 int primary key);
180
insert into t1 values (4),(3),(1),(2);
181
delete from t1 where (@a:= f1) order by f1 limit 1;
182
select @a;
183
@a
184
1
185
drop table t1;
186
CREATE TABLE t1 (
187
`date` date ,
188
`time` time ,
189
`seq` int(10) unsigned NOT NULL auto_increment,
190
PRIMARY KEY  (`seq`),
191
KEY `seq` (`seq`),
192
KEY `time` (`time`),
193
KEY `date` (`date`)
194
);
195
DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1;
196
drop table t1;
197
End of 4.1 tests
198
CREATE TABLE t1 (a int not null,b int not null);
199
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b));
200
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));
201
insert into t1 values (1,1),(2,1),(1,3);
202
insert into t2 values (1,1),(2,2),(3,3);
203
insert into t3 values (1,1),(2,1),(1,3);
204
select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
205
a	b	a	b	a	b
206
1	1	1	1	1	1
207
2	1	2	2	2	1
208
1	3	1	1	1	3
209
explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
210
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
211
1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	
212
1	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a	1	Using index
213
1	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.b,test.t1.b	1	Using index
214
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
215
select * from t3;
216
a	b
217
drop table t1,t2,t3;
218
create table t1(a date not null);
219
insert into t1 values (0);
220
select * from t1 where a is null;
221
a
222
0000-00-00
223
delete from t1 where a is null;
224
select count(*) from t1;
225
count(*)
226
0
227
drop table t1;
228
CREATE TABLE t1 (a INT);
229
INSERT INTO t1 VALUES (1);
230
DELETE FROM t1 ORDER BY x;
231
ERROR 42S22: Unknown column 'x' in 'order clause'
232
DELETE FROM t1 ORDER BY t2.x;
233
ERROR 42S22: Unknown column 't2.x' in 'order clause'
234
DELETE FROM t1 ORDER BY (SELECT x);
235
ERROR 42S22: Unknown column 'x' in 'field list'
236
DROP TABLE t1;
237
CREATE TABLE t1 (
238
a INT
239
);
240
CREATE TABLE t2 (
241
a INT
242
);
243
CREATE DATABASE db1;
244
CREATE TABLE db1.t1 (
245
a INT
246
);
247
INSERT INTO db1.t1 (a) SELECT * FROM t1;
248
CREATE DATABASE db2;
249
CREATE TABLE db2.t1 (
250
a INT
251
);
252
INSERT INTO db2.t1 (a) SELECT * FROM t2;
253
DELETE FROM t1 alias USING t1, t2 alias WHERE t1.a = alias.a;
254
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'alias USING t1, t2 alias WHERE t1.a = alias.a' at line 1
255
DELETE FROM alias USING t1, t2 alias WHERE t1.a = alias.a;
256
DELETE FROM t1, alias USING t1, t2 alias WHERE t1.a = alias.a;
257
DELETE FROM t1, t2 USING t1, t2 alias WHERE t1.a = alias.a;
258
ERROR 42S02: Unknown table 't2' in MULTI DELETE
259
DELETE FROM db1.t1 alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
260
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a' at line 1
261
DELETE FROM alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
262
DELETE FROM db2.alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
263
ERROR 42S02: Unknown table 'alias' in MULTI DELETE
264
DELETE FROM t1 USING t1 WHERE a = 1;
265
SELECT * FROM t1;
266
a
267
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
268
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'alias USING t1 alias WHERE a = 2' at line 1
269
SELECT * FROM t1;
270
a
271
DROP TABLE t1, t2;
272
DROP DATABASE db1;
273
DROP DATABASE db2;
274
End of 5.0 tests
275
DROP DATABASE IF EXISTS db1;
276
DROP DATABASE IF EXISTS db2;
277
DROP DATABASE IF EXISTS db3;
278
DROP DATABASE IF EXISTS db4;
279
DROP TABLE IF EXISTS t1, t2;
280
USE test;
281
CREATE DATABASE db1;
282
CREATE DATABASE db2;
283
CREATE TABLE db1.t1 (a INT, b INT);
284
INSERT INTO db1.t1 VALUES (1,1),(2,2),(3,3);
285
CREATE TABLE db1.t2 AS SELECT * FROM db1.t1;
286
CREATE TABLE db2.t1 AS SELECT * FROM db1.t2;
287
CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
288
CREATE TABLE t1 AS SELECT * FROM db2.t2;
289
CREATE TABLE t2 AS SELECT * FROM t1;
290
CREATE DATABASE db3;
291
USE db3;
292
DROP DATABASE db3;
293
SELECT * FROM t1;
294
ERROR 3D000: No database selected
295
DELETE a1,a2 FROM db1.t1, db2.t2;
296
ERROR 3D000: No database selected
297
DELETE a1,a2 FROM db1.t1, db2.t2;
298
ERROR 3D000: No database selected
299
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
300
ERROR 3D000: No database selected
301
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
302
ERROR 3D000: No database selected
303
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
304
ERROR 3D000: No database selected
305
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
306
ERROR 3D000: No database selected
307
DELETE FROM a1,a2 USING db1.t1, db2.t2;
308
ERROR 3D000: No database selected
309
DELETE FROM a1,a2 USING db1.t1, db2.t2;
310
ERROR 3D000: No database selected
311
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
312
ERROR 3D000: No database selected
313
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
314
ERROR 3D000: No database selected
315
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
316
ERROR 3D000: No database selected
317
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
318
ERROR 3D000: No database selected
319
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
320
ERROR 3D000: No database selected
321
DELETE a1 FROM db1.a1, db2.t2 AS a1;
322
ERROR 3D000: No database selected
323
DELETE a1 FROM a1, db1.t1 AS a1;
324
ERROR 3D000: No database selected
325
DELETE t1 FROM db1.t1, db2.t1 AS a1;
326
ERROR 3D000: No database selected
327
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
328
ERROR 3D000: No database selected
329
DELETE t1 FROM db1.t1, db2.t1;
330
ERROR 3D000: No database selected
331
USE test;
332
DELETE a1,a2 FROM db1.t1, db2.t2;
333
ERROR 42S02: Unknown table 'a1' in MULTI DELETE
334
DELETE a1,a2 FROM db1.t1, db2.t2;
335
ERROR 42S02: Unknown table 'a1' in MULTI DELETE
336
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
337
ERROR 42S02: Unknown table 'a2' in MULTI DELETE
338
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
339
ERROR 42S02: Unknown table 'a1' in MULTI DELETE
340
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
341
ERROR 42S02: Table 'db3.t1' doesn't exist
342
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
343
ERROR 42S02: Table 'db3.t1' doesn't exist
344
DELETE FROM a1,a2 USING db1.t1, db2.t2;
345
ERROR 42S02: Unknown table 'a1' in MULTI DELETE
346
DELETE FROM a1,a2 USING db1.t1, db2.t2;
347
ERROR 42S02: Unknown table 'a1' in MULTI DELETE
348
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
349
ERROR 42S02: Unknown table 'a2' in MULTI DELETE
350
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
351
ERROR 42S02: Unknown table 'a1' in MULTI DELETE
352
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
353
ERROR 42S02: Table 'db3.t1' doesn't exist
354
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
355
ERROR 42S02: Table 'db3.t1' doesn't exist
356
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
357
ERROR 42000: Not unique table/alias: 'a1'
358
DELETE a1 FROM db1.a1, db2.t2 AS a1;
359
ERROR 42S02: Table 'db1.a1' doesn't exist
360
DELETE a1 FROM a1, db1.t1 AS a1;
361
ERROR 42000: Not unique table/alias: 'a1'
362
DELETE t1 FROM db1.t1, db2.t1 AS a1;
363
ERROR 42S02: Unknown table 't1' in MULTI DELETE
364
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
365
ERROR 42S02: Unknown table 't1' in MULTI DELETE
366
DELETE t1 FROM db1.t1, db2.t1;
367
ERROR 42S02: Unknown table 't1' in MULTI DELETE
368
DELETE t1 FROM db1.t2 AS t1, db2.t2 AS t2 WHERE t2.a = 1 AND t1.a = t2.a;
369
SELECT ROW_COUNT();
370
ROW_COUNT()
371
1
372
DELETE a1, a2 FROM db2.t1 AS a1, t2 AS a2 WHERE a1.a = 2 AND a2.a = 2;
373
SELECT ROW_COUNT();
374
ROW_COUNT()
375
2
376
DROP DATABASE db1;
377
DROP DATABASE db2;
378
DROP TABLE t1, t2;