~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/delete.test

  • Committer: Brian Aker
  • Date: 2009-07-16 22:37:01 UTC
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: brian@gaz-20090716223701-vbbbo8dmgd2ljqqo
Refactor TableShare has to be behind class.

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
-- error 1054
 
67
DELETE FROM t1 USING t1 WHERE post='1';
66
68
drop table t1;
67
69
 
68
70
#
69
71
# CHAR(0) bug - not actually DELETE bug, but anyway...
70
72
#
71
73
 
72
 
CREATE TEMPORARY TABLE t1 (
 
74
CREATE TABLE t1 (
73
75
  bool     char(0) default NULL,
74
 
  not_null varchar(20) NOT NULL default '',
 
76
  not_null varchar(20) binary NOT NULL default '',
75
77
  misc     integer not null,
76
78
  PRIMARY KEY  (not_null)
77
79
) ENGINE=MyISAM;
89
91
select count(*) from t1;
90
92
 
91
93
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;
92
104
 
93
105
#
94
106
# IGNORE option
103
115
--sorted_result
104
116
select * from t12;
105
117
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;
 
118
-- error 1242
 
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);
112
129
-- error 1242
113
130
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
114
131
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
 
}
 
132
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
120
133
select * from t11;
121
134
drop table t11, t12, t2;
122
135
 
126
139
 
127
140
create table t1 (a int, b int, unique key (a), key (b));
128
141
insert into t1 values (3, 3), (7, 7);
129
 
delete from t1 where a = 3;
 
142
delete t1 from t1 where a = 3;
130
143
check table t1;
131
144
select * from t1;
132
145
drop table t1;
143
156
DROP TABLE t1;
144
157
 
145
158
#
 
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
#
146
169
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
147
170
#            non-restricting WHERE is present.
148
171
#
171
194
--echo End of 4.1 tests
172
195
 
173
196
#
 
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
#
174
214
# Bug #26186: delete order by, sometimes accept unknown column
175
215
#
176
216
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
211
251
);
212
252
INSERT INTO db2.t1 (a) SELECT * FROM t2;
213
253
 
 
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;
214
266
SELECT * FROM t1;
215
267
--error ER_PARSE_ERROR
216
268
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
248
300
CREATE TABLE t1 AS SELECT * FROM db2.t2;
249
301
CREATE TABLE t2 AS SELECT * FROM t1;
250
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
 
251
410
DROP DATABASE db1;
252
411
DROP DATABASE db2;
253
412
DROP TABLE t1, t2;