~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-16 16:56:48 UTC
  • mto: This revision was merged to the branch mainline in revision 938.
  • Revision ID: mordred@inaugust.com-20090316165648-0dsce73jne0qikk0
Addd -Wshadow to PROTOSKIP warnings and turned -Wstrict-aliasing off. Jumped the gun...

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