~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/t/update.test

MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
# Some strange updates to test some otherwise unused code
15
15
update t1 set a=a+100 where a=1 and a=2;
16
 
--error ER_BAD_FIELD_ERROR
 
16
--error 1054
17
17
update t1 set a=b+100 where a=1 and a=2; 
18
 
--error ER_BAD_FIELD_ERROR
 
18
--error 1054
19
19
update t1 set a=b+100 where c=1 and a=2; 
20
 
--error ER_BAD_FIELD_ERROR
 
20
--error 1054
21
21
update t1 set d=a+100 where a=1;
22
22
select * from t1;
23
23
drop table t1;
24
24
 
25
25
CREATE TABLE t1
26
26
 (
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,
 
27
 place_id int (10) unsigned NOT NULL,
 
28
 shows int(10) unsigned DEFAULT '0' NOT NULL,
 
29
 ishows int(10) unsigned DEFAULT '0' NOT NULL,
 
30
 ushows int(10) unsigned DEFAULT '0' NOT NULL,
 
31
 clicks int(10) unsigned DEFAULT '0' NOT NULL,
 
32
 iclicks int(10) unsigned DEFAULT '0' NOT NULL,
 
33
 uclicks int(10) unsigned DEFAULT '0' NOT NULL,
34
34
 ts timestamp,
35
35
 PRIMARY KEY (place_id,ts)
36
36
 );
45
45
# Test bug with update reported by Jan Legenhausen
46
46
#
47
47
 
48
 
CREATE TEMPORARY TABLE t1 (
49
 
  lfdnr int NOT NULL default '0',
50
 
  ticket int NOT NULL default '0',
 
48
CREATE TABLE t1 (
 
49
  lfdnr int(10) unsigned NOT NULL default '0',
 
50
  ticket int(10) unsigned NOT NULL default '0',
51
51
  client varchar(255) NOT NULL default '',
52
52
  replyto varchar(255) NOT NULL default '',
53
53
  subject varchar(100) NOT NULL default '',
54
 
  timestamp int NOT NULL default '0',
 
54
  timestamp int(10) unsigned NOT NULL default '0',
55
55
  tstamp timestamp NOT NULL,
56
 
  status int NOT NULL default '0',
 
56
  status int(3) NOT NULL default '0',
57
57
  type varchar(15) NOT NULL default '',
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',
 
58
  assignment int(10) unsigned NOT NULL default '0',
 
59
  fupcount int(4) unsigned NOT NULL default '0',
 
60
  parent int(10) unsigned NOT NULL default '0',
 
61
  activity int(10) unsigned NOT NULL default '0',
 
62
  priority tinyint(1) unsigned NOT NULL default '1',
63
63
  cc varchar(255) NOT NULL default '',
64
64
  bcc varchar(255) NOT NULL default '',
65
65
  body text NOT NULL,
75
75
 
76
76
INSERT INTO t1 VALUES (773,773,'','','',980257344,20010318180652,0,'Open',10,0,0,0,1,'','','','','');
77
77
 
78
 
alter table t1 change lfdnr lfdnr int not null auto_increment;
 
78
alter table t1 change lfdnr lfdnr int(10) unsigned not null auto_increment;
79
79
update t1 set status=1 where type='Open';
80
80
select status from t1;
81
81
drop table t1;
102
102
# Test with limit (Bug #393)
103
103
#
104
104
 
105
 
CREATE TEMPORARY TABLE t1 (
106
 
   `id_param` int NOT NULL default '0',
 
105
CREATE TABLE t1 (
 
106
   `id_param` smallint(3) unsigned NOT NULL default '0',
107
107
   `nom_option` char(40) NOT NULL default '',
108
 
   `valid` int NOT NULL default '0',
 
108
   `valid` tinyint(1) NOT NULL default '0',
109
109
   KEY `id_param` (`id_param`,`nom_option`)
110
110
 ) ENGINE=MyISAM;
111
111
 
116
116
drop table t1;
117
117
 
118
118
#
 
119
# Multi table update test from bugs
 
120
#
 
121
 
 
122
create table t1 (F1 VARCHAR(30), F2 VARCHAR(30), F3 VARCHAR(30), cnt int, groupid int, KEY groupid_index (groupid));
 
123
 
 
124
insert into t1 (F1,F2,F3,cnt,groupid) values ('0','0','0',1,6),
 
125
('0','1','2',1,5), ('0','2','0',1,3), ('1','0','1',1,2),
 
126
('1','2','1',1,1), ('1','2','2',1,1), ('2','0','1',2,4),
 
127
('2','2','0',1,7);
 
128
delete from m1 using t1 m1,t1 m2 where m1.groupid=m2.groupid and (m1.cnt < m2.cnt or m1.cnt=m2.cnt and m1.F3>m2.F3);
 
129
select * from t1;
 
130
drop table t1;
 
131
 
 
132
#
 
133
# Bug#5553 - Multi table UPDATE IGNORE fails on duplicate keys 
 
134
#
 
135
 
 
136
CREATE TABLE t1 ( 
 
137
   `colA` int(10) unsigned NOT NULL auto_increment,
 
138
   `colB` int(11) NOT NULL default '0',
 
139
   PRIMARY KEY  (`colA`)
 
140
);
 
141
INSERT INTO t1 VALUES (4433,5424);
 
142
CREATE TABLE t2 (
 
143
  `colC` int(10) unsigned NOT NULL default '0',
 
144
  `colA` int(10) unsigned NOT NULL default '0',
 
145
  `colD` int(10) unsigned NOT NULL default '0',
 
146
  `colE` int(10) unsigned NOT NULL default '0',
 
147
  `colF` int(10) unsigned NOT NULL default '0',
 
148
  PRIMARY KEY  (`colC`,`colA`,`colD`,`colE`)
 
149
);
 
150
INSERT INTO t2 VALUES (3,4433,10005,495,500);
 
151
INSERT INTO t2 VALUES (3,4433,10005,496,500);
 
152
INSERT INTO t2 VALUES (3,4433,10009,494,500);
 
153
INSERT INTO t2 VALUES (3,4433,10011,494,500);
 
154
INSERT INTO t2 VALUES (3,4433,10005,497,500);
 
155
INSERT INTO t2 VALUES (3,4433,10013,489,500);
 
156
INSERT INTO t2 VALUES (3,4433,10005,494,500);
 
157
INSERT INTO t2 VALUES (3,4433,10005,493,500);
 
158
INSERT INTO t2 VALUES (3,4433,10005,492,500);
 
159
UPDATE IGNORE t2,t1 set t2.colE = t2.colE + 1,colF=0 WHERE t1.colA = t2.colA AND (t1.colB & 4096) > 0 AND (colE + 1) < colF;
 
160
SELECT * FROM t2;
 
161
DROP TABLE t1;
 
162
DROP TABLE t2;
 
163
 
 
164
#
 
165
# Bug #6054 
 
166
#
 
167
create table t1 (c1 int, c2 char(6), c3 int);
 
168
create table t2 (c1 int, c2 char(6));
 
169
insert into t1 values (1, "t1c2-1", 10), (2, "t1c2-2", 20);
 
170
update t1 left join t2 on t1.c1 = t2.c1 set t2.c2 = "t2c2-1";
 
171
update t1 left join t2 on t1.c1 = t2.c1 set t2.c2 = "t2c2-1" where t1.c3 = 10;
 
172
drop table t1, t2;
 
173
 
 
174
#
119
175
# Bug #8057
120
176
#
121
177
create table t1 (id int not null auto_increment primary key, id_str varchar(32));
134
190
select * from t1;
135
191
drop table t1;
136
192
 
 
193
# BUG#9103 "Erroneous data truncation warnings on multi-table updates"
 
194
create table t1 (a int, b varchar(10), key b(b(5))) engine=myisam;
 
195
create table t2 (a int, b varchar(10)) engine=myisam;
 
196
insert into t1 values ( 1, 'abcd1e');
 
197
insert into t1 values ( 2, 'abcd2e');
 
198
insert into t2 values ( 1, 'abcd1e');
 
199
insert into t2 values ( 2, 'abcd2e');
 
200
analyze table t1,t2;
 
201
update t1, t2 set t1.a = t2.a where t2.b = t1.b;
 
202
show warnings;
 
203
drop table t1, t2;
 
204
 
137
205
#
138
206
# Bug #11868 Update with subquery with ref built with a key from the updated
139
207
#            table crashes server
152
220
#
153
221
create table t1(f1 int);
154
222
select DATABASE();
155
 
--error ER_INVALID_GROUP_FUNC_USE
 
223
--error 1111
156
224
update t1 set f1=1 where count(*)=1;
157
225
select DATABASE();
158
 
--error ER_INVALID_GROUP_FUNC_USE
 
226
--error 1111
159
227
delete from t1 where count(*)=1;
160
228
drop table t1;
161
229
 
165
233
 
166
234
flush status;
167
235
select a from t1 order by a limit 1;
168
 
--replace_column 2 #
169
236
show status like 'handler_read%';
170
237
 
171
238
flush status;
172
239
update t1 set a=9999 order by a limit 1;
173
240
update t1 set b=9999 order by a limit 1;
174
 
--replace_column 2 #
175
241
show status like 'handler_read%';
176
242
 
177
243
flush status;
178
244
delete from t1 order by a limit 1;
179
 
--replace_column 2 #
180
245
show status like 'handler_read%';
181
246
 
182
247
flush status;
183
248
delete from t1 order by a desc limit 1;
184
 
--replace_column 2 #
185
249
show status like 'handler_read%';
186
250
 
187
251
alter table t1 disable keys;
188
252
 
189
253
flush status;
190
254
delete from t1 order by a limit 1;
191
 
--replace_column 2 #
192
255
show status like 'handler_read%';
193
256
 
194
 
# PBXT: this select returns a different result to
195
 
# innodb because the 2 updates above change different rows
196
257
select * from t1;
197
258
update t1 set a=a+10,b=1 order by a limit 3;
198
259
update t1 set a=a+11,b=2 order by a limit 3;
204
265
#
205
266
# Bug#14186 select datefield is null not updated
206
267
#
207
 
create table t1 (f1 date NULL);
208
 
insert into t1 values('2000-01-01'),(NULL);
 
268
create table t1 (f1 date not null);
 
269
insert into t1 values('2000-01-01'),('0000-00-00');
209
270
update t1 set f1='2002-02-02' where f1 is null;
210
271
select * from t1;
211
272
drop table t1;
212
273
 
 
274
#
 
275
# Bug#15028 Multitable update returns different numbers of matched rows
 
276
#           depending on table order
 
277
create table t1 (f1 int);
 
278
create table t2 (f2 int);
 
279
insert into t1 values(1),(2);
 
280
insert into t2 values(1),(1);
 
281
--enable_info
 
282
update t1,t2 set f1=3,f2=3 where f1=f2 and f1=1;
 
283
--disable_info
 
284
update t2 set f2=1;
 
285
update t1 set f1=1 where f1=3;
 
286
--enable_info
 
287
update t2,t1 set f1=3,f2=3 where f1=f2 and f1=1;
 
288
--disable_info
 
289
drop table t1,t2;
 
290
 
 
291
 
213
292
# BUG#15935
214
293
create table t1 (a int);
215
294
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
217
296
insert into t2 select A.a + 10*B.a, 'filler','filler' from t1 A, t1 B;
218
297
flush status;
219
298
update t2 set a=3 where a=2;
220
 
--replace_column 2 #
221
299
show status like 'handler_read%';
222
300
drop table t1, t2;
223
301
 
233
311
# Bug#25126: Wrongly resolved field leads to a crash
234
312
#
235
313
create table t1(f1 int);
236
 
--error ER_BAD_FIELD_ERROR
 
314
--error 1054
237
315
update t1 set f2=1 order by f2;
238
316
drop table t1;
239
317
# End of 4.1 tests
243
321
#
244
322
 
245
323
CREATE TABLE t1 (
246
 
  request_id int NOT NULL auto_increment,
 
324
  request_id int unsigned NOT NULL auto_increment,
247
325
  user_id varchar(12) default NULL,
248
 
  time_stamp datetime,
 
326
  time_stamp datetime NOT NULL default '0000-00-00 00:00:00',
249
327
  ip_address varchar(15) default NULL,
250
328
  PRIMARY KEY (request_id),
251
329
  KEY user_id_2 (user_id,time_stamp)
263
341
 
264
342
flush status;
265
343
SELECT user_id FROM t1 WHERE request_id=9999999999999; 
266
 
--replace_column 2 #
267
344
show status like '%Handler_read%';
268
345
SELECT user_id FROM t1 WHERE request_id=999999999999999999999999999999; 
269
 
--replace_column 2 #
270
346
show status like '%Handler_read%';
271
347
UPDATE t1 SET user_id=null WHERE request_id=9999999999999;
272
 
--replace_column 2 #
273
348
show status like '%Handler_read%';
274
349
UPDATE t1 SET user_id=null WHERE request_id=999999999999999999999999999999;
275
 
--replace_column 2 #
276
350
show status like '%Handler_read%';
277
351
 
278
352
DROP TABLE t1;
283
357
#
284
358
CREATE TABLE t1 (
285
359
 
286
 
  a int,
 
360
  a INT(11),
287
361
  quux decimal( 31, 30 ),
288
362
 
289
363
  UNIQUE KEY bar (a),
314
388
 
315
389
# Create the test tables
316
390
create table t1 (id int, a int, key idx(a));
317
 
create table t2 (id int not null auto_increment primary key, a int);
 
391
create table t2 (id int unsigned not null auto_increment primary key, a int);
318
392
insert into t2(a) values(1),(2),(3),(4),(5),(6),(7),(8);
319
393
insert into t2(a) select a from t2; 
320
394
insert into t2(a) select a from t2;
322
396
update t2 set a=id;
323
397
insert into t1 select * from t2;
324
398
 
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....
328
399
# Check that the number of matched rows is correct when the temporary
329
400
# table is small enough to not be converted to MyISAM
330
401
select count(*) from t1 join t2 on (t1.a=t2.a);
 
402
--enable_info
 
403
update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
 
404
--disable_info
331
405
 
332
406
# Increase table sizes
333
407
insert into t2(a) select a from t2; 
338
412
# Check that the number of matched rows is correct when the temporary
339
413
# table has to be converted to MyISAM
340
414
select count(*) from t1 join t2 on (t1.a=t2.a);
 
415
--enable_info
 
416
update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
 
417
--disable_info
341
418
 
342
419
# Check that the number of matched rows is correct when there are duplicate
343
420
# key errors
344
421
update t1 set a=1;
345
422
update t2 set a=1;
346
423
select count(*) from t1 join t2 on (t1.a=t2.a);
 
424
--enable_info
 
425
update t1 join t2 on (t1.a=t2.a) set t1.id=t2.id;
 
426
--disable_info
347
427
 
348
428
drop table t1,t2;
349
429
 
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
 
 
356
430
connection default;
357
431
disconnect con1;
358
432
 
359
 
drop table t1;
360
433
--echo End of 5.0 tests