~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#
# Check for problems with delete
#

--disable_warnings
drop table if exists t1,t2,t3,t11,t12;
--enable_warnings
CREATE TABLE t1 (a int, b int);
INSERT INTO t1 VALUES (1,1);
INSERT INTO t1 VALUES (1,2);
INSERT INTO t1 VALUES (1,3);
DELETE from t1 where a=1 limit 1;
DELETE from t1 where a=1;

INSERT INTO t1 VALUES (1,1);
DELETE from t1;
INSERT INTO t1 VALUES (1,2);
DELETE from t1;
INSERT INTO t1 VALUES (1,2);
SET AUTOCOMMIT=0;
DELETE from t1;
SET AUTOCOMMIT=1;
drop table t1;

#
# Test of delete when the delete will cause a node to disappear and reappear
# (This assumes a block size of 1024)
#

create table t1 (
	a bigint not null,
	b bigint not null default 0,
	c bigint not null default 0,
	d bigint not null default 0,
	e bigint not null default 0,
	f bigint not null default 0,
	g bigint not null default 0,
	h bigint not null default 0,
	i bigint not null default 0,
	j bigint not null default 0,
	primary key (a,b,c,d,e,f,g,h,i,j));
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23);
delete from t1 where a=26;
drop table t1;
create table t1 (
	a bigint not null,
	b bigint not null default 0,
	c bigint not null default 0,
	d bigint not null default 0,
	e bigint not null default 0,
	f bigint not null default 0,
	g bigint not null default 0,
	h bigint not null default 0,
	i bigint not null default 0,
	j bigint not null default 0,
	primary key (a,b,c,d,e,f,g,h,i,j));
insert into t1 (a) values (2),(4),(6),(8),(10),(12),(14),(16),(18),(20),(22),(24),(26),(23),(27);
delete from t1 where a=27;
drop table t1;

CREATE TABLE `t1` (
  `i` int NOT NULL default '0',
  `i2` int NOT NULL default '0',
  PRIMARY KEY  (`i`)
);
drop table t1;

#
# CHAR(0) bug - not actually DELETE bug, but anyway...
#

CREATE TEMPORARY TABLE t1 (
  bool     char(0) default NULL,
  not_null varchar(20) NOT NULL default '',
  misc     integer not null,
  PRIMARY KEY  (not_null)
) ENGINE=MyISAM;

INSERT INTO t1 VALUES (NULL,'a',4), (NULL,'b',5), (NULL,'c',6), (NULL,'d',7);

select * from t1 where misc > 5 and bool is null;
delete   from t1 where misc > 5 and bool is null;
select * from t1 where misc > 5 and bool is null;

select count(*) from t1;
delete from t1 where 1 > 2;
select count(*) from t1;
delete from t1 where 3 > 2;
select count(*) from t1;

drop table t1;

#
# IGNORE option
#
create table t11 (a int NOT NULL, b int, primary key (a));
create table t12 (a int NOT NULL, b int, primary key (a));
create table t2 (a int NOT NULL, b int, primary key (a));
insert into t11 values (0, 10),(1, 11),(2, 12);
insert into t12 values (33, 10),(0, 11),(2, 12);
insert into t2 values (1, 21),(2, 12),(3, 23);
select * from t11;
--sorted_result
select * from t12;
select * from t2;
select * from t11;
--sorted_result
select * from t12;
select * from t11;
--sorted_result
select * from t12;
-- error 1242
delete from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
select * from t11;
delete ignore from t11 where t11.b <> (select b from t2 where t11.a < t2.a);
select * from t11;
drop table t11, t12, t2;

#
# Bug #4198: deletion and KEYREAD
#

create table t1 (a int, b int, unique key (a), key (b));
insert into t1 values (3, 3), (7, 7);
delete from t1 where a = 3;
check table t1;
select * from t1;
drop table t1;

#
# Bug #8392: delete with ORDER BY containing a direct reference to the table 
#
 
CREATE TABLE t1 ( a int PRIMARY KEY );
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a;
INSERT INTO t1 VALUES (0),(1),(2);
DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a LIMIT 1;
SELECT * FROM t1;
DROP TABLE t1;

#
# Bug#17711: DELETE doesn't use index when ORDER BY, LIMIT and
#            non-restricting WHERE is present.
#
# PBXT is different here. @a = 2 instead of 1. I think the
# reason is because an index is not used, as done with
# InnoDB. This may be due to lack of cluster index. If the
# delete below is based on a secondary index then the
# index is not used
create table t1(f1 int primary key);
insert into t1 values (4),(3),(1),(2);
delete from t1 where (@a:= f1) order by f1 limit 1;
select @a;
drop table t1;

# BUG#30385 "Server crash when deleting with order by and limit"
CREATE TABLE t1 (
  `date` date ,
  `seq` int NOT NULL auto_increment,
  PRIMARY KEY  (`seq`),
  KEY `seq` (`seq`),
  KEY `date` (`date`)
);
DELETE FROM t1 ORDER BY date ASC LIMIT 1;
drop table t1;

--echo End of 4.1 tests

#
# Bug #26186: delete order by, sometimes accept unknown column
#
CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1);

--error ER_BAD_FIELD_ERROR
DELETE FROM t1 ORDER BY x;

# even columns from a table not used in query (and not even existing)
--error ER_BAD_FIELD_ERROR
DELETE FROM t1 ORDER BY t2.x;

# subquery (as long as the subquery from is valid or DUAL)
--error ER_BAD_FIELD_ERROR
DELETE FROM t1 ORDER BY (SELECT x);

DROP TABLE t1;

#
# Bug #30234: Unexpected behavior using DELETE with AS and USING
# '
CREATE TABLE t1 (
  a INT
);

CREATE TABLE t2 (
  a INT
);

CREATE DATABASE db1;
CREATE TABLE db1.t1 (
  a INT
);
INSERT INTO db1.t1 (a) SELECT * FROM t1;

CREATE DATABASE db2;
CREATE TABLE db2.t1 (
  a INT
);
INSERT INTO db2.t1 (a) SELECT * FROM t2;

SELECT * FROM t1;
--error ER_PARSE_ERROR
DELETE FROM t1 alias USING t1 alias WHERE a = 2;
SELECT * FROM t1;

DROP TABLE t1, t2;
DROP DATABASE db1;
DROP DATABASE db2;

--echo End of 5.0 tests

#
# Bug#27525: table not found when using multi-table-deletes with aliases over
#            several databas
# Bug#21148: MULTI-DELETE fails to resolve a table by alias if it's from a
#            different database
#

--disable_warnings
DROP DATABASE IF EXISTS db1;
DROP DATABASE IF EXISTS db2;
DROP DATABASE IF EXISTS db3;
DROP DATABASE IF EXISTS db4;
DROP TABLE IF EXISTS t1, t2;
--enable_warnings
USE test;
CREATE DATABASE db1;
CREATE DATABASE db2;

CREATE TABLE db1.t1 (a INT, b INT);
INSERT INTO db1.t1 VALUES (1,1),(2,2),(3,3);
CREATE TABLE db1.t2 AS SELECT * FROM db1.t1;
CREATE TABLE db2.t1 AS SELECT * FROM db1.t2;
CREATE TABLE db2.t2 AS SELECT * FROM db2.t1;
CREATE TABLE t1 AS SELECT * FROM db2.t2;
CREATE TABLE t2 AS SELECT * FROM t1;