~drizzle-trunk/drizzle/development

1 by brian
clean slate
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
396 by Brian Aker
Cleanup tiny and small int.
8
CREATE TABLE t1 (a int, b int);
1 by brian
clean slate
9
INSERT INTO t1 VALUES (1,1);
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
10
INSERT INTO t1 VALUES (1,2);
1 by brian
clean slate
11
INSERT INTO t1 VALUES (1,3);
12
DELETE from t1 where a=1 limit 1;
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
13
DELETE from t1 where a=1;
1 by brian
clean slate
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` (
223 by Brian Aker
Cleanup int() work.
62
  `i` int NOT NULL default '0',
63
  `i2` int NOT NULL default '0',
1 by brian
clean slate
64
  PRIMARY KEY  (`i`)
65
);
66
drop table t1;
67
68
#
69
# CHAR(0) bug - not actually DELETE bug, but anyway...
70
#
71
1063.9.3 by Brian Aker
Partial fix for tests for tmp
72
CREATE TEMPORARY TABLE t1 (
1 by brian
clean slate
73
  bool     char(0) default NULL,
1217 by Brian Aker
Removed bits of charset support from the parser.
74
  not_null varchar(20) NOT NULL default '',
1 by brian
clean slate
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;
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
103
--sorted_result
1 by brian
clean slate
104
select * from t12;
105
select * from t2;
1108.1.1 by Brian Aker
Remove multi-update from parser/tests.
106
select * from t11;
107
--sorted_result
108
select * from t12;
109
select * from t11;
110
--sorted_result
111
select * from t12;
1 by brian
clean slate
112
-- error 1242
113
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
114
select * from t11;
1441 by Brian Aker
Fixing tests to work with PBXT.
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
}
1 by brian
clean slate
120
select * from t11;
121
drop table t11, t12, t2;
122
123
#
124
# Bug #4198: deletion and KEYREAD
125
#
126
127
create table t1 (a int, b int, unique key (a), key (b));
128
insert into t1 values (3, 3), (7, 7);
1108.1.1 by Brian Aker
Remove multi-update from parser/tests.
129
delete from t1 where a = 3;
1 by brian
clean slate
130
check table t1;
131
select * from t1;
132
drop table t1;
133
134
#
135
# Bug #8392: delete with ORDER BY containing a direct reference to the table 
136
#
137
 
138
CREATE TABLE t1 ( a int PRIMARY KEY );
139
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
140
INSERT INTO t1 VALUES (0),(1),(2);
141
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
142
SELECT * FROM t1;
143
DROP TABLE t1;
144
145
#
146
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
147
#            non-restricting WHERE is present.
148
#
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
149
# PBXT is different here. @a = 2 instead of 1. I think the
150
# reason is because an index is not used, as done with
151
# InnoDB. This may be due to lack of cluster index. If the
152
# delete below is based on a secondary index then the
153
# index is not used
1 by brian
clean slate
154
create table t1(f1 int primary key);
155
insert into t1 values (4),(3),(1),(2);
156
delete from t1 where (@a:= f1) order by f1 limit 1;
157
select @a;
158
drop table t1;
159
160
# BUG#30385 "Server crash when deleting with order by and limit"
161
CREATE TABLE t1 (
162
  `date` date ,
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
163
  `seq` int NOT NULL auto_increment,
1 by brian
clean slate
164
  PRIMARY KEY  (`seq`),
165
  KEY `seq` (`seq`),
166
  KEY `date` (`date`)
167
);
896.5.1 by Jay Pipes
Removes the TIME column type and related time functions.
168
DELETE FROM t1 ORDER BY date ASC LIMIT 1;
1 by brian
clean slate
169
drop table t1;
170
171
--echo End of 4.1 tests
172
173
#
174
# Bug #26186: delete order by, sometimes accept unknown column
175
#
176
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);
177
178
--error ER_BAD_FIELD_ERROR
179
DELETE FROM t1 ORDER BY x;
180
181
# even columns from a table not used in query (and not even existing)
182
--error ER_BAD_FIELD_ERROR
183
DELETE FROM t1 ORDER BY t2.x;
184
185
# subquery (as long as the subquery from is valid or DUAL)
186
--error ER_BAD_FIELD_ERROR
187
DELETE FROM t1 ORDER BY (SELECT x);
188
189
DROP TABLE t1;
190
191
#
192
# Bug #30234: Unexpected behavior using DELETE with AS and USING
193
# '
194
CREATE TABLE t1 (
195
  a INT
196
);
197
198
CREATE TABLE t2 (
199
  a INT
200
);
201
202
CREATE DATABASE db1;
203
CREATE TABLE db1.t1 (
204
  a INT
205
);
206
INSERT INTO db1.t1 (a) SELECT * FROM t1;
207
208
CREATE DATABASE db2;
209
CREATE TABLE db2.t1 (
210
  a INT
211
);
212
INSERT INTO db2.t1 (a) SELECT * FROM t2;
213
214
SELECT * FROM t1;
215
--error ER_PARSE_ERROR
216
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
217
SELECT * FROM t1;
218
219
DROP TABLE t1, t2;
220
DROP DATABASE db1;
221
DROP DATABASE db2;
222
223
--echo End of 5.0 tests
224
225
#
226
# Bug#27525: table not found when using multi-table-deletes with aliases over
227
#            several databas
228
# Bug#21148: MULTI-DELETE fails to resolve a table by alias if it's from a
229
#            different database
230
#
231
232
--disable_warnings
233
DROP DATABASE IF EXISTS db1;
234
DROP DATABASE IF EXISTS db2;
235
DROP DATABASE IF EXISTS db3;
236
DROP DATABASE IF EXISTS db4;
237
DROP TABLE IF EXISTS t1, t2;
238
--enable_warnings
239
USE test;
240
CREATE DATABASE db1;
241
CREATE DATABASE db2;
242
243
CREATE TABLE db1.t1 (a INT, b INT);
244
INSERT INTO db1.t1 VALUES (1,1),(2,2),(3,3);
245
CREATE TABLE db1.t2 AS SELECT * FROM db1.t1;
246
CREATE TABLE db2.t1 AS SELECT * FROM db1.t2;
247
CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
248
CREATE TABLE t1 AS SELECT * FROM db2.t2;
249
CREATE TABLE t2 AS SELECT * FROM t1;
1435.1.3 by Stewart Smith
fix delete test case so that it doesn't leave databases and tables lying around carelessly for somebody to trip down the stairs on.
250
251
DROP DATABASE db1;
252
DROP DATABASE db2;
253
DROP TABLE t1, t2;