~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/delete.test

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
--disable_warnings
6
6
drop table if exists t1,t2,t3,t11,t12;
7
7
--enable_warnings
8
 
CREATE TABLE t1 (a tinyint, b tinyint);
 
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
114
100
insert into t12 values (33, 10),(0, 11),(2, 12);
115
101
insert into t2 values (1, 21),(2, 12),(3, 23);
116
102
select * from t11;
 
103
--sorted_result
117
104
select * from t12;
118
105
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
 
select * from t12;
122
 
delete ignore t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b <> (select b from t2 where t11.a < t2.a);
123
 
select * from t11;
124
 
select * from t12;
125
 
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;
126
112
-- error 1242
127
113
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
128
114
select * from t11;
137
122
 
138
123
create table t1 (a int, b int, unique key (a), key (b));
139
124
insert into t1 values (3, 3), (7, 7);
140
 
delete t1 from t1 where a = 3;
 
125
delete from t1 where a = 3;
141
126
check table t1;
142
127
select * from t1;
143
128
drop table t1;
154
139
DROP TABLE t1;
155
140
 
156
141
#
157
 
# Bug #21392: multi-table delete with alias table name fails with 
158
 
# 1003: Incorrect table name
159
 
#
160
 
 
161
 
create table t1 (a int);
162
 
delete `4.t1` from t1 as `4.t1` where `4.t1`.a = 5;
163
 
delete FROM `4.t1` USING t1 as `4.t1` where `4.t1`.a = 5;
164
 
drop table t1;
165
 
 
166
 
#
167
142
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
168
143
#            non-restricting WHERE is present.
169
144
#
 
145
# PBXT is different here. @a = 2 instead of 1. I think the
 
146
# reason is because an index is not used, as done with
 
147
# InnoDB. This may be due to lack of cluster index. If the
 
148
# delete below is based on a secondary index then the
 
149
# index is not used
170
150
create table t1(f1 int primary key);
171
151
insert into t1 values (4),(3),(1),(2);
172
152
delete from t1 where (@a:= f1) order by f1 limit 1;
176
156
# BUG#30385 "Server crash when deleting with order by and limit"
177
157
CREATE TABLE t1 (
178
158
  `date` date ,
179
 
  `time` time ,
180
 
  `seq` int unsigned NOT NULL auto_increment,
 
159
  `seq` int NOT NULL auto_increment,
181
160
  PRIMARY KEY  (`seq`),
182
161
  KEY `seq` (`seq`),
183
 
  KEY `time` (`time`),
184
162
  KEY `date` (`date`)
185
163
);
186
 
DELETE FROM t1 ORDER BY date ASC, time ASC LIMIT 1;
 
164
DELETE FROM t1 ORDER BY date ASC LIMIT 1;
187
165
drop table t1;
188
166
 
189
167
--echo End of 4.1 tests
190
168
 
191
169
#
192
 
# Test of multi-delete where we are not scanning the first table
193
 
#
194
 
 
195
 
CREATE TABLE t1 (a int not null,b int not null);
196
 
CREATE TABLE t2 (a int not null, b int not null, primary key (a,b));
197
 
CREATE TABLE t3 (a int not null, b int not null, primary key (a,b));
198
 
insert into t1 values (1,1),(2,1),(1,3);
199
 
insert into t2 values (1,1),(2,2),(3,3);
200
 
insert into t3 values (1,1),(2,1),(1,3);
201
 
select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
202
 
explain select * from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
203
 
delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
204
 
# This should be empty
205
 
select * from t3;
206
 
drop table t1,t2,t3;
207
 
 
208
 
#
209
 
# Bug #8143: deleting '0000-00-00' values using IS NULL
210
 
#
211
 
 
212
 
create table t1(a date not null);
213
 
insert into t1 values (0);
214
 
select * from t1 where a is null;
215
 
delete from t1 where a is null;
216
 
select count(*) from t1;
217
 
drop table t1;
218
 
 
219
 
#
220
170
# Bug #26186: delete order by, sometimes accept unknown column
221
171
#
222
172
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
257
207
);
258
208
INSERT INTO db2.t1 (a) SELECT * FROM t2;
259
209
 
260
 
--error ER_PARSE_ERROR
261
 
DELETE FROM t1 alias USING t1, t2 alias WHERE t1.a = alias.a;
262
 
DELETE FROM alias USING t1, t2 alias WHERE t1.a = alias.a;
263
 
DELETE FROM t1, alias USING t1, t2 alias WHERE t1.a = alias.a;
264
 
--error ER_UNKNOWN_TABLE
265
 
DELETE FROM t1, t2 USING t1, t2 alias WHERE t1.a = alias.a;
266
 
--error ER_PARSE_ERROR
267
 
DELETE FROM db1.t1 alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
268
 
DELETE FROM alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
269
 
--error ER_UNKNOWN_TABLE
270
 
DELETE FROM db2.alias USING db1.t1, db2.t1 alias WHERE db1.t1.a = alias.a;
271
 
DELETE FROM t1 USING t1 WHERE a = 1;
272
210
SELECT * FROM t1;
273
211
--error ER_PARSE_ERROR
274
212
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
305
243
CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
306
244
CREATE TABLE t1 AS SELECT * FROM db2.t2;
307
245
CREATE TABLE t2 AS SELECT * FROM t1;
308
 
 
309
 
#
310
 
# Testing without a selected database
311
 
#
312
 
 
313
 
CREATE DATABASE db3;
314
 
USE db3;
315
 
DROP DATABASE db3;
316
 
--error ER_NO_DB_ERROR
317
 
SELECT * FROM t1;
318
 
 
319
 
# Detect missing table references
320
 
 
321
 
--error ER_NO_DB_ERROR
322
 
DELETE a1,a2 FROM db1.t1, db2.t2;
323
 
--error ER_NO_DB_ERROR
324
 
DELETE a1,a2 FROM db1.t1, db2.t2;
325
 
--error ER_NO_DB_ERROR
326
 
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
327
 
--error ER_NO_DB_ERROR
328
 
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
329
 
--error ER_NO_DB_ERROR
330
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
331
 
--error ER_NO_DB_ERROR
332
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
333
 
 
334
 
--error ER_NO_DB_ERROR
335
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
336
 
--error ER_NO_DB_ERROR
337
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
338
 
--error ER_NO_DB_ERROR
339
 
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
340
 
--error ER_NO_DB_ERROR
341
 
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
342
 
--error ER_NO_DB_ERROR
343
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
344
 
--error ER_NO_DB_ERROR
345
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
346
 
 
347
 
# Ambiguous table references
348
 
 
349
 
--error ER_NO_DB_ERROR
350
 
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
351
 
--error ER_NO_DB_ERROR
352
 
DELETE a1 FROM db1.a1, db2.t2 AS a1;
353
 
--error ER_NO_DB_ERROR
354
 
DELETE a1 FROM a1, db1.t1 AS a1;
355
 
--error ER_NO_DB_ERROR
356
 
DELETE t1 FROM db1.t1, db2.t1 AS a1;
357
 
--error ER_NO_DB_ERROR
358
 
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
359
 
--error ER_NO_DB_ERROR
360
 
DELETE t1 FROM db1.t1, db2.t1;
361
 
 
362
 
# Test all again, now with a selected database
363
 
 
364
 
USE test;
365
 
 
366
 
# Detect missing table references
367
 
 
368
 
--error ER_UNKNOWN_TABLE
369
 
DELETE a1,a2 FROM db1.t1, db2.t2;
370
 
--error ER_UNKNOWN_TABLE
371
 
DELETE a1,a2 FROM db1.t1, db2.t2;
372
 
--error ER_UNKNOWN_TABLE
373
 
DELETE a1,a2 FROM db1.t1 AS a1, db2.t2;
374
 
--error ER_UNKNOWN_TABLE
375
 
DELETE a1,a2 FROM db1.t1, db2.t2 AS a2;
376
 
--error ER_NO_SUCH_TABLE
377
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
378
 
--error ER_NO_SUCH_TABLE
379
 
DELETE a1,a2 FROM db3.t1 AS a1, db4.t2 AS a2;
380
 
 
381
 
--error ER_UNKNOWN_TABLE
382
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
383
 
--error ER_UNKNOWN_TABLE
384
 
DELETE FROM a1,a2 USING db1.t1, db2.t2;
385
 
--error ER_UNKNOWN_TABLE
386
 
DELETE FROM a1,a2 USING db1.t1 AS a1, db2.t2;
387
 
--error ER_UNKNOWN_TABLE
388
 
DELETE FROM a1,a2 USING db1.t1, db2.t2 AS a2;
389
 
--error ER_NO_SUCH_TABLE
390
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
391
 
--error ER_NO_SUCH_TABLE
392
 
DELETE FROM a1,a2 USING db3.t1 AS a1, db4.t2 AS a2;
393
 
 
394
 
# Ambiguous table references
395
 
 
396
 
--error ER_NONUNIQ_TABLE
397
 
DELETE a1 FROM db1.t1 AS a1, db2.t2 AS a1;
398
 
--error ER_NO_SUCH_TABLE
399
 
DELETE a1 FROM db1.a1, db2.t2 AS a1;
400
 
--error ER_NONUNIQ_TABLE
401
 
DELETE a1 FROM a1, db1.t1 AS a1;
402
 
--error ER_UNKNOWN_TABLE
403
 
DELETE t1 FROM db1.t1, db2.t1 AS a1;
404
 
--error ER_UNKNOWN_TABLE
405
 
DELETE t1 FROM db1.t1 AS a1, db2.t1 AS a2;
406
 
--error ER_UNKNOWN_TABLE
407
 
DELETE t1 FROM db1.t1, db2.t1;
408
 
 
409
 
# Test multiple-table cross database deletes
410
 
 
411
 
DELETE t1 FROM db1.t2 AS t1, db2.t2 AS t2 WHERE t2.a = 1 AND t1.a = t2.a;
412
 
SELECT ROW_COUNT();
413
 
DELETE a1, a2 FROM db2.t1 AS a1, t2 AS a2 WHERE a1.a = 2 AND a2.a = 2;
414
 
SELECT ROW_COUNT();
415
 
 
416
 
DROP DATABASE db1;
417
 
DROP DATABASE db2;
418
 
DROP TABLE t1, t2;