~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# test of updating of keys
3
#
4
5
--disable_warnings
6
drop table if exists t1,t2;
7
--enable_warnings
8
9
create table t1 (a int auto_increment , primary key (a));
10
insert into t1 values (NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL); 
11
update t1 set a=a+10 where a > 34;
12
update t1 set a=a+100 where a > 0;
13
14
# Some strange updates to test some otherwise unused code
15
update t1 set a=a+100 where a=1 and a=2;
16
--error 1054
17
update t1 set a=b+100 where a=1 and a=2; 
18
--error 1054
19
update t1 set a=b+100 where c=1 and a=2; 
20
--error 1054
21
update t1 set d=a+100 where a=1;
22
select * from t1;
23
drop table t1;
24
25
CREATE TABLE t1
26
 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
27
 place_id int NOT NULL,
28
 shows int DEFAULT '0' NOT NULL,
29
 ishows int DEFAULT '0' NOT NULL,
30
 ushows int DEFAULT '0' NOT NULL,
31
 clicks int DEFAULT '0' NOT NULL,
32
 iclicks int DEFAULT '0' NOT NULL,
33
 uclicks int DEFAULT '0' NOT NULL,
1 by brian
clean slate
34
 ts timestamp,
35
 PRIMARY KEY (place_id,ts)
36
 );
37
38
INSERT INTO t1 (place_id,shows,ishows,ushows,clicks,iclicks,uclicks,ts)
39
VALUES (1,0,0,0,0,0,0,20000928174434);
40
UPDATE t1 SET shows=shows+1,ishows=ishows+1,ushows=ushows+1,clicks=clicks+1,iclicks=iclicks+1,uclicks=uclicks+1 WHERE place_id=1 AND ts>="2000-09-28 00:00:00";
41
select place_id,shows from t1;
42
drop table t1;
43
44
#
45
# Test bug with update reported by Jan Legenhausen
46
#
47
1063.9.45 by Stewart Smith
update.test for MyISAM as temp only.
48
CREATE TEMPORARY TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
49
  lfdnr int NOT NULL default '0',
50
  ticket int NOT NULL default '0',
1 by brian
clean slate
51
  client varchar(255) NOT NULL default '',
52
  replyto varchar(255) NOT NULL default '',
53
  subject varchar(100) NOT NULL default '',
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
54
  timestamp int NOT NULL default '0',
1 by brian
clean slate
55
  tstamp timestamp NOT NULL,
223 by Brian Aker
Cleanup int() work.
56
  status int NOT NULL default '0',
1 by brian
clean slate
57
  type varchar(15) NOT NULL default '',
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
58
  assignment int NOT NULL default '0',
59
  fupcount int NOT NULL default '0',
60
  parent int NOT NULL default '0',
61
  activity int NOT NULL default '0',
62
  priority int NOT NULL default '1',
1 by brian
clean slate
63
  cc varchar(255) NOT NULL default '',
64
  bcc varchar(255) NOT NULL default '',
65
  body text NOT NULL,
66
  comment text,
67
  header text,
68
  PRIMARY KEY  (lfdnr),
69
  KEY k1 (timestamp),
70
  KEY k2 (type),
71
  KEY k3 (parent),
72
  KEY k4 (assignment),
73
  KEY ticket (ticket)
74
) ENGINE=MyISAM;
75
76
INSERT INTO t1 VALUES (773,773,'','','',980257344,20010318180652,0,'Open',10,0,0,0,1,'','','','','');
77
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
78
alter table t1 change lfdnr lfdnr int not null auto_increment;
1 by brian
clean slate
79
update t1 set status=1 where type='Open';
80
select status from t1;
81
drop table t1;
82
83
#
84
# Test of ORDER BY
85
#
86
87
create table t1 (a int not null, b int not null, key (a));
88
insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);
89
SET @tmp=0;
90
update t1 set b=(@tmp:=@tmp+1) order by a;
91
update t1 set b=99 where a=1 order by b asc limit 1;
92
select * from t1 order by a,b;
93
update t1 set b=100 where a=1 order by b desc limit 2;
94
update t1 set a=a+10+b where a=1 order by b;
95
select * from t1 order by a,b;
96
create table t2 (a int not null, b int not null);
97
insert into t2 values (1,1),(1,2),(1,3);
98
update t1 set b=(select distinct 1 from (select * from t2) a);
99
drop table t1,t2;
100
101
#
102
# Test with limit (Bug #393)
103
#
104
1063.9.45 by Stewart Smith
update.test for MyISAM as temp only.
105
CREATE TEMPORARY TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
106
   `id_param` int NOT NULL default '0',
1 by brian
clean slate
107
   `nom_option` char(40) NOT NULL default '',
396 by Brian Aker
Cleanup tiny and small int.
108
   `valid` int NOT NULL default '0',
1 by brian
clean slate
109
   KEY `id_param` (`id_param`,`nom_option`)
110
 ) ENGINE=MyISAM;
111
112
INSERT INTO t1 (id_param,nom_option,valid) VALUES (185,'600x1200',1);
113
114
UPDATE t1 SET nom_option='test' WHERE id_param=185 AND nom_option='600x1200' AND valid=1 LIMIT 1;
115
select * from t1;
116
drop table t1;
117
118
#
119
# Bug #8057
120
#
121
create table t1 (id int not null auto_increment primary key, id_str varchar(32));
122
insert into t1 (id_str) values ("test");
123
update t1 set id_str = concat(id_str, id) where id = last_insert_id();
124
select * from t1;
125
drop table t1;
126
127
#
128
# Bug #8942: a problem with update and partial key part
129
#
130
131
create table t1 (a int, b char(255), key(a, b(20)));
132
insert into t1 values (0, '1');
133
update t1 set b = b + 1 where a = 0;
134
select * from t1;
135
drop table t1;
136
137
#
138
# Bug #11868 Update with subquery with ref built with a key from the updated
139
#            table crashes server
140
#
141
create table t1(f1 int, f2 int);
142
create table t2(f3 int, f4 int);
143
create index idx on t2(f3);
144
insert into t1 values(1,0),(2,0);
145
insert into t2 values(1,1),(2,2);
146
UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1);
147
select * from t1;
148
drop table t1,t2;
149
150
#
151
# Bug #13180 sometimes server accepts sum func in update/delete where condition
152
#
153
create table t1(f1 int);
154
select DATABASE();
155
--error 1111
156
update t1 set f1=1 where count(*)=1;
157
select DATABASE();
158
--error 1111
159
delete from t1 where count(*)=1;
160
drop table t1;
161
162
# BUG#12915: Optimize "DELETE|UPDATE ... ORDER BY ... LIMIT n" to use an index
163
create table t1 ( a int, b int default 0, index (a) );
164
insert into t1 (a) values (0),(0),(0),(0),(0),(0),(0),(0);
165
166
flush status;
167
select a from t1 order by a limit 1;
1273.16.1 by Brian Aker
More removal of show code.
168
--replace_column 2 #
1 by brian
clean slate
169
show status like 'handler_read%';
170
171
flush status;
172
update t1 set a=9999 order by a limit 1;
173
update t1 set b=9999 order by a limit 1;
1273.16.1 by Brian Aker
More removal of show code.
174
--replace_column 2 #
1 by brian
clean slate
175
show status like 'handler_read%';
176
177
flush status;
178
delete from t1 order by a limit 1;
1273.16.1 by Brian Aker
More removal of show code.
179
--replace_column 2 #
1 by brian
clean slate
180
show status like 'handler_read%';
181
182
flush status;
183
delete from t1 order by a desc limit 1;
1273.16.1 by Brian Aker
More removal of show code.
184
--replace_column 2 #
1 by brian
clean slate
185
show status like 'handler_read%';
186
187
alter table t1 disable keys;
188
189
flush status;
190
delete from t1 order by a limit 1;
1273.16.1 by Brian Aker
More removal of show code.
191
--replace_column 2 #
1 by brian
clean slate
192
show status like 'handler_read%';
193
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
194
# PBXT: this select returns a different result to
195
# innodb because the 2 updates above change different rows
1 by brian
clean slate
196
select * from t1;
197
update t1 set a=a+10,b=1 order by a limit 3;
198
update t1 set a=a+11,b=2 order by a limit 3;
199
update t1 set a=a+12,b=3 order by a limit 3;
200
select * from t1 order by a;
201
202
drop table t1;
203
204
#
205
# Bug#14186 select datefield is null not updated
206
#
873.1.1 by Jay Pipes
Fixes the Field_date class to not allow any invalid input at
207
create table t1 (f1 date NULL);
208
insert into t1 values('2000-01-01'),(NULL);
1 by brian
clean slate
209
update t1 set f1='2002-02-02' where f1 is null;
210
select * from t1;
211
drop table t1;
212
213
# BUG#15935
214
create table t1 (a int);
215
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
216
create table t2 (a int, filler1 char(200), filler2 char(200), key(a));
217
insert into t2 select A.a + 10*B.a, 'filler','filler' from t1 A, t1 B;
218
flush status;
219
update t2 set a=3 where a=2;
1273.16.1 by Brian Aker
More removal of show code.
220
--replace_column 2 #
1 by brian
clean slate
221
show status like 'handler_read%';
222
drop table t1, t2;
223
224
#
225
# Bug #16510 Updating field named like '*name' caused server crash
226
#
227
create table t1(f1 int, `*f2` int);
228
insert into t1 values (1,1);
229
update t1 set `*f2`=1;
230
drop table t1;
231
232
#
233
# Bug#25126: Wrongly resolved field leads to a crash
234
#
235
create table t1(f1 int);
236
--error 1054
237
update t1 set f2=1 order by f2;
238
drop table t1;
239
# End of 4.1 tests
240
241
#
242
# Bug #24035: performance degradation with condition int_field=big_decimal
243
#
244
245
CREATE TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
246
  request_id int NOT NULL auto_increment,
1 by brian
clean slate
247
  user_id varchar(12) default NULL,
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
248
  time_stamp datetime,
1 by brian
clean slate
249
  ip_address varchar(15) default NULL,
250
  PRIMARY KEY (request_id),
251
  KEY user_id_2 (user_id,time_stamp)
252
);
253
254
INSERT INTO t1 (user_id) VALUES ('user1');
255
INSERT INTO t1(user_id) SELECT user_id FROM t1;
256
INSERT INTO t1(user_id) SELECT user_id FROM t1;
257
INSERT INTO t1(user_id) SELECT user_id FROM t1;
258
INSERT INTO t1(user_id) SELECT user_id FROM t1;
259
INSERT INTO t1(user_id) SELECT user_id FROM t1;
260
INSERT INTO t1(user_id) SELECT user_id FROM t1;
261
INSERT INTO t1(user_id) SELECT user_id FROM t1;
262
INSERT INTO t1(user_id) SELECT user_id FROM t1;
263
264
flush status;
265
SELECT user_id FROM t1 WHERE request_id=9999999999999; 
1273.16.1 by Brian Aker
More removal of show code.
266
--replace_column 2 #
1 by brian
clean slate
267
show status like '%Handler_read%';
268
SELECT user_id FROM t1 WHERE request_id=999999999999999999999999999999; 
1273.16.1 by Brian Aker
More removal of show code.
269
--replace_column 2 #
1 by brian
clean slate
270
show status like '%Handler_read%';
271
UPDATE t1 SET user_id=null WHERE request_id=9999999999999;
1273.16.1 by Brian Aker
More removal of show code.
272
--replace_column 2 #
1 by brian
clean slate
273
show status like '%Handler_read%';
274
UPDATE t1 SET user_id=null WHERE request_id=999999999999999999999999999999;
1273.16.1 by Brian Aker
More removal of show code.
275
--replace_column 2 #
1 by brian
clean slate
276
show status like '%Handler_read%';
277
278
DROP TABLE t1;
279
280
#
281
# Bug #24010: INSERT INTO ... SELECT fails on unique constraint with data it 
282
# doesn't select
283
#
284
CREATE TABLE t1 (
285
223 by Brian Aker
Cleanup int() work.
286
  a int,
1 by brian
clean slate
287
  quux decimal( 31, 30 ),
288
289
  UNIQUE KEY bar (a),
290
  KEY quux (quux)
291
);
292
293
INSERT INTO
294
 t1 ( a, quux )
295
VALUES
296
    ( 1,    1 ),
297
    ( 2,  0.1 );
298
299
INSERT INTO t1( a )
300
  SELECT @newA := 1 + a FROM t1 WHERE quux <= 0.1;
301
302
SELECT * FROM t1;
303
304
DROP TABLE t1;
305
306
#
307
# Bug #22364: Inconsistent "matched rows" when executing UPDATE
308
#
309
310
connect (con1,localhost,root,,test);
311
connection con1;
312
313
set tmp_table_size=1024;
314
315
# Create the test tables
316
create table t1 (id int, a int, key idx(a));
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
317
create table t2 (id int not null auto_increment primary key, a int);
1 by brian
clean slate
318
insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
319
insert into t2(a) select a from t2; 
320
insert into t2(a) select a from t2;
321
insert into t2(a) select a from t2; 
322
update t2 set a=id;
323
insert into t1 select * from t2;
324
496.1.2 by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB
325
# PBXT: Rows changed are different here between InnoDB and PBXT
326
# because PBXT does not update the rows that are not modified!
327
# InnoDB seems to do this....
1 by brian
clean slate
328
# Check that the number of matched rows is correct when the temporary
329
# table is small enough to not be converted to MyISAM
330
select count(*) from t1 join t2 on (t1.a=t2.a);
331
332
# Increase table sizes
333
insert into t2(a) select a from t2; 
334
update t2 set a=id; 
335
truncate t1; 
336
insert into t1 select * from t2; 
337
338
# Check that the number of matched rows is correct when the temporary
339
# table has to be converted to MyISAM
340
select count(*) from t1 join t2 on (t1.a=t2.a);
341
342
# Check that the number of matched rows is correct when there are duplicate
343
# key errors
344
update t1 set a=1;
345
update t2 set a=1;
346
select count(*) from t1 join t2 on (t1.a=t2.a);
347
348
drop table t1,t2;
349
1124.2.14 by Diego Medina
* On certain UPDATE and DELETE statements, drizzled failed an assert() in
350
#
351
# Bug #439719: Drizzle crash when running random query generator
352
#
353
CREATE TABLE t1(col1 enum('a','b') NOT NULL, col2 enum('a','b') DEFAULT NULL, KEY col2 (col2));
354
UPDATE t1 SET col1 = "crash" WHERE col2 = now() ;
355
1 by brian
clean slate
356
connection default;
357
disconnect con1;
358
1435.1.6 by Stewart Smith
update test leaving tables in the hallway for me to trip over.
359
drop table t1;
1 by brian
clean slate
360
--echo End of 5.0 tests