~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/delete.test

Fixed sql_builtin in the right place.

Show diffs side-by-side

added added

removed removed

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