~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/delete.test

Removed/replaced DBUG symbols and TRUE/FALSE

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Check for problems with delete
3
 
#
4
 
 
5
 
--disable_warnings
6
 
drop table if exists t1,t2,t3,t11,t12;
7
 
--enable_warnings
8
 
CREATE TABLE t1 (a int, b int);
9
 
INSERT INTO t1 VALUES (1,1);
10
 
INSERT INTO t1 VALUES (1,2);
11
 
INSERT INTO t1 VALUES (1,3);
12
 
DELETE from t1 where a=1 limit 1;
13
 
DELETE from t1 where a=1;
14
 
 
15
 
INSERT INTO t1 VALUES (1,1);
16
 
DELETE from t1;
17
 
INSERT INTO t1 VALUES (1,2);
18
 
DELETE from t1;
19
 
INSERT INTO t1 VALUES (1,2);
20
 
SET AUTOCOMMIT=0;
21
 
DELETE from t1;
22
 
SET AUTOCOMMIT=1;
23
 
drop table t1;
24
 
 
25
 
#
26
 
# Test of delete when the delete will cause a node to disappear and reappear
27
 
# (This assumes a block size of 1024)
28
 
#
29
 
 
30
 
create table t1 (
31
 
        a bigint not null,
32
 
        b bigint not null default 0,
33
 
        c bigint not null default 0,
34
 
        d bigint not null default 0,
35
 
        e bigint not null default 0,
36
 
        f bigint not null default 0,
37
 
        g bigint not null default 0,
38
 
        h bigint not null default 0,
39
 
        i bigint not null default 0,
40
 
        j bigint not null default 0,
41
 
        primary key (a,b,c,d,e,f,g,h,i,j));
42
 
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23);
43
 
delete from t1 where a=26;
44
 
drop table t1;
45
 
create table t1 (
46
 
        a bigint not null,
47
 
        b bigint not null default 0,
48
 
        c bigint not null default 0,
49
 
        d bigint not null default 0,
50
 
        e bigint not null default 0,
51
 
        f bigint not null default 0,
52
 
        g bigint not null default 0,
53
 
        h bigint not null default 0,
54
 
        i bigint not null default 0,
55
 
        j bigint not null default 0,
56
 
        primary key (a,b,c,d,e,f,g,h,i,j));
57
 
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27);
58
 
delete from t1 where a=27;
59
 
drop table t1;
60
 
 
61
 
CREATE TABLE `t1` (
62
 
  `i` int NOT NULL default '0',
63
 
  `i2` int NOT NULL default '0',
64
 
  PRIMARY KEY  (`i`)
65
 
);
66
 
drop table t1;
67
 
 
68
 
#
69
 
# CHAR(0) bug - not actually DELETE bug, but anyway...
70
 
#
71
 
 
72
 
CREATE TEMPORARY TABLE t1 (
73
 
  bool     char(0) default NULL,
74
 
  not_null varchar(20) NOT NULL default '',
75
 
  misc     integer not null,
76
 
  PRIMARY KEY  (not_null)
77
 
) ENGINE=MyISAM;
78
 
 
79
 
INSERT INTO t1 VALUES (NULL,'a',4), (NULL,'b',5), (NULL,'c',6), (NULL,'d',7);
80
 
 
81
 
select * from t1 where misc > 5 and bool is null;
82
 
delete   from t1 where misc > 5 and bool is null;
83
 
select * from t1 where misc > 5 and bool is null;
84
 
 
85
 
select count(*) from t1;
86
 
delete from t1 where 1 > 2;
87
 
select count(*) from t1;
88
 
delete from t1 where 3 > 2;
89
 
select count(*) from t1;
90
 
 
91
 
drop table t1;
92
 
 
93
 
#
94
 
# IGNORE option
95
 
#
96
 
create table t11 (a int NOT NULL, b int, primary key (a));
97
 
create table t12 (a int NOT NULL, b int, primary key (a));
98
 
create table t2 (a int NOT NULL, b int, primary key (a));
99
 
insert into t11 values (0, 10),(1, 11),(2, 12);
100
 
insert into t12 values (33, 10),(0, 11),(2, 12);
101
 
insert into t2 values (1, 21),(2, 12),(3, 23);
102
 
select * from t11;
103
 
--sorted_result
104
 
select * from t12;
105
 
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;
112
 
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
113
 
select * from t11;
114
 
 
115
 
# PBXT doesn't currently support DELETE IGNORE and turns it into plain DELETE
116
 
if (`select if (@@storage_engine = 'PBXT', 0, 1)`) { 
117
 
  delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
118
 
}
119
 
select * from t11;
120
 
drop table t11, t12, t2;
121
 
 
122
 
#
123
 
# Bug #4198: deletion and KEYREAD
124
 
#
125
 
 
126
 
create table t1 (a int, b int, unique key (a), key (b));
127
 
insert into t1 values (3, 3), (7, 7);
128
 
delete from t1 where a = 3;
129
 
check table t1;
130
 
select * from t1;
131
 
drop table t1;
132
 
 
133
 
#
134
 
# Bug #8392: delete with ORDER BY containing a direct reference to the table 
135
 
#
136
 
 
137
 
CREATE TABLE t1 ( a int PRIMARY KEY );
138
 
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
139
 
INSERT INTO t1 VALUES (0),(1),(2);
140
 
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
141
 
SELECT * FROM t1;
142
 
DROP TABLE t1;
143
 
 
144
 
#
145
 
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
146
 
#            non-restricting WHERE is present.
147
 
#
148
 
# PBXT is different here. @a = 2 instead of 1. I think the
149
 
# reason is because an index is not used, as done with
150
 
# InnoDB. This may be due to lack of cluster index. If the
151
 
# delete below is based on a secondary index then the
152
 
# index is not used
153
 
create table t1(f1 int primary key);
154
 
insert into t1 values (4),(3),(1),(2);
155
 
delete from t1 where (@a:= f1) order by f1 limit 1;
156
 
select @a;
157
 
drop table t1;
158
 
 
159
 
# BUG#30385 "Server crash when deleting with order by and limit"
160
 
CREATE TABLE t1 (
161
 
  `date` date ,
162
 
  `seq` int NOT NULL auto_increment,
163
 
  PRIMARY KEY  (`seq`),
164
 
  KEY `seq` (`seq`),
165
 
  KEY `date` (`date`)
166
 
);
167
 
DELETE FROM t1 ORDER BY date ASC LIMIT 1;
168
 
drop table t1;
169
 
 
170
 
--echo End of 4.1 tests
171
 
 
172
 
#
173
 
# Bug #26186: delete order by, sometimes accept unknown column
174
 
#
175
 
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
176
 
 
177
 
--error ER_BAD_FIELD_ERROR
178
 
DELETE FROM t1 ORDER BY x;
179
 
 
180
 
# even columns from a table not used in query (and not even existing)
181
 
--error ER_BAD_FIELD_ERROR
182
 
DELETE FROM t1 ORDER BY t2.x;
183
 
 
184
 
# subquery (as long as the subquery from is valid or DUAL)
185
 
--error ER_BAD_FIELD_ERROR
186
 
DELETE FROM t1 ORDER BY (SELECT x);
187
 
 
188
 
DROP TABLE t1;
189
 
 
190
 
#
191
 
# Bug #30234: Unexpected behavior using DELETE with AS and USING
192
 
# '
193
 
CREATE TABLE t1 (
194
 
  a INT
195
 
);
196
 
 
197
 
CREATE TABLE t2 (
198
 
  a INT
199
 
);
200
 
 
201
 
CREATE DATABASE db1;
202
 
CREATE TABLE db1.t1 (
203
 
  a INT
204
 
);
205
 
INSERT INTO db1.t1 (a) SELECT * FROM t1;
206
 
 
207
 
CREATE DATABASE db2;
208
 
CREATE TABLE db2.t1 (
209
 
  a INT
210
 
);
211
 
INSERT INTO db2.t1 (a) SELECT * FROM t2;
212
 
 
213
 
SELECT * FROM t1;
214
 
--error ER_PARSE_ERROR
215
 
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
216
 
SELECT * FROM t1;
217
 
 
218
 
DROP TABLE t1, t2;
219
 
DROP DATABASE db1;
220
 
DROP DATABASE db2;
221
 
 
222
 
--echo End of 5.0 tests
223
 
 
224
 
#
225
 
# Bug#27525: table not found when using multi-table-deletes with aliases over
226
 
#            several databas
227
 
# Bug#21148: MULTI-DELETE fails to resolve a table by alias if it's from a
228
 
#            different database
229
 
#
230
 
 
231
 
--disable_warnings
232
 
DROP DATABASE IF EXISTS db1;
233
 
DROP DATABASE IF EXISTS db2;
234
 
DROP DATABASE IF EXISTS db3;
235
 
DROP DATABASE IF EXISTS db4;
236
 
DROP TABLE IF EXISTS t1, t2;
237
 
--enable_warnings
238
 
USE test;
239
 
CREATE DATABASE db1;
240
 
CREATE DATABASE db2;
241
 
 
242
 
CREATE TABLE db1.t1 (a INT, b INT);
243
 
INSERT INTO db1.t1 VALUES (1,1),(2,2),(3,3);
244
 
CREATE TABLE db1.t2 AS SELECT * FROM db1.t1;
245
 
CREATE TABLE db2.t1 AS SELECT * FROM db1.t2;
246
 
CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
247
 
CREATE TABLE t1 AS SELECT * FROM db2.t2;
248
 
CREATE TABLE t2 AS SELECT * FROM t1;
249
 
 
250
 
DROP DATABASE db1;
251
 
DROP DATABASE db2;
252
 
DROP TABLE t1, t2;