~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Check for problems with delete
3
#
4
5
--disable_warnings
6
drop table if exists t1,t2,t3,t11,t12;
7
--enable_warnings
396 by Brian Aker
Cleanup tiny and small int.
8
CREATE TABLE t1 (a int, b int);
1 by brian
clean slate
9
INSERT INTO t1 VALUES (1,1);
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
10
INSERT INTO t1 VALUES (1,2);
1 by brian
clean slate
11
INSERT INTO t1 VALUES (1,3);
12
DELETE from t1 where a=1 limit 1;
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
13
DELETE from t1 where a=1;
1 by brian
clean slate
14
15
INSERT INTO t1 VALUES (1,1);
16
DELETE from t1;
17
INSERT INTO t1 VALUES (1,2);
18
DELETE from t1;
19
INSERT INTO t1 VALUES (1,2);
20
SET AUTOCOMMIT=0;
21
DELETE from t1;
22
SET AUTOCOMMIT=1;
23
drop table t1;
24
25
#
26
# Test of delete when the delete will cause a node to disappear and reappear
27
# (This assumes a block size of 1024)
28
#
29
30
create table t1 (
31
	a bigint not null,
32
	b bigint not null default 0,
33
	c bigint not null default 0,
34
	d bigint not null default 0,
35
	e bigint not null default 0,
36
	f bigint not null default 0,
37
	g bigint not null default 0,
38
	h bigint not null default 0,
39
	i bigint not null default 0,
40
	j bigint not null default 0,
41
	primary key (a,b,c,d,e,f,g,h,i,j));
42
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23);
43
delete from t1 where a=26;
44
drop table t1;
45
create table t1 (
46
	a bigint not null,
47
	b bigint not null default 0,
48
	c bigint not null default 0,
49
	d bigint not null default 0,
50
	e bigint not null default 0,
51
	f bigint not null default 0,
52
	g bigint not null default 0,
53
	h bigint not null default 0,
54
	i bigint not null default 0,
55
	j bigint not null default 0,
56
	primary key (a,b,c,d,e,f,g,h,i,j));
57
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27);
58
delete from t1 where a=27;
59
drop table t1;
60
61
CREATE TABLE `t1` (
223 by Brian Aker
Cleanup int() work.
62
  `i` int NOT NULL default '0',
63
  `i2` int NOT NULL default '0',
1 by brian
clean slate
64
  PRIMARY KEY  (`i`)
65
);
66
-- error 1054
67
DELETE FROM t1 USING t1 WHERE post='1';
68
drop table t1;
69
70
#
71
# CHAR(0) bug - not actually DELETE bug, but anyway...
72
#
73
1063.9.3 by Brian Aker
Partial fix for tests for tmp
74
CREATE TEMPORARY TABLE t1 (
1 by brian
clean slate
75
  bool     char(0) default NULL,
76
  not_null varchar(20) binary NOT NULL default '',
77
  misc     integer not null,
78
  PRIMARY KEY  (not_null)
79
) ENGINE=MyISAM;
80
81
INSERT INTO t1 VALUES (NULL,'a',4), (NULL,'b',5), (NULL,'c',6), (NULL,'d',7);
82
83
select * from t1 where misc > 5 and bool is null;
84
delete   from t1 where misc > 5 and bool is null;
85
select * from t1 where misc > 5 and bool is null;
86
87
select count(*) from t1;
88
delete from t1 where 1 > 2;
89
select count(*) from t1;
90
delete from t1 where 3 > 2;
91
select count(*) from t1;
92
93
drop table t1;
94
#
95
# Bug #5733: Table handler error with self-join multi-table DELETE
96
#
97
98
create table t1 (a int not null auto_increment primary key, b char(32));
99
insert into t1 (b) values ('apple'), ('apple');
100
select * from t1;
101
delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a;
102
select * from t1;
103
drop table t1;
104
105
#
106
# IGNORE option
107
#
108
create table t11 (a int NOT NULL, b int, primary key (a));
109
create table t12 (a int NOT NULL, b int, primary key (a));
110
create table t2 (a int NOT NULL, b int, primary key (a));
111
insert into t11 values (0, 10),(1, 11),(2, 12);
112
insert into t12 values (33, 10),(0, 11),(2, 12);
113
insert into t2 values (1, 21),(2, 12),(3, 23);
114
select * from t11;
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
115
--sorted_result
1 by brian
clean slate
116
select * from t12;
117
select * from t2;
118
-- error 1242
119
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
120
select * from t11;
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
121
--sorted_result
1 by brian
clean slate
122
select * from t12;
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
123
# PBXT: for some reason this returns 2 warnings instead of 1
1 by brian
clean slate
124
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
125
select * from t11;
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
126
--sorted_result
1 by brian
clean slate
127
select * from t12;
128
insert into t11 values (2, 12);
129
-- error 1242
130
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
131
select * from t11;
132
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
133
select * from t11;
134
drop table t11, t12, t2;
135
136
#
137
# Bug #4198: deletion and KEYREAD
138
#
139
140
create table t1 (a int, b int, unique key (a), key (b));
141
insert into t1 values (3, 3), (7, 7);
142
delete t1 from t1 where a = 3;
143
check table t1;
144
select * from t1;
145
drop table t1;
146
147
#
148
# Bug #8392: delete with ORDER BY containing a direct reference to the table 
149
#
150
 
151
CREATE TABLE t1 ( a int PRIMARY KEY );
152
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
153
INSERT INTO t1 VALUES (0),(1),(2);
154
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
155
SELECT * FROM t1;
156
DROP TABLE t1;
157
158
#
159
# Bug #21392: multi-table delete with alias table name fails with 
160
# 1003: Incorrect table name
161
#
162
163
create table t1 (a int);
164
delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5;
165
delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5;
166
drop table t1;
167
168
#
169
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
170
#            non-restricting WHERE is present.
171
#
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
172
# PBXT is different here. @a = 2 instead of 1. I think the
173
# reason is because an index is not used, as done with
174
# InnoDB. This may be due to lack of cluster index. If the
175
# delete below is based on a secondary index then the
176
# index is not used
1 by brian
clean slate
177
create table t1(f1 int primary key);
178
insert into t1 values (4),(3),(1),(2);
179
delete from t1 where (@a:= f1) order by f1 limit 1;
180
select @a;
181
drop table t1;
182
183
# BUG#30385 "Server crash when deleting with order by and limit"
184
CREATE TABLE t1 (
185
  `date` date ,
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
186
  `seq` int NOT NULL auto_increment,
1 by brian
clean slate
187
  PRIMARY KEY  (`seq`),
188
  KEY `seq` (`seq`),
189
  KEY `date` (`date`)
190
);
896.5.1 by Jay Pipes
Removes the TIME column type and related time functions.
191
DELETE FROM t1 ORDER BY date ASC LIMIT 1;
1 by brian
clean slate
192
drop table t1;
193
194
--echo End of 4.1 tests
195
196
#
197
# Test of multi-delete where we are not scanning the first table
198
#
199
200
CREATE TABLE t1 (a int not null,b int not null);
201
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b));
202
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));
203
insert into t1 values (1,1),(2,1),(1,3);
204
insert into t2 values (1,1),(2,2),(3,3);
205
insert into t3 values (1,1),(2,1),(1,3);
206
select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
207
explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
208
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
209
# This should be empty
210
select * from t3;
211
drop table t1,t2,t3;
212
213
#
214
# Bug #26186: delete order by, sometimes accept unknown column
215
#
216
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
217
218
--error ER_BAD_FIELD_ERROR
219
DELETE FROM t1 ORDER BY x;
220
221
# even columns from a table not used in query (and not even existing)
222
--error ER_BAD_FIELD_ERROR
223
DELETE FROM t1 ORDER BY t2.x;
224
225
# subquery (as long as the subquery from is valid or DUAL)
226
--error ER_BAD_FIELD_ERROR
227
DELETE FROM t1 ORDER BY (SELECT x);
228
229
DROP TABLE t1;
230
231
#
232
# Bug #30234: Unexpected behavior using DELETE with AS and USING
233
# '
234
CREATE TABLE t1 (
235
  a INT
236
);
237
238
CREATE TABLE t2 (
239
  a INT
240
);
241
242
CREATE DATABASE db1;
243
CREATE TABLE db1.t1 (
244
  a INT
245
);
246
INSERT INTO db1.t1 (a) SELECT * FROM t1;
247
248
CREATE DATABASE db2;
249
CREATE TABLE db2.t1 (
250
  a INT
251
);
252
INSERT INTO db2.t1 (a) SELECT * FROM t2;
253
254
--error ER_PARSE_ERROR
255
DELETE FROM t1 alias USING t1, t2 alias WHERE t1.a = alias.a;
256
DELETE FROM alias USING t1, t2 alias WHERE t1.a = alias.a;
257
DELETE FROM t1, alias USING t1, t2 alias WHERE t1.a = alias.a;
258
--error ER_UNKNOWN_TABLE
259
DELETE FROM t1, t2 USING t1, t2 alias WHERE t1.a = alias.a;
260
--error ER_PARSE_ERROR
261
DELETE FROM db1.t1 alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
262
DELETE FROM alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
263
--error ER_UNKNOWN_TABLE
264
DELETE FROM db2.alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
265
DELETE FROM t1 USING t1 WHERE a = 1;
266
SELECT * FROM t1;
267
--error ER_PARSE_ERROR
268
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
269
SELECT * FROM t1;
270
271
DROP TABLE t1, t2;
272
DROP DATABASE db1;
273
DROP DATABASE db2;
274
275
--echo End of 5.0 tests
276
277
#
278
# Bug#27525: table not found when using multi-table-deletes with aliases over
279
#            several databas
280
# Bug#21148: MULTI-DELETE fails to resolve a table by alias if it's from a
281
#            different database
282
#
283
284
--disable_warnings
285
DROP DATABASE IF EXISTS db1;
286
DROP DATABASE IF EXISTS db2;
287
DROP DATABASE IF EXISTS db3;
288
DROP DATABASE IF EXISTS db4;
289
DROP TABLE IF EXISTS t1, t2;
290
--enable_warnings
291
USE test;
292
CREATE DATABASE db1;
293
CREATE DATABASE db2;
294
295
CREATE TABLE db1.t1 (a INT, b INT);
296
INSERT INTO db1.t1 VALUES (1,1),(2,2),(3,3);
297
CREATE TABLE db1.t2 AS SELECT * FROM db1.t1;
298
CREATE TABLE db2.t1 AS SELECT * FROM db1.t2;
299
CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
300
CREATE TABLE t1 AS SELECT * FROM db2.t2;
301
CREATE TABLE t2 AS SELECT * FROM t1;
302
303
#
304
# Testing without a selected database
305
#
306
307
CREATE DATABASE db3;
308
USE db3;
309
DROP DATABASE db3;
310
--error ER_NO_DB_ERROR
311
SELECT * FROM t1;
312
313
# Detect missing table references
314
315
--error ER_NO_DB_ERROR
316
DELETE a1,a2 FROM db1.t1, db2.t2;
317
--error ER_NO_DB_ERROR
318
DELETE a1,a2 FROM db1.t1, db2.t2;
319
--error ER_NO_DB_ERROR
320
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
321
--error ER_NO_DB_ERROR
322
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
323
--error ER_NO_DB_ERROR
324
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
325
--error ER_NO_DB_ERROR
326
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
327
328
--error ER_NO_DB_ERROR
329
DELETE FROM a1,a2 USING db1.t1, db2.t2;
330
--error ER_NO_DB_ERROR
331
DELETE FROM a1,a2 USING db1.t1, db2.t2;
332
--error ER_NO_DB_ERROR
333
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
334
--error ER_NO_DB_ERROR
335
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
336
--error ER_NO_DB_ERROR
337
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
338
--error ER_NO_DB_ERROR
339
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
340
341
# Ambiguous table references
342
343
--error ER_NO_DB_ERROR
344
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
345
--error ER_NO_DB_ERROR
346
DELETE a1 FROM db1.a1, db2.t2 AS a1;
347
--error ER_NO_DB_ERROR
348
DELETE a1 FROM a1, db1.t1 AS a1;
349
--error ER_NO_DB_ERROR
350
DELETE t1 FROM db1.t1, db2.t1 AS a1;
351
--error ER_NO_DB_ERROR
352
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
353
--error ER_NO_DB_ERROR
354
DELETE t1 FROM db1.t1, db2.t1;
355
356
# Test all again, now with a selected database
357
358
USE test;
359
360
# Detect missing table references
361
362
--error ER_UNKNOWN_TABLE
363
DELETE a1,a2 FROM db1.t1, db2.t2;
364
--error ER_UNKNOWN_TABLE
365
DELETE a1,a2 FROM db1.t1, db2.t2;
366
--error ER_UNKNOWN_TABLE
367
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
368
--error ER_UNKNOWN_TABLE
369
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
370
--error ER_NO_SUCH_TABLE
371
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
372
--error ER_NO_SUCH_TABLE
373
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
374
375
--error ER_UNKNOWN_TABLE
376
DELETE FROM a1,a2 USING db1.t1, db2.t2;
377
--error ER_UNKNOWN_TABLE
378
DELETE FROM a1,a2 USING db1.t1, db2.t2;
379
--error ER_UNKNOWN_TABLE
380
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
381
--error ER_UNKNOWN_TABLE
382
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
383
--error ER_NO_SUCH_TABLE
384
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
385
--error ER_NO_SUCH_TABLE
386
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
387
388
# Ambiguous table references
389
390
--error ER_NONUNIQ_TABLE
391
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
392
--error ER_NO_SUCH_TABLE
393
DELETE a1 FROM db1.a1, db2.t2 AS a1;
394
--error ER_NONUNIQ_TABLE
395
DELETE a1 FROM a1, db1.t1 AS a1;
396
--error ER_UNKNOWN_TABLE
397
DELETE t1 FROM db1.t1, db2.t1 AS a1;
398
--error ER_UNKNOWN_TABLE
399
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
400
--error ER_UNKNOWN_TABLE
401
DELETE t1 FROM db1.t1, db2.t1;
402
403
# Test multiple-table cross database deletes
404
405
DELETE t1 FROM db1.t2 AS t1, db2.t2 AS t2 WHERE t2.a = 1 AND t1.a = t2.a;
406
SELECT ROW_COUNT();
407
DELETE a1, a2 FROM db2.t1 AS a1, t2 AS a2 WHERE a1.a = 2 AND a2.a = 2;
408
SELECT ROW_COUNT();
409
410
DROP DATABASE db1;
411
DROP DATABASE db2;
412
DROP TABLE t1, t2;