~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/delete.test

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

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 INTO t1 VALUES (1,2);
 
10
INSERT LOW_PRIORITY 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 from t1 where a=1;
 
13
DELETE LOW_PRIORITY 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;
17
18
INSERT INTO t1 VALUES (1,2);
18
19
DELETE from t1;
 
20
UNLOCK TABLES;
19
21
INSERT INTO t1 VALUES (1,2);
20
22
SET AUTOCOMMIT=0;
21
23
DELETE from t1;
63
65
  `i2` int NOT NULL default '0',
64
66
  PRIMARY KEY  (`i`)
65
67
);
 
68
-- error 1054
 
69
DELETE FROM t1 USING t1 WHERE post='1';
66
70
drop table t1;
67
71
 
68
72
#
69
73
# CHAR(0) bug - not actually DELETE bug, but anyway...
70
74
#
71
75
 
72
 
CREATE TEMPORARY TABLE t1 (
 
76
CREATE TABLE t1 (
73
77
  bool     char(0) default NULL,
74
 
  not_null varchar(20) NOT NULL default '',
 
78
  not_null varchar(20) binary NOT NULL default '',
75
79
  misc     integer not null,
76
80
  PRIMARY KEY  (not_null)
77
81
) ENGINE=MyISAM;
89
93
select count(*) from t1;
90
94
 
91
95
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;
92
106
 
93
107
#
94
108
# IGNORE option
103
117
--sorted_result
104
118
select * from t12;
105
119
select * from t2;
106
 
select * from t11;
107
 
--sorted_result
108
 
select * from t12;
109
 
select * from t11;
110
 
--sorted_result
111
 
select * from t12;
 
120
-- error 1242
 
121
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
 
122
select * from t11;
 
123
--sorted_result
 
124
select * from t12;
 
125
# PBXT: for some reason this returns 2 warnings instead of 1
 
126
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
 
127
select * from t11;
 
128
--sorted_result
 
129
select * from t12;
 
130
insert into t11 values (2, 12);
112
131
-- error 1242
113
132
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
114
133
select * from t11;
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
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
120
135
select * from t11;
121
136
drop table t11, t12, t2;
122
137
 
126
141
 
127
142
create table t1 (a int, b int, unique key (a), key (b));
128
143
insert into t1 values (3, 3), (7, 7);
129
 
delete from t1 where a = 3;
 
144
delete t1 from t1 where a = 3;
130
145
check table t1;
131
146
select * from t1;
132
147
drop table t1;
143
158
DROP TABLE t1;
144
159
 
145
160
#
 
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
#
146
171
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
147
172
#            non-restricting WHERE is present.
148
173
#
171
196
--echo End of 4.1 tests
172
197
 
173
198
#
 
199
# Test of multi-delete where we are not scanning the first table
 
200
#
 
201
 
 
202
CREATE TABLE t1 (a int not null,b int not null);
 
203
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b));
 
204
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));
 
205
insert into t1 values (1,1),(2,1),(1,3);
 
206
insert into t2 values (1,1),(2,2),(3,3);
 
207
insert into t3 values (1,1),(2,1),(1,3);
 
208
select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
 
209
explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
 
210
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
 
211
# This should be empty
 
212
select * from t3;
 
213
drop table t1,t2,t3;
 
214
 
 
215
#
174
216
# Bug #26186: delete order by, sometimes accept unknown column
175
217
#
176
218
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
211
253
);
212
254
INSERT INTO db2.t1 (a) SELECT * FROM t2;
213
255
 
 
256
--error ER_PARSE_ERROR
 
257
DELETE FROM t1 alias USING t1, t2 alias WHERE t1.a = alias.a;
 
258
DELETE FROM alias USING t1, t2 alias WHERE t1.a = alias.a;
 
259
DELETE FROM t1, alias USING t1, t2 alias WHERE t1.a = alias.a;
 
260
--error ER_UNKNOWN_TABLE
 
261
DELETE FROM t1, t2 USING t1, t2 alias WHERE t1.a = alias.a;
 
262
--error ER_PARSE_ERROR
 
263
DELETE FROM db1.t1 alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
 
264
DELETE FROM alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
 
265
--error ER_UNKNOWN_TABLE
 
266
DELETE FROM db2.alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
 
267
DELETE FROM t1 USING t1 WHERE a = 1;
214
268
SELECT * FROM t1;
215
269
--error ER_PARSE_ERROR
216
270
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
248
302
CREATE TABLE t1 AS SELECT * FROM db2.t2;
249
303
CREATE TABLE t2 AS SELECT * FROM t1;
250
304
 
 
305
#
 
306
# Testing without a selected database
 
307
#
 
308
 
 
309
CREATE DATABASE db3;
 
310
USE db3;
 
311
DROP DATABASE db3;
 
312
--error ER_NO_DB_ERROR
 
313
SELECT * FROM t1;
 
314
 
 
315
# Detect missing table references
 
316
 
 
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, db2.t2;
 
321
--error ER_NO_DB_ERROR
 
322
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
 
323
--error ER_NO_DB_ERROR
 
324
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
 
325
--error ER_NO_DB_ERROR
 
326
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 
327
--error ER_NO_DB_ERROR
 
328
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 
329
 
 
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, db2.t2;
 
334
--error ER_NO_DB_ERROR
 
335
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
 
336
--error ER_NO_DB_ERROR
 
337
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
 
338
--error ER_NO_DB_ERROR
 
339
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 
340
--error ER_NO_DB_ERROR
 
341
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 
342
 
 
343
# Ambiguous table references
 
344
 
 
345
--error ER_NO_DB_ERROR
 
346
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
 
347
--error ER_NO_DB_ERROR
 
348
DELETE a1 FROM db1.a1, db2.t2 AS a1;
 
349
--error ER_NO_DB_ERROR
 
350
DELETE a1 FROM a1, db1.t1 AS a1;
 
351
--error ER_NO_DB_ERROR
 
352
DELETE t1 FROM db1.t1, db2.t1 AS a1;
 
353
--error ER_NO_DB_ERROR
 
354
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
 
355
--error ER_NO_DB_ERROR
 
356
DELETE t1 FROM db1.t1, db2.t1;
 
357
 
 
358
# Test all again, now with a selected database
 
359
 
 
360
USE test;
 
361
 
 
362
# Detect missing table references
 
363
 
 
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, db2.t2;
 
368
--error ER_UNKNOWN_TABLE
 
369
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
 
370
--error ER_UNKNOWN_TABLE
 
371
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
 
372
--error ER_NO_SUCH_TABLE
 
373
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 
374
--error ER_NO_SUCH_TABLE
 
375
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
 
376
 
 
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, db2.t2;
 
381
--error ER_UNKNOWN_TABLE
 
382
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
 
383
--error ER_UNKNOWN_TABLE
 
384
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
 
385
--error ER_NO_SUCH_TABLE
 
386
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 
387
--error ER_NO_SUCH_TABLE
 
388
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
 
389
 
 
390
# Ambiguous table references
 
391
 
 
392
--error ER_NONUNIQ_TABLE
 
393
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
 
394
--error ER_NO_SUCH_TABLE
 
395
DELETE a1 FROM db1.a1, db2.t2 AS a1;
 
396
--error ER_NONUNIQ_TABLE
 
397
DELETE a1 FROM a1, db1.t1 AS a1;
 
398
--error ER_UNKNOWN_TABLE
 
399
DELETE t1 FROM db1.t1, db2.t1 AS a1;
 
400
--error ER_UNKNOWN_TABLE
 
401
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
 
402
--error ER_UNKNOWN_TABLE
 
403
DELETE t1 FROM db1.t1, db2.t1;
 
404
 
 
405
# Test multiple-table cross database deletes
 
406
 
 
407
DELETE t1 FROM db1.t2 AS t1, db2.t2 AS t2 WHERE t2.a = 1 AND t1.a = t2.a;
 
408
SELECT ROW_COUNT();
 
409
DELETE a1, a2 FROM db2.t1 AS a1, t2 AS a2 WHERE a1.a = 2 AND a2.a = 2;
 
410
SELECT ROW_COUNT();
 
411
 
251
412
DROP DATABASE db1;
252
413
DROP DATABASE db2;
253
414
DROP TABLE t1, t2;