~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/delete.test

  • Committer: Brian Aker
  • Date: 2009-08-04 06:21:17 UTC
  • mfrom: (1108.2.2 merge)
  • Revision ID: brian@gaz-20090804062117-fef8x6y3ydzrvab3
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
  `i2` int NOT NULL default '0',
64
64
  PRIMARY KEY  (`i`)
65
65
);
66
 
DELETE FROM t1 USING t1 WHERE post='1';
67
66
drop table t1;
68
67
 
69
68
#
91
89
select count(*) from t1;
92
90
 
93
91
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
92
 
105
93
#
106
94
# IGNORE option
115
103
--sorted_result
116
104
select * from t12;
117
105
select * from t2;
118
 
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
119
 
select * from t11;
120
 
--sorted_result
121
 
select * from t12;
122
 
# PBXT: for some reason this returns 2 warnings instead of 1
123
 
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
124
 
select * from t11;
125
 
--sorted_result
126
 
select * from t12;
127
 
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;
128
112
-- error 1242
129
113
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
130
114
select * from t11;
139
122
 
140
123
create table t1 (a int, b int, unique key (a), key (b));
141
124
insert into t1 values (3, 3), (7, 7);
142
 
delete t1 from t1 where a = 3;
 
125
delete from t1 where a = 3;
143
126
check table t1;
144
127
select * from t1;
145
128
drop table t1;
156
139
DROP TABLE t1;
157
140
 
158
141
#
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
142
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
170
143
#            non-restricting WHERE is present.
171
144
#
194
167
--echo End of 4.1 tests
195
168
 
196
169
#
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
170
# Bug #26186: delete order by, sometimes accept unknown column
215
171
#
216
172
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
251
207
);
252
208
INSERT INTO db2.t1 (a) SELECT * FROM t2;
253
209
 
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
210
SELECT * FROM t1;
267
211
--error ER_PARSE_ERROR
268
212
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
299
243
CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
300
244
CREATE TABLE t1 AS SELECT * FROM db2.t2;
301
245
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;