~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/multi_update.test

  • Committer: Monty Taylor
  • Date: 2008-08-16 21:06:22 UTC
  • Revision ID: monty@inaugust.com-20080816210622-zpnn13unyinqzn72
Updated po files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Test of update statement that uses many tables.
3
 
#
4
 
 
5
 
source include/have_log_bin.inc;
6
 
 
7
 
--disable_warnings
8
 
drop table if exists t1,t2,t3;
9
 
drop database if exists mysqltest;
10
 
--enable_warnings
11
 
 
12
 
create table t1(id1 int not null auto_increment primary key, t char(12));
13
 
create table t2(id2 int not null, t char(12));
14
 
create table t3(id3 int not null, t char(12), index(id3));
15
 
disable_query_log;
16
 
let $1 = 100;
17
 
while ($1)
18
 
 {
19
 
  let $2 = 5;
20
 
  eval insert into t1(t) values ('$1'); 
21
 
  while ($2)
22
 
   {
23
 
     eval insert into t2(id2,t) values ($1,'$2'); 
24
 
     let $3 = 10;
25
 
     while ($3)
26
 
     {
27
 
       eval insert into t3(id3,t) values ($1,'$2'); 
28
 
       dec $3;
29
 
     }
30
 
     dec $2; 
31
 
   }
32
 
  dec $1;
33
 
 }
34
 
enable_query_log;
35
 
 
36
 
select count(*) from t1 where id1 > 95;
37
 
select count(*) from t2 where id2 > 95;
38
 
select count(*) from t3 where id3 > 95;
39
 
 
40
 
update t1,t2,t3 set t1.t="aaa", t2.t="bbb", t3.t="cc" where  t1.id1 = t2.id2 and t2.id2 = t3.id3  and t1.id1 > 90;
41
 
select count(*) from t1 where t = "aaa";
42
 
select count(*) from t1 where id1 > 90;
43
 
select count(*) from t2 where t = "bbb";
44
 
select count(*) from t2 where id2 > 90;
45
 
select count(*) from t3 where t = "cc";
46
 
select count(*) from t3 where id3 > 90;
47
 
delete t1.*, t2.*, t3.*  from t1,t2,t3 where t1.id1 = t2.id2 and t2.id2 = t3.id3  and t1.id1 > 95;
48
 
 
49
 
check table t1, t2, t3;
50
 
 
51
 
select count(*) from t1 where id1 > 95;
52
 
select count(*) from t2 where id2 > 95;
53
 
select count(*) from t3 where id3 > 95;
54
 
 
55
 
delete t1, t2, t3  from t1,t2,t3 where t1.id1 = t2.id2 and t2.id2 = t3.id3  and t1.id1 > 5;
56
 
select count(*) from t1 where id1 > 5;
57
 
select count(*) from t2 where id2 > 5;
58
 
select count(*) from t3 where id3 > 5;
59
 
 
60
 
delete from t1, t2, t3  using t1,t2,t3 where t1.id1 = t2.id2 and t2.id2 = t3.id3  and t1.id1 > 0;
61
 
 
62
 
# These queries will force a scan of the table
63
 
select count(*) from t1 where id1;
64
 
select count(*) from t2 where id2;
65
 
select count(*) from t3 where id3;
66
 
drop table t1,t2,t3;
67
 
 
68
 
create table t1(id1 int not null  primary key, t varchar(100)) pack_keys = 1;
69
 
create table t2(id2 int not null, t varchar(100), index(id2)) pack_keys = 1;
70
 
disable_query_log;
71
 
let $1 = 1000;
72
 
while ($1)
73
 
 {
74
 
  let $2 = 5;
75
 
  eval insert into t1 values ($1,'aaaaaaaaaaaaaaaaaaaa'); 
76
 
  while ($2)
77
 
   {
78
 
     eval insert into t2(id2,t) values ($1,'bbbbbbbbbbbbbbbbb'); 
79
 
     dec $2; 
80
 
   }
81
 
  dec $1;
82
 
 }
83
 
enable_query_log;
84
 
delete t1  from t1,t2 where t1.id1 = t2.id2 and t1.id1 > 500;
85
 
drop table t1,t2;
86
 
 
87
 
CREATE TABLE t1 (
88
 
  id int NOT NULL default '0',
89
 
  name varchar(10) default NULL,
90
 
  PRIMARY KEY  (id)
91
 
) ENGINE=MyISAM;
92
 
INSERT INTO t1 VALUES (1,'aaa'),(2,'aaa'),(3,'aaa');
93
 
CREATE TABLE t2 (
94
 
  id int NOT NULL default '0',
95
 
  name varchar(10) default NULL,
96
 
  PRIMARY KEY  (id)
97
 
) ENGINE=MyISAM;
98
 
INSERT INTO t2 VALUES (2,'bbb'),(3,'bbb'),(4,'bbb');
99
 
CREATE TABLE t3 (
100
 
  id int NOT NULL default '0',
101
 
  mydate datetime default NULL,
102
 
  PRIMARY KEY  (id)
103
 
) ENGINE=MyISAM;
104
 
INSERT INTO t3 VALUES (1,'2002-02-04 00:00:00'),(3,'2002-05-12 00:00:00'),(5,'2002-05-12 00:00:00'),(6,'2002-06-22
105
 
00:00:00'),(7,'2002-07-22 00:00:00');
106
 
delete t1,t2,t3 from t1,t2,t3 where to_days(now())-to_days(t3.mydate)>=30 and t3.id=t1.id and t3.id=t2.id;
107
 
select * from t3;
108
 
DROP TABLE t1,t2,t3;
109
 
 
110
 
CREATE TABLE IF NOT EXISTS `t1` (
111
 
  `id` int NOT NULL auto_increment,
112
 
  `tst` text,
113
 
  `tst1` text,
114
 
  PRIMARY KEY  (`id`)
115
 
) ENGINE=MyISAM;
116
 
 
117
 
CREATE TABLE IF NOT EXISTS `t2` (
118
 
  `ID` int NOT NULL auto_increment,
119
 
  `ParId` int default NULL,
120
 
  `tst` text,
121
 
  `tst1` text,
122
 
  PRIMARY KEY  (`ID`),
123
 
  KEY `IX_ParId_t2` (`ParId`),
124
 
  FOREIGN KEY (`ParId`) REFERENCES `t1` (`id`)
125
 
) ENGINE=MyISAM;
126
 
 
127
 
INSERT INTO t1(tst,tst1) VALUES("MySQL","MySQL AB"), ("MSSQL","Microsoft"), ("ORACLE","ORACLE");
128
 
 
129
 
INSERT INTO t2(ParId) VALUES(1), (2), (3);
130
 
 
131
 
select * from t2;
132
 
 
133
 
UPDATE t2, t1 SET t2.tst = t1.tst, t2.tst1 = t1.tst1 WHERE t2.ParId = t1.Id;
134
 
 
135
 
select * from t2;
136
 
drop table t1, t2 ;
137
 
 
138
 
create table t1 (n numeric(10));
139
 
create table t2 (n numeric(10));
140
 
insert into t2 values (1),(2),(4),(8),(16),(32);
141
 
select * from t2 left outer join t1  using (n);
142
 
delete  t1,t2 from t2 left outer join t1  using (n);
143
 
select * from t2 left outer join t1  using (n);
144
 
drop table t1,t2 ;
145
 
 
146
 
#
147
 
# Test with locking
148
 
#
149
 
 
150
 
create table t1 (n int not null primary key, d int);
151
 
create table t2 (n int not null primary key, d int);
152
 
insert into t1 values(1,1);
153
 
insert into t2 values(1,10),(2,20);
154
 
LOCK TABLES t1 write, t2 read;
155
 
--error 1099
156
 
DELETE t1.*, t2.* FROM t1,t2 where t1.n=t2.n;
157
 
--error 1099
158
 
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
159
 
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
160
 
unlock tables;
161
 
LOCK TABLES t1 write, t2 write;
162
 
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
163
 
select * from t1;
164
 
DELETE t1.*, t2.* FROM t1,t2 where t1.n=t2.n;
165
 
select * from t1;
166
 
select * from t2;
167
 
unlock tables;
168
 
drop table t1,t2;
169
 
 
170
 
#
171
 
# Test safe updates and timestamps
172
 
#
173
 
set sql_safe_updates=1;
174
 
create table t1 (n int, d int);
175
 
create table t2 (n int, d int);
176
 
insert into t1 values(1,1);
177
 
insert into t2 values(1,10),(2,20);
178
 
--error 1175
179
 
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
180
 
set sql_safe_updates=0;
181
 
drop table t1,t2;
182
 
set timestamp=1038401397;
183
 
create table t1 (n int not null primary key, d int, t timestamp);
184
 
create table t2 (n int not null primary key, d int, t timestamp);
185
 
insert into t1 values(1,1,NULL);
186
 
insert into t2 values(1,10,NULL),(2,20,NULL);
187
 
set timestamp=1038000000;
188
 
UPDATE t1,t2 SET t1.d=t2.d WHERE t1.n=t2.n;
189
 
select n,d,unix_timestamp(t) from t1;
190
 
select n,d,unix_timestamp(t) from t2;
191
 
--error 1064
192
 
UPDATE t1,t2 SET 1=2 WHERE t1.n=t2.n;
193
 
drop table t1,t2;
194
 
set timestamp=0;
195
 
set sql_safe_updates=0;
196
 
create table t1 (n int not null primary key, d int);
197
 
create table t2 (n int not null primary key, d int);
198
 
insert into t1 values(1,1), (3,3);
199
 
insert into t2 values(1,10),(2,20);
200
 
UPDATE t2 left outer join t1 on t1.n=t2.n  SET t1.d=t2.d;
201
 
select * from t1;
202
 
select * from t2;
203
 
drop table t1,t2;
204
 
create table t1 (n int, d int);
205
 
create table t2 (n int, d int);
206
 
insert into t1 values(1,1),(1,2);
207
 
insert into t2 values(1,10),(2,20);
208
 
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
209
 
select * from t1;
210
 
select * from t2;
211
 
drop table t1,t2;
212
 
create table t1 (n int, d int);
213
 
create table t2 (n int, d int);
214
 
insert into t1 values(1,1),(3,2);
215
 
insert into t2 values(1,10),(1,20);
216
 
UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
217
 
select * from t1;
218
 
select * from t2;
219
 
UPDATE t1 a ,t2 b SET a.d=b.d,b.d=30 WHERE a.n=b.n;
220
 
select * from t1;
221
 
select * from t2;
222
 
DELETE a, b  FROM t1 a,t2 b where a.n=b.n;
223
 
select * from t1;
224
 
select * from t2;
225
 
drop table t1,t2;
226
 
 
227
 
CREATE TABLE t1 ( broj int NOT NULL default '0',  naziv char(25) NOT NULL default 'NEPOZNAT',  PRIMARY KEY  (broj)) ENGINE=MyISAM;
228
 
INSERT INTO t1 VALUES (1,'jedan'),(2,'dva'),(3,'tri'),(4,'xxxxxxxxxx'),(5,'a'),(10,''),(11,''),(12,''),(13,'');
229
 
CREATE TABLE t2 ( broj int NOT NULL default '0',  naziv char(25) NOT NULL default 'NEPOZNAT',  PRIMARY KEY  (broj)) ENGINE=MyISAM;
230
 
INSERT INTO t2 VALUES (1,'jedan'),(2,'dva'),(3,'tri'),(4,'xxxxxxxxxx'),(5,'a');
231
 
CREATE TABLE t3 ( broj int NOT NULL default '0',  naziv char(25) NOT NULL default 'NEPOZNAT',  PRIMARY KEY  (broj)) ENGINE=MyISAM;
232
 
INSERT INTO t3 VALUES (1,'jedan'),(2,'dva');
233
 
update t1,t2 set t1.naziv="aaaa" where t1.broj=t2.broj;
234
 
update t1,t2,t3 set t1.naziv="bbbb", t2.naziv="aaaa" where t1.broj=t2.broj and t2.broj=t3.broj;
235
 
drop table t1,t2,t3;
236
 
 
237
 
#
238
 
# Test multi update with different join methods
239
 
#
240
 
 
241
 
CREATE TABLE t1 (a int not null primary key, b int not null, key (b));
242
 
CREATE TABLE t2 (a int not null primary key, b int not null, key (b));
243
 
INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
244
 
INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
245
 
 
246
 
# Full join, without key
247
 
update t1,t2 set t1.a=t1.a+100;
248
 
select * from t1;
249
 
 
250
 
# unique key
251
 
update t1,t2 set t1.a=t1.a+100 where t1.a=101;
252
 
select * from t1;
253
 
 
254
 
# ref key
255
 
update t1,t2 set t1.b=t1.b+10 where t1.b=2;
256
 
select * from t1;
257
 
 
258
 
# Range key (in t1)
259
 
update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t2.a=t1.a-100;
260
 
select * from t1;
261
 
select * from t2;
262
 
 
263
 
# test for non-updating table which is also used in sub-select
264
 
 
265
 
update t1,t2 set t1.b=t2.b, t1.a=t2.a where t1.a=t2.a and not exists (select * from t2 where t2.a > 10);
266
 
 
267
 
drop table t1,t2;
268
 
CREATE TABLE t3 (  KEY1 varchar(50) NOT NULL default '',  PARAM_CORR_DISTANCE_RUSH double default NULL,  PARAM_CORR_DISTANCE_GEM double default NULL,  PARAM_AVG_TARE double default NULL,  PARAM_AVG_NB_DAYS double default NULL,  PARAM_DEFAULT_PROP_GEM_SRVC varchar(50) default NULL,  PARAM_DEFAULT_PROP_GEM_NO_ETIK varchar(50) default NULL,  PARAM_SCENARIO_COSTS varchar(50) default NULL,  PARAM_DEFAULT_WAGON_COST double default NULL,  tmp int default NULL,  PRIMARY KEY  (KEY1)) ENGINE=MyISAM;
269
 
INSERT INTO t3 VALUES ('A',1,1,22,3.2,'R','R','BASE2',0.24,NULL);
270
 
create table t1 (A varchar(1));
271
 
insert into t1 values  ("A") ,("B"),("C"),("D");
272
 
create table t2(Z varchar(15));
273
 
insert into t2(Z)  select concat(a.a,b.a,c.a,d.a) from t1 as a, t1 as b, t1 as c, t1 as d;
274
 
update t2,t3 set Z =param_scenario_costs;
275
 
drop table t1,t2,t3;
276
 
create table t1 (a int, b int);
277
 
create table t2 (a int, b int);
278
 
insert into t1 values (1,1),(2,1),(3,1);
279
 
insert into t2 values (1,1), (3,1);
280
 
update t1 left join t2  on t1.a=t2.a set t1.b=2, t2.b=2 where t1.b=1 and t2.b=1 or t2.a is NULL;
281
 
select t1.a, t1.b,t2.a, t2.b from t1 left join t2  on t1.a=t2.a where t1.b=1 and t2.b=1 or t2.a is NULL;
282
 
drop table t1,t2;
283
 
 
284
 
#
285
 
# Test reuse of same table
286
 
#
287
 
 
288
 
create table t1 (a int not null auto_increment primary key, b int not null);
289
 
insert into t1 (b) values (1),(2),(3),(4);
290
 
update t1, t1 as t2 set t1.b=t2.b+1 where t1.a=t2.a;
291
 
select * from t1;
292
 
drop table t1;
293
 
 
294
 
# Test multi-update and multi-delete with impossible where
295
 
 
296
 
create table t1(id1 int, field char(5));
297
 
create table t2(id2 int, field char(5));
298
 
 
299
 
insert into t1 values (1, 'a'), (2, 'aa');
300
 
insert into t2 values (1, 'b'), (2, 'bb');
301
 
 
302
 
select * from t1;
303
 
select * from t2;
304
 
 
305
 
update t2 inner join t1 on t1.id1=t2.id2
306
 
  set t2.field=t1.field
307
 
  where 0=1;
308
 
update t2, t1 set t2.field=t1.field
309
 
  where t1.id1=t2.id2 and 0=1;
310
 
 
311
 
delete t1, t2 from t2 inner join t1 on t1.id1=t2.id2
312
 
  where 0=1;
313
 
delete t1, t2 from t2,t1 
314
 
  where t1.id1=t2.id2 and 0=1;
315
 
 
316
 
drop table t1,t2;
317
 
 
318
 
#
319
 
# Test for bug #1820.
320
 
#
321
 
 
322
 
create table t1 ( a int not null, b int not null) ;
323
 
--disable_query_log
324
 
insert into t1 values (1,1),(2,2),(3,3),(4,4);
325
 
let $1=19;
326
 
set @d=4;
327
 
while ($1)
328
 
{
329
 
  eval insert into t1 select a+@d,b+@d from t1;
330
 
  eval set @d=@d*2;
331
 
  dec $1;
332
 
}
333
 
 
334
 
--enable_query_log
335
 
alter table t1 add index i1(a);
336
 
delete from t1 where a > 2000000;
337
 
create table t2 like t1;
338
 
insert into t2 select * from t1;
339
 
 
340
 
select 't2 rows before small delete', count(*) from t1;
341
 
delete t1,t2 from t1,t2 where t1.b=t2.a and t1.a < 2;
342
 
select 't2 rows after small delete', count(*) from t2;
343
 
select 't1 rows after small delete', count(*) from t1;
344
 
 
345
 
## Try deleting many rows 
346
 
 
347
 
delete t1,t2 from t1,t2 where t1.b=t2.a and t1.a < 100*1000;
348
 
select 't2 rows after big delete', count(*) from t2;
349
 
select 't1 rows after big delete', count(*) from t1;
350
 
 
351
 
drop table t1,t2;
352
 
 
353
 
#
354
 
# Test alias (this is not correct in 4.0)
355
 
#
356
 
 
357
 
CREATE TABLE t1 ( a int );
358
 
CREATE TABLE t2 ( a int );
359
 
DELETE t1 FROM t1, t2 AS t3;
360
 
DELETE t4 FROM t1, t1 AS t4;
361
 
DELETE t3 FROM t1 AS t3, t1 AS t4;
362
 
--error 1109
363
 
DELETE t1 FROM t1 AS t3, t2 AS t4;
364
 
INSERT INTO t1 values (1),(2);
365
 
INSERT INTO t2 values (1),(2);
366
 
DELETE t1 FROM t1 AS t2, t2 AS t1 where t1.a=t2.a and t1.a=1;
367
 
SELECT * from t1;
368
 
SELECT * from t2;
369
 
DELETE t2 FROM t1 AS t2, t2 AS t1 where t1.a=t2.a and t1.a=2;
370
 
SELECT * from t1;
371
 
SELECT * from t2;
372
 
DROP TABLE t1,t2;
373
 
 
374
 
#
375
 
# Test update with const tables
376
 
#
377
 
create table `t1` (`p_id` int NOT NULL auto_increment, `p_code` varchar(20) NOT NULL default '', `p_active` int NOT NULL default '1', PRIMARY KEY (`p_id`) );
378
 
create table `t2` (`c2_id` int NULL auto_increment, `c2_p_id` int NOT NULL default '0', `c2_note` text NOT NULL, `c2_active` int NOT NULL default '1', PRIMARY KEY (`c2_id`), KEY `c2_p_id` (`c2_p_id`) );
379
 
insert into t1 values (0,'A01-Comp',1);
380
 
insert into t1 values (0,'B01-Comp',1);
381
 
insert into t2 values (0,1,'A Note',1);
382
 
update t1 left join t2 on p_id = c2_p_id set c2_note = 'asdf-1' where p_id = 2; 
383
 
select * from t1;
384
 
select * from t2;
385
 
drop table t1, t2;
386
 
 
387
 
#
388
 
# multi delete wrong table check
389
 
#
390
 
create table t1 (a int, primary key (a));
391
 
create table t2 (a int, primary key (a));
392
 
create table t3 (a int, primary key (a));
393
 
delete t1,t3 from t1,t2 where t1.a=t2.a and t2.a=(select t3.a from t3 where t1.a=t3.a);
394
 
drop table t1, t2, t3;
395
 
 
396
 
#
397
 
# multi* unique updating table check
398
 
#
399
 
create table t1 (col1 int); 
400
 
create table t2 (col1 int);
401
 
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
402
 
delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1;
403
 
drop table t1,t2;
404
 
 
405
 
# Test for BUG#5837 - delete with outer join and const tables
406
 
--disable_warnings
407
 
create table t1 (
408
 
  aclid bigint not null primary key, 
409
 
  status int not null 
410
 
) engine = innodb;
411
 
 
412
 
create table t2 (
413
 
  refid bigint not null primary key, 
414
 
  aclid bigint, index idx_acl(aclid) 
415
 
) engine = innodb;
416
 
--enable_warnings
417
 
insert into t2 values(1,null);
418
 
delete t2, t1 from t2 left join t1 on (t2.aclid=t1.aclid) where t2.refid='1';
419
 
drop table t1, t2;
420
 
 
421
 
#
422
 
# Bug#19225: unchecked error leads to server crash
423
 
#
424
 
create table t1(a int);
425
 
create table t2(a int);
426
 
--error 1093
427
 
delete from t1,t2 using t1,t2 where t1.a=(select a from t1);
428
 
drop table t1, t2;
429
 
# End of 4.1 tests
430
 
 
431
 
#
432
 
# Test for bug #1980.
433
 
#
434
 
--disable_warnings
435
 
create table t1 ( c char(8) not null ) engine=innodb;
436
 
--enable_warnings
437
 
 
438
 
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
439
 
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
440
 
 
441
 
alter table t1 add b char(8) not null;
442
 
alter table t1 add a char(8) not null;
443
 
alter table t1 add primary key (a,b,c);
444
 
update t1 set a=c, b=c;
445
 
 
446
 
create table t2 like t1;
447
 
insert into t2 select * from t1;
448
 
 
449
 
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
450
 
 
451
 
drop table t1,t2;
452
 
 
453
 
--disable_warnings
454
 
create table t1 ( c char(8) not null ) engine=innodb;
455
 
--enable_warnings
456
 
 
457
 
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
458
 
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
459
 
 
460
 
alter table t1 add b char(8) not null;
461
 
alter table t1 add a char(8) not null;
462
 
alter table t1 add primary key (a,b,c);
463
 
update t1 set a=c, b=c;
464
 
 
465
 
create table t2 like t1;
466
 
insert into t2 select * from t1;
467
 
 
468
 
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
469
 
 
470
 
drop table t1,t2;
471
 
 
472
 
#
473
 
# Test alter table and a concurrent multi update
474
 
# (This will force update to reopen tables)
475
 
#
476
 
 
477
 
create table t1 (a int, b int);
478
 
insert into t1 values (1, 2), (2, 3), (3, 4);
479
 
create table t2 (a int);
480
 
insert into t2 values (10), (20), (30);
481
 
create table v1 as select a as b, a/10 as a from t2;
482
 
 
483
 
connect (locker,localhost,root,,test);
484
 
connection locker;
485
 
lock table t1 write;
486
 
 
487
 
connect (changer,localhost,root,,test);
488
 
connection changer;
489
 
send alter table t1 add column c int default 100 after a;
490
 
 
491
 
connect (updater,localhost,root,,test);
492
 
connection updater;
493
 
sleep 2;
494
 
send update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a;
495
 
 
496
 
connection locker;
497
 
sleep 2;
498
 
unlock tables;
499
 
 
500
 
connection changer;
501
 
reap;
502
 
 
503
 
connection updater;
504
 
reap;
505
 
select * from t1;
506
 
select * from t2;
507
 
drop table v1;
508
 
drop table t1, t2;
509
 
 
510
 
#
511
 
# Test multi updates and deletes using primary key and without.
512
 
#
513
 
create table t1 (i1 int, i2 int, i3 int);
514
 
create table t2 (id int, c1 varchar(20), c2 varchar(20));
515
 
insert into t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2);
516
 
insert into t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test");
517
 
select * from t1 order by i1;
518
 
select * from t2;
519
 
update t1,t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id;
520
 
select * from t1 order by i1;
521
 
select * from t2 order by id;
522
 
delete t1.*,t2.* from t1,t2 where t1.i2=t2.id;
523
 
select * from t1 order by i1;
524
 
select * from t2 order by id;
525
 
drop table t1, t2;
526
 
create table t1 (i1 int auto_increment not null, i2 int, i3 int, primary key (i1));
527
 
create table t2 (id int auto_increment not null, c1 varchar(20), c2 varchar(20), primary key(id));
528
 
insert into t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2);
529
 
insert into t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test");
530
 
select * from t1 order by i1;
531
 
select * from t2 order by id;
532
 
update t1,t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id;
533
 
select * from t1 order by i1;
534
 
select * from t2 order by id;
535
 
delete t1.*,t2.* from t1,t2 where t1.i2=t2.id;
536
 
select * from t1 order by i1;
537
 
select * from t2 order by id;
538
 
drop table t1, t2;
539
 
 
540
 
#
541
 
# Bug#27716     multi-update did partially and has not binlogged
542
 
#
543
 
CREATE TABLE `t1` (
544
 
  `a` int NOT NULL auto_increment,
545
 
  `b` int default NULL,
546
 
  PRIMARY KEY  (`a`)
547
 
) ENGINE=MyISAM;
548
 
 
549
 
CREATE TABLE `t2` (
550
 
  `a` int NOT NULL auto_increment,
551
 
  `b` int default NULL,
552
 
  PRIMARY KEY  (`a`)
553
 
) ENGINE=MyISAM;
554
 
 
555
 
#
556
 
# @TODO Only row format now...commenting out.
557
 
# as the test is about to see erroed queries in binlog
558
 
#set @sav_binlog_format=  @@session.binlog_format;
559
 
#set @@session.binlog_format= mixed;
560
 
 
561
 
 
562
 
# A. testing multi_update::send_error() effective update
563
 
insert into t1 values (1,1),(2,2);
564
 
insert into t2 values (1,1),(4,4);
565
 
reset master;
566
 
error ER_DUP_ENTRY;
567
 
UPDATE t2,t1 SET t2.a=t1.a+2;
568
 
# check
569
 
select * from t2 /* must be (3,1), (4,4) */;
570
 
show master status /* there must be the UPDATE query event */;
571
 
 
572
 
# B. testing multi_update::send_error() ineffective update 
573
 
# (as there is a policy described at mysql_update() still go to binlog) 
574
 
delete from t1;
575
 
delete from t2;
576
 
insert into t1 values (1,2),(3,4),(4,4);
577
 
insert into t2 values (1,2),(3,4),(4,4);
578
 
reset master;
579
 
error ER_DUP_ENTRY;
580
 
UPDATE t2,t1  SET t2.a=t2.b where t2.a=t1.a;
581
 
show master status /* there must be the UPDATE query event */;
582
 
 
583
 
# cleanup bug#27716
584
 
drop table t1, t2;
585
 
#set @@session.binlog_format= @sav_binlog_format;
586
 
 
587
 
#
588
 
# Bug #29136    erred multi-delete on trans table does not rollback 
589
 
#
590
 
# @TODO JRP: This doesn't test any rollback! Commenting out...
591
 
# prepare
592
 
#--disable_warnings
593
 
#drop table if exists t1, t2, t3;
594
 
#--enable_warnings
595
 
#CREATE TABLE t1 (a int, PRIMARY KEY (a));
596
 
#CREATE TABLE t2 (a int, PRIMARY KEY (a));
597
 
#CREATE TABLE t3 (a int, PRIMARY KEY (a)) ENGINE=MyISAM;
598
 
#create trigger trg_del_t3 before  delete on t3 for each row insert into t1 values (1);
599
 
 
600
 
#insert into t2 values (1),(2);
601
 
#insert into t3 values (1),(2);
602
 
#reset master;
603
 
 
604
 
# exec cases B, A - see innodb.test
605
 
 
606
 
# B. send_eof() and send_error() afterward
607
 
 
608
 
#--error ER_DUP_ENTRY
609
 
#delete t3.* from t2,t3 where t2.a=t3.a;
610
 
 
611
 
# check
612
 
#select count(*) from t1 /* must be 1 */;
613
 
#select count(*) from t3 /* must be 1 */;
614
 
 
615
 
# cleanup bug#29136
616
 
#drop table t1, t2, t3;
617
 
 
618
 
#
619
 
# Add further tests from here
620
 
#
621
 
 
622
 
 
623
 
--echo end of tests