~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/multi_update.test

  • Committer: Monty Taylor
  • Date: 2009-03-08 23:45:12 UTC
  • mto: (923.2.1 mordred)
  • mto: This revision was merged to the branch mainline in revision 921.
  • Revision ID: mordred@inaugust.com-20090308234512-tqkygxtu1iaig23s
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards!

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
-- error 1109
 
394
delete t1,t3 from t1,t2 where t1.a=t2.a and t2.a=(select t3.a from t3 where t1.a=t3.a);
 
395
drop table t1, t2, t3;
 
396
 
 
397
#
 
398
# multi* unique updating table check
 
399
#
 
400
create table t1 (col1 int); 
 
401
create table t2 (col1 int);
 
402
-- error 1093
 
403
update t1,t2 set t1.col1 = (select max(col1) from t1) where t1.col1 = t2.col1;
 
404
-- error 1093
 
405
delete t1 from t1,t2 where t1.col1 < (select max(col1) from t1) and t1.col1 = t2.col1;
 
406
drop table t1,t2;
 
407
 
 
408
# Test for BUG#5837 - delete with outer join and const tables
 
409
--disable_warnings
 
410
create table t1 (
 
411
  aclid bigint not null primary key, 
 
412
  status int not null 
 
413
) engine = innodb;
 
414
 
 
415
create table t2 (
 
416
  refid bigint not null primary key, 
 
417
  aclid bigint, index idx_acl(aclid) 
 
418
) engine = innodb;
 
419
--enable_warnings
 
420
insert into t2 values(1,null);
 
421
delete t2, t1 from t2 left join t1 on (t2.aclid=t1.aclid) where t2.refid='1';
 
422
drop table t1, t2;
 
423
 
 
424
#
 
425
# Bug#19225: unchecked error leads to server crash
 
426
#
 
427
create table t1(a int);
 
428
create table t2(a int);
 
429
--error 1093
 
430
delete from t1,t2 using t1,t2 where t1.a=(select a from t1);
 
431
drop table t1, t2;
 
432
# End of 4.1 tests
 
433
 
 
434
#
 
435
# Test for bug #1980.
 
436
#
 
437
--disable_warnings
 
438
create table t1 ( c char(8) not null ) engine=innodb;
 
439
--enable_warnings
 
440
 
 
441
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
 
442
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
 
443
 
 
444
alter table t1 add b char(8) not null;
 
445
alter table t1 add a char(8) not null;
 
446
alter table t1 add primary key (a,b,c);
 
447
update t1 set a=c, b=c;
 
448
 
 
449
create table t2 like t1;
 
450
insert into t2 select * from t1;
 
451
 
 
452
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
 
453
 
 
454
drop table t1,t2;
 
455
 
 
456
--disable_warnings
 
457
create table t1 ( c char(8) not null ) engine=innodb;
 
458
--enable_warnings
 
459
 
 
460
insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
 
461
insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
 
462
 
 
463
alter table t1 add b char(8) not null;
 
464
alter table t1 add a char(8) not null;
 
465
alter table t1 add primary key (a,b,c);
 
466
update t1 set a=c, b=c;
 
467
 
 
468
create table t2 like t1;
 
469
insert into t2 select * from t1;
 
470
 
 
471
delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
 
472
 
 
473
drop table t1,t2;
 
474
 
 
475
#
 
476
# Test alter table and a concurrent multi update
 
477
# (This will force update to reopen tables)
 
478
#
 
479
 
 
480
create table t1 (a int, b int);
 
481
insert into t1 values (1, 2), (2, 3), (3, 4);
 
482
create table t2 (a int);
 
483
insert into t2 values (10), (20), (30);
 
484
create table v1 as select a as b, a/10 as a from t2;
 
485
 
 
486
connect (locker,localhost,root,,test);
 
487
connection locker;
 
488
lock table t1 write;
 
489
 
 
490
connect (changer,localhost,root,,test);
 
491
connection changer;
 
492
send alter table t1 add column c int default 100 after a;
 
493
 
 
494
connect (updater,localhost,root,,test);
 
495
connection updater;
 
496
sleep 2;
 
497
send update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a;
 
498
 
 
499
connection locker;
 
500
sleep 2;
 
501
unlock tables;
 
502
 
 
503
connection changer;
 
504
reap;
 
505
 
 
506
connection updater;
 
507
reap;
 
508
select * from t1;
 
509
select * from t2;
 
510
drop table v1;
 
511
drop table t1, t2;
 
512
 
 
513
#
 
514
# Test multi updates and deletes using primary key and without.
 
515
#
 
516
create table t1 (i1 int, i2 int, i3 int);
 
517
create table t2 (id int, c1 varchar(20), c2 varchar(20));
 
518
insert into t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2);
 
519
insert into t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test");
 
520
select * from t1 order by i1;
 
521
select * from t2;
 
522
update t1,t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id;
 
523
select * from t1 order by i1;
 
524
select * from t2 order by id;
 
525
delete t1.*,t2.* from t1,t2 where t1.i2=t2.id;
 
526
select * from t1 order by i1;
 
527
select * from t2 order by id;
 
528
drop table t1, t2;
 
529
create table t1 (i1 int auto_increment not null, i2 int, i3 int, primary key (i1));
 
530
create table t2 (id int auto_increment not null, c1 varchar(20), c2 varchar(20), primary key(id));
 
531
insert into t1 values (1,5,10),(3,7,12),(4,5,2),(9,10,15),(2,2,2);
 
532
insert into t2 values (9,"abc","def"),(5,"opq","lmn"),(2,"test t","t test");
 
533
select * from t1 order by i1;
 
534
select * from t2 order by id;
 
535
update t1,t2 set t1.i2=15, t2.c2="ppc" where t1.i1=t2.id;
 
536
select * from t1 order by i1;
 
537
select * from t2 order by id;
 
538
delete t1.*,t2.* from t1,t2 where t1.i2=t2.id;
 
539
select * from t1 order by i1;
 
540
select * from t2 order by id;
 
541
drop table t1, t2;
 
542
#
 
543
#set @@session.binlog_format= @sav_binlog_format;
 
544
 
 
545
#
 
546
# Bug #29136    erred multi-delete on trans table does not rollback 
 
547
#
 
548
# @TODO JRP: This doesn't test any rollback! Commenting out...
 
549
# prepare
 
550
#--disable_warnings
 
551
#drop table if exists t1, t2, t3;
 
552
#--enable_warnings
 
553
#CREATE TABLE t1 (a int, PRIMARY KEY (a));
 
554
#CREATE TABLE t2 (a int, PRIMARY KEY (a));
 
555
#CREATE TABLE t3 (a int, PRIMARY KEY (a)) ENGINE=MyISAM;
 
556
#create trigger trg_del_t3 before  delete on t3 for each row insert into t1 values (1);
 
557
 
 
558
#insert into t2 values (1),(2);
 
559
#insert into t3 values (1),(2);
 
560
#reset master;
 
561
 
 
562
# exec cases B, A - see innodb.test
 
563
 
 
564
# B. send_eof() and send_error() afterward
 
565
 
 
566
#--error ER_DUP_ENTRY
 
567
#delete t3.* from t2,t3 where t2.a=t3.a;
 
568
 
 
569
# check
 
570
#select count(*) from t1 /* must be 1 */;
 
571
#select count(*) from t3 /* must be 1 */;
 
572
 
 
573
# cleanup bug#29136
 
574
#drop table t1, t2, t3;
 
575
 
 
576
#
 
577
# Add further tests from here
 
578
#
 
579
 
 
580
 
 
581
--echo end of tests