~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/multi_update.test

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

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