~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/delete.test

  • Committer: Brian Aker
  • Date: 2010-12-08 22:35:56 UTC
  • mfrom: (1819.9.158 update-innobase)
  • Revision ID: brian@tangent.org-20101208223556-37mi4omqg7lkjzf3
Merge in Stewart's changes, 1.3 changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
--enable_warnings
8
8
CREATE TABLE t1 (a int, b int);
9
9
INSERT INTO t1 VALUES (1,1);
10
 
INSERT LOW_PRIORITY INTO t1 VALUES (1,2);
 
10
INSERT INTO t1 VALUES (1,2);
11
11
INSERT INTO t1 VALUES (1,3);
12
12
DELETE from t1 where a=1 limit 1;
13
 
DELETE LOW_PRIORITY from t1 where a=1;
 
13
DELETE from t1 where a=1;
14
14
 
15
15
INSERT INTO t1 VALUES (1,1);
16
16
DELETE from t1;
17
 
LOCK TABLE t1 write;
18
17
INSERT INTO t1 VALUES (1,2);
19
18
DELETE from t1;
20
 
UNLOCK TABLES;
21
19
INSERT INTO t1 VALUES (1,2);
22
20
SET AUTOCOMMIT=0;
23
21
DELETE from t1;
65
63
  `i2` int NOT NULL default '0',
66
64
  PRIMARY KEY  (`i`)
67
65
);
68
 
DELETE FROM t1 USING t1 WHERE post='1';
69
66
drop table t1;
70
67
 
71
68
#
72
69
# CHAR(0) bug - not actually DELETE bug, but anyway...
73
70
#
74
71
 
75
 
CREATE TABLE t1 (
 
72
CREATE TEMPORARY TABLE t1 (
76
73
  bool     char(0) default NULL,
77
 
  not_null varchar(20) binary NOT NULL default '',
 
74
  not_null varchar(20) NOT NULL default '',
78
75
  misc     integer not null,
79
76
  PRIMARY KEY  (not_null)
80
77
) ENGINE=MyISAM;
93
89
select count(*) from t1;
94
90
 
95
91
drop table t1;
96
 
#
97
 
# Bug #5733: Table handler error with self-join multi-table DELETE
98
 
#
99
 
 
100
 
create table t1 (a int not null auto_increment primary key, b char(32));
101
 
insert into t1 (b) values ('apple'), ('apple');
102
 
select * from t1;
103
 
delete t1 from t1, t1 as t2 where t1.b = t2.b and t1.a > t2.a;
104
 
select * from t1;
105
 
drop table t1;
106
92
 
107
93
#
108
94
# IGNORE option
117
103
--sorted_result
118
104
select * from t12;
119
105
select * from t2;
120
 
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
121
 
select * from t11;
122
 
--sorted_result
123
 
select * from t12;
124
 
# PBXT: for some reason this returns 2 warnings instead of 1
125
 
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
126
 
select * from t11;
127
 
--sorted_result
128
 
select * from t12;
129
 
insert into t11 values (2, 12);
 
106
select * from t11;
 
107
--sorted_result
 
108
select * from t12;
 
109
select * from t11;
 
110
--sorted_result
 
111
select * from t12;
130
112
-- error 1242
131
113
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
132
114
select * from t11;
133
 
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
 
115
 
 
116
# PBXT doesn't currently support DELETE IGNORE and turns it into plain DELETE
 
117
if (`select if (@@storage_engine = 'PBXT', 0, 1)`) { 
 
118
  delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
 
119
}
134
120
select * from t11;
135
121
drop table t11, t12, t2;
136
122
 
141
126
 
142
127
create table t1 (a int, b int, unique key (a), key (b));
143
128
insert into t1 values (3, 3), (7, 7);
144
 
delete t1 from t1 where a = 3;
 
129
delete from t1 where a = 3;
145
130
check table t1;
146
131
select * from t1;
147
132
drop table t1;
158
143
DROP TABLE t1;
159
144
 
160
145
#
161
 
# Bug #21392: multi-table delete with alias table name fails with 
162
 
# 1003: Incorrect table name
163
 
#
164
 
 
165
 
create table t1 (a int);
166
 
delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5;
167
 
delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5;
168
 
drop table t1;
169
 
 
170
 
#
171
146
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
172
147
#            non-restricting WHERE is present.
173
148
#
185
160
# BUG#30385 "Server crash when deleting with order by and limit"
186
161
CREATE TABLE t1 (
187
162
  `date` date ,
188
 
  `time` time ,
189
163
  `seq` int NOT NULL auto_increment,
190
164
  PRIMARY KEY  (`seq`),
191
165
  KEY `seq` (`seq`),
192
 
  KEY `time` (`time`),
193
166
  KEY `date` (`date`)
194
167
);
195
 
DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1;
 
168
DELETE FROM t1 ORDER BY date ASC LIMIT 1;
196
169
drop table t1;
197
170
 
198
171
--echo End of 4.1 tests
199
172
 
200
173
#
201
 
# Test of multi-delete where we are not scanning the first table
202
 
#
203
 
 
204
 
CREATE TABLE t1 (a int not null,b int not null);
205
 
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b));
206
 
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));
207
 
insert into t1 values (1,1),(2,1),(1,3);
208
 
insert into t2 values (1,1),(2,2),(3,3);
209
 
insert into t3 values (1,1),(2,1),(1,3);
210
 
select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
211
 
explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
212
 
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
213
 
# This should be empty
214
 
select * from t3;
215
 
drop table t1,t2,t3;
216
 
 
217
 
#
218
 
# Bug #8143: deleting '0000-00-00' values using IS NULL
219
 
#
220
 
 
221
 
create table t1(a date not null);
222
 
insert into t1 values (0);
223
 
select * from t1 where a is null;
224
 
delete from t1 where a is null;
225
 
select count(*) from t1;
226
 
drop table t1;
227
 
 
228
 
#
229
174
# Bug #26186: delete order by, sometimes accept unknown column
230
175
#
231
176
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
266
211
);
267
212
INSERT INTO db2.t1 (a) SELECT * FROM t2;
268
213
 
269
 
--error ER_PARSE_ERROR
270
 
DELETE FROM t1 alias USING t1, t2 alias WHERE t1.a = alias.a;
271
 
DELETE FROM alias USING t1, t2 alias WHERE t1.a = alias.a;
272
 
DELETE FROM t1, alias USING t1, t2 alias WHERE t1.a = alias.a;
273
 
--error ER_UNKNOWN_TABLE
274
 
DELETE FROM t1, t2 USING t1, t2 alias WHERE t1.a = alias.a;
275
 
--error ER_PARSE_ERROR
276
 
DELETE FROM db1.t1 alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
277
 
DELETE FROM alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
278
 
--error ER_UNKNOWN_TABLE
279
 
DELETE FROM db2.alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
280
 
DELETE FROM t1 USING t1 WHERE a = 1;
281
214
SELECT * FROM t1;
282
215
--error ER_PARSE_ERROR
283
216
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
315
248
CREATE TABLE t1 AS SELECT * FROM db2.t2;
316
249
CREATE TABLE t2 AS SELECT * FROM t1;
317
250
 
318
 
#
319
 
# Testing without a selected database
320
 
#
321
 
 
322
 
CREATE DATABASE db3;
323
 
USE db3;
324
 
DROP DATABASE db3;
325
 
--error ER_NO_DB_ERROR
326
 
SELECT * FROM t1;
327
 
 
328
 
# Detect missing table references
329
 
 
330
 
--error ER_NO_DB_ERROR
331
 
DELETE a1,a2 FROM db1.t1, db2.t2;
332
 
--error ER_NO_DB_ERROR
333
 
DELETE a1,a2 FROM db1.t1, db2.t2;
334
 
--error ER_NO_DB_ERROR
335
 
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
336
 
--error ER_NO_DB_ERROR
337
 
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
338
 
--error ER_NO_DB_ERROR
339
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
340
 
--error ER_NO_DB_ERROR
341
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
342
 
 
343
 
--error ER_NO_DB_ERROR
344
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
345
 
--error ER_NO_DB_ERROR
346
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
347
 
--error ER_NO_DB_ERROR
348
 
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
349
 
--error ER_NO_DB_ERROR
350
 
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
351
 
--error ER_NO_DB_ERROR
352
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
353
 
--error ER_NO_DB_ERROR
354
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
355
 
 
356
 
# Ambiguous table references
357
 
 
358
 
--error ER_NO_DB_ERROR
359
 
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
360
 
--error ER_NO_DB_ERROR
361
 
DELETE a1 FROM db1.a1, db2.t2 AS a1;
362
 
--error ER_NO_DB_ERROR
363
 
DELETE a1 FROM a1, db1.t1 AS a1;
364
 
--error ER_NO_DB_ERROR
365
 
DELETE t1 FROM db1.t1, db2.t1 AS a1;
366
 
--error ER_NO_DB_ERROR
367
 
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
368
 
--error ER_NO_DB_ERROR
369
 
DELETE t1 FROM db1.t1, db2.t1;
370
 
 
371
 
# Test all again, now with a selected database
372
 
 
373
 
USE test;
374
 
 
375
 
# Detect missing table references
376
 
 
377
 
--error ER_UNKNOWN_TABLE
378
 
DELETE a1,a2 FROM db1.t1, db2.t2;
379
 
--error ER_UNKNOWN_TABLE
380
 
DELETE a1,a2 FROM db1.t1, db2.t2;
381
 
--error ER_UNKNOWN_TABLE
382
 
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
383
 
--error ER_UNKNOWN_TABLE
384
 
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
385
 
--error ER_NO_SUCH_TABLE
386
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
387
 
--error ER_NO_SUCH_TABLE
388
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
389
 
 
390
 
--error ER_UNKNOWN_TABLE
391
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
392
 
--error ER_UNKNOWN_TABLE
393
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
394
 
--error ER_UNKNOWN_TABLE
395
 
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
396
 
--error ER_UNKNOWN_TABLE
397
 
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
398
 
--error ER_NO_SUCH_TABLE
399
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
400
 
--error ER_NO_SUCH_TABLE
401
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
402
 
 
403
 
# Ambiguous table references
404
 
 
405
 
--error ER_NONUNIQ_TABLE
406
 
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
407
 
--error ER_NO_SUCH_TABLE
408
 
DELETE a1 FROM db1.a1, db2.t2 AS a1;
409
 
--error ER_NONUNIQ_TABLE
410
 
DELETE a1 FROM a1, db1.t1 AS a1;
411
 
--error ER_UNKNOWN_TABLE
412
 
DELETE t1 FROM db1.t1, db2.t1 AS a1;
413
 
--error ER_UNKNOWN_TABLE
414
 
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
415
 
--error ER_UNKNOWN_TABLE
416
 
DELETE t1 FROM db1.t1, db2.t1;
417
 
 
418
 
# Test multiple-table cross database deletes
419
 
 
420
 
DELETE t1 FROM db1.t2 AS t1, db2.t2 AS t2 WHERE t2.a = 1 AND t1.a = t2.a;
421
 
SELECT ROW_COUNT();
422
 
DELETE a1, a2 FROM db2.t1 AS a1, t2 AS a2 WHERE a1.a = 2 AND a2.a = 2;
423
 
SELECT ROW_COUNT();
424
 
 
425
251
DROP DATABASE db1;
426
252
DROP DATABASE db2;
427
253
DROP TABLE t1, t2;