mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / extra / binlog_tests / mix_innodb_myisam_binlog.test
blob5db79e4f848297a7cd161dcac7d3f9d04b785c52
1 # Check that binlog is ok when a transaction mixes updates to InnoDB and
2 # MyISAM.
3 # It would be nice to make this a replication test, but in 4.0 the
4 # slave is always with --skip-innodb in the testsuite. I (Guilhem) however
5 # did some tests manually on a slave; tables are replicated fine and
6 # Exec_Master_Log_Pos advances as expected.
8 -- source include/have_log_bin.inc
9 -- source include/have_innodb.inc
12 --disable_warnings
13 drop table if exists t1, t2;
14 --enable_warnings
16 connect (con1,localhost,root,,);
17 connect (con2,localhost,root,,);
19 connection con1;
20 create table t1 (a int) engine=innodb;
21 create table t2 (a int) engine=myisam;
23 reset master;
25 begin;
26 insert into t1 values(1);
27 insert into t2 select * from t1;
28 commit;
30 source include/show_binlog_events.inc;
32 delete from t1;
33 delete from t2;
34 reset master;
36 begin;
37 insert into t1 values(2);
38 insert into t2 select * from t1;
39 # should say some changes to non-transact1onal tables couldn't be rolled back
40 rollback;
42 source include/show_binlog_events.inc;
44 delete from t1;
45 delete from t2;
46 reset master;
48 begin;
49 insert into t1 values(3);
50 savepoint my_savepoint;
51 insert into t1 values(4);
52 insert into t2 select * from t1;
53 rollback to savepoint my_savepoint;
54 commit;
56 source include/show_binlog_events.inc;
58 delete from t1;
59 delete from t2;
60 reset master;
62 begin;
63 insert into t1 values(5);
64 savepoint my_savepoint;
65 insert into t1 values(6);
66 insert into t2 select * from t1;
67 rollback to savepoint my_savepoint;
68 insert into t1 values(7);
69 commit;
70 select a from t1 order by a; # check that savepoints work :)
72 source include/show_binlog_events.inc;
74 # and when ROLLBACK is not explicit?
75 delete from t1;
76 delete from t2;
77 reset master;
79 select get_lock("a",10);
80 begin;
81 insert into t1 values(8);
82 insert into t2 select * from t1;
83 disconnect con1;
85 connection con2;
86 # We want to SHOW BINLOG EVENTS, to know what was logged. But there is no
87 # guarantee that logging of the terminated con1 has been done yet (it may not
88 # even be started, so con1 may have not even attempted to lock the binlog yet;
89 # so SHOW BINLOG EVENTS may come before con1 does the loggin. To be sure that
90 # logging has been done, we use a user lock.
91 select get_lock("a",10);
92 source include/show_binlog_events.inc;
94 # and when not in a transact1on?
95 delete from t1;
96 delete from t2;
97 reset master;
99 insert into t1 values(9);
100 insert into t2 select * from t1;
102 source include/show_binlog_events.inc;
104 # Check that when the query updat1ng the MyISAM table is the first in the
105 # transaction, we log it immediately.
106 delete from t1;
107 delete from t2;
108 reset master;
110 insert into t1 values(10); # first make t1 non-empty
111 begin;
112 insert into t2 select * from t1;
113 source include/show_binlog_events.inc;
114 insert into t1 values(11);
115 commit;
117 source include/show_binlog_events.inc;
119 # Check that things work like before this BEGIN/ROLLBACK code was added,
120 # when t2 is INNODB 
122 alter table t2 engine=INNODB;
124 delete from t1;
125 delete from t2;
126 reset master;
128 begin;
129 insert into t1 values(12);
130 insert into t2 select * from t1;
131 commit;
133 source include/show_binlog_events.inc;
135 delete from t1;
136 delete from t2;
137 reset master;
139 begin;
140 insert into t1 values(13);
141 insert into t2 select * from t1;
142 rollback;
144 source include/show_binlog_events.inc;
146 delete from t1;
147 delete from t2;
148 reset master;
150 begin;
151 insert into t1 values(14);
152 savepoint my_savepoint;
153 insert into t1 values(15);
154 insert into t2 select * from t1;
155 rollback to savepoint my_savepoint;
156 commit;
158 source include/show_binlog_events.inc;
160 delete from t1;
161 delete from t2;
162 reset master;
164 begin;
165 insert into t1 values(16);
166 savepoint my_savepoint;
167 insert into t1 values(17);
168 insert into t2 select * from t1;
169 rollback to savepoint my_savepoint;
170 insert into t1 values(18);
171 commit;
172 select a from t1 order by a; # check that savepoints work :)
174 source include/show_binlog_events.inc;
176 # Test for BUG#5714, where a MyISAM update in the transaction used to
177 # release row-level locks in InnoDB
179 connect (con3,localhost,root,,);
181 connection con3;
182 delete from t1;
183 delete from t2;
184 --disable_warnings
185 alter table t2 engine=MyISAM;
186 --enable_warnings
187 insert into t1 values (1);
188 begin;
189 select * from t1 for update;
191 connection con2;
192 select (@before:=unix_timestamp())*0; # always give repeatable output
193 begin;
194 send select * from t1 for update;
196 connection con3;
197 insert into t2 values (20);
199 connection con2;
200 --error 1205
201 reap;
202 select (@after:=unix_timestamp())*0; # always give repeatable output
203 # verify that innodb_lock_wait_timeout was exceeded. When there was
204 # the bug, the reap would return immediately after the insert into t2.
205 select (@after-@before) >= 2;
207 drop table t1,t2;
208 commit;
210 # test for BUG#7947 - DO RELEASE_LOCK() not written to binlog on rollback in
211 # the middle of a transaction
213 connection con2;
214 begin;
215 create temporary table ti (a int) engine=innodb;
216 rollback;
217 insert into ti values(1);
218 set autocommit=0;
219 create temporary table t1 (a int) engine=myisam; 
220 commit;
221 insert t1 values (1); 
222 rollback;
223 create table t0 (n int);
224 insert t0 select * from t1;
225 set autocommit=1;
226 insert into t0 select GET_LOCK("lock1",null);
227 set autocommit=0;
228 create table t2 (n int) engine=innodb;
229 insert into t2 values (3); 
230 disconnect con2;
231 connection con3;
232 select get_lock("lock1",60);
233 source include/show_binlog_events.inc;
234 do release_lock("lock1");
235 drop table t0,t2;
237 # End of 4.1 tests
240 # Test behaviour of CREATE ... SELECT when mixing MyISAM and InnoDB tables
243 set autocommit=0;
244 CREATE TABLE t1 (a int, b int) engine=myisam;
245 reset master;
246 INSERT INTO t1 values (1,1),(1,2);
247 --error ER_DUP_ENTRY
248 CREATE TABLE t2 (primary key (a)) engine=innodb select * from t1;
249 # This should give warning
250 DROP TABLE if exists t2;
251 INSERT INTO t1 values (3,3);
252 --error ER_DUP_ENTRY
253 CREATE TEMPORARY TABLE t2 (primary key (a)) engine=innodb select * from t1;
254 ROLLBACK;
255 # This should give warning
256 DROP TABLE IF EXISTS t2;
258 CREATE TABLE t2 (a int, b int, primary key (a)) engine=innodb;
259 INSERT INTO t1 VALUES (4,4);
260 --error ER_DUP_ENTRY
261 CREATE TABLE IF NOT EXISTS t2 (primary key (a)) engine=innodb select * from t1;
262 SELECT * from t2;
263 TRUNCATE table t2;
264 INSERT INTO t1 VALUES (5,5);
265 --error ER_DUP_ENTRY
266 INSERT INTO t2 select * from t1;
267 SELECT * FROM t2;
268 DROP TABLE t2;
270 INSERT INTO t1 values (6,6);
271 CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a)) engine=innodb ;
272 INSERT INTO t1 values (7,7);
273 ROLLBACK;
274 INSERT INTO t1 values (8,8);
275 --error ER_DUP_ENTRY
276 CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) engine=innodb select * from t1;
277 COMMIT;
278 INSERT INTO t1 values (9,9);
279 --error ER_DUP_ENTRY
280 CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) engine=innodb select * from t1;
281 ROLLBACK;
282 SELECT * from t2;
283 TRUNCATE table t2;
284 INSERT INTO t1 values (10,10);
285 --error ER_DUP_ENTRY
286 INSERT INTO t2 select * from t1;
287 SELECT * from t1;
288 INSERT INTO t2 values (100,100);
289 --error ER_DUP_ENTRY
290 CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) engine=innodb select * from t1;
291 COMMIT;
292 INSERT INTO t2 values (101,101);
293 --error ER_DUP_ENTRY
294 CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) engine=innodb select * from t1;
295 ROLLBACK;
296 SELECT * from t2;
297 DROP TABLE t1,t2;
298 source include/show_binlog_events.inc;
300 # Test for BUG#16559 (ROLLBACK should always have a zero error code in
301 # binlog). Has to be here and not earlier, as the SELECTs influence
302 # XIDs differently between normal and ps-protocol (and SHOW BINLOG
303 # EVENTS above read XIDs).
305 connect (con4,localhost,root,,);
306 connection con3;
307 reset master;
308 create table t1 (a int) engine=innodb;
309 create table t2 (a int) engine=myisam;
310 select get_lock("a",10);
311 begin;
312 insert into t1 values(8);
313 insert into t2 select * from t1;
314 disconnect con3;
316 connection con4;
317 select get_lock("a",10); # wait for rollback to finish
318 flush logs;
320 let $MYSQLD_DATADIR= `select @@datadir`;
321 # we check that the error code of the "ROLLBACK" event is 0 and not
322 # ER_SERVER_SHUTDOWN (i.e. disconnection just rolls back transaction
323 # and does not make slave to stop)
324 if (`select @@binlog_format = 'ROW'`)
326   --exec $MYSQL_BINLOG --start-position=524 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
329 if (`select @@binlog_format = 'STATEMENT' || @@binlog_format = 'MIXED'`)
331   --exec $MYSQL_BINLOG --start-position=555 $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output
334 --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
335 eval select
336 (@a:=load_file("$MYSQLTEST_VARDIR/tmp/mix_innodb_myisam_binlog.output"))
337 is not null;
338 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
339 eval select
340 @a like "%#%error_code=0%ROLLBACK\\n/*!*/;%ROLLBACK /* added by mysqlbinlog */;%" OR
341 @a like "%#%error_code=0%ROLLBACK\\r\\n/*!*/;%ROLLBACK /* added by mysqlbinlog */;%",
342 @a not like "%#%error_code=%error_code=%";
343 drop table t1, t2;
346 # Bug #27417    thd->no_trans_update.stmt lost value inside of SF-exec-stack
347 # bug #28960    non-trans temp table changes with insert .. select
348 #               not binlogged after rollback
350 # testing appearence of insert into temp_table in binlog.
351 # There are two branches of execution that require different setup.
353 ## send_eof() branch
355 # prepare
357 create temporary table tt (a int unique);
358 create table ti (a int) engine=innodb;
359 reset master;
361 # action
363 begin; 
364 insert into ti values (1); 
365 insert into ti values (2) ; 
366 insert into tt select * from ti;
367 rollback;
369 # check
371 select count(*) from tt /* 2 */;
372 source include/show_binlog_events.inc;
373 select count(*) from ti /* zero */;
374 insert into ti select * from tt;
375 select * from ti /* that is what slave would miss - a bug */;
378 ## send_error() branch
379 delete from ti;
380 delete from tt where a=1;
381 reset master;
383 # action
385 begin; 
386 insert into ti values (1); 
387 insert into ti values (2) /* to make the dup error in the following */; 
388 --error ER_DUP_ENTRY
389 insert into tt select * from ti /* one affected and error */;
390 rollback;
392 # check
394 source include/show_binlog_events.inc;
395 select count(*) from ti /* zero */;
396 insert into ti select * from tt;
397 select * from tt /* that is what otherwise slave missed - the bug */;
399 drop table ti, tt;
403 # Bug #27417 thd->no_trans_update.stmt lost value inside of SF-exec-stack
405 # Testing asserts: if there is a side effect of modifying non-transactional
406 # table thd->no_trans_update.stmt must be TRUE;
407 # the assert is active with debug build
410 --disable_warnings
411 drop function if exists bug27417;
412 drop table if exists t1,t2;
413 --enable_warnings
414 # side effect table
415 CREATE TABLE t1 (a int NOT NULL auto_increment primary key) ENGINE=MyISAM;
416 # target tables
417 CREATE TABLE t2 (a int NOT NULL auto_increment, PRIMARY KEY (a));
419 delimiter |;
420 create function bug27417(n int)
421 RETURNS int(11)
422 begin
423   insert into t1 values (null);
424   return n;
425 end|
426 delimiter ;|
428 reset master;
430 # execute
432 insert into t2 values (bug27417(1));
433 insert into t2 select bug27417(2);
434 reset master;
436 --error ER_DUP_ENTRY
437 insert into t2 values (bug27417(2)); 
438 source include/show_binlog_events.inc; /* only (!) with fixes for #23333 will show there is the query */;
439 select count(*) from t1 /* must be 3 */;
441 reset master;
442 select count(*) from t2;
443 delete from t2 where a=bug27417(3);
444 select count(*) from t2 /* nothing got deleted */; 
445 source include/show_binlog_events.inc; /* the query must be in regardless of #23333 */;
446 select count(*) from t1 /* must be 5 */;
448 --enable_info
449 delete t2 from t2 where t2.a=bug27417(100) /* must not affect t2 */;
450 --disable_info
451 select count(*) from t1 /* must be 7 */;
453 # function bug27417 remains for the following testing of bug#23333
454 drop table t1,t2;
457 # Bug#23333 using the patch (and the test) for bug#27471
459 # throughout the bug tests 
460 # t1 - non-trans side effects gatherer;
461 # t2 - transactional table;
464 CREATE TABLE t1 (a int  NOT NULL auto_increment primary key) ENGINE=MyISAM;
465 CREATE TABLE t2 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
466 CREATE TABLE t3 (a int, PRIMARY KEY (a), b int unique) ENGINE=MyISAM;
467 CREATE TABLE t4 (a int, PRIMARY KEY (a), b int unique) ENGINE=Innodb;
468 CREATE TABLE t5 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
472 # INSERT
475 # prepare
476   
477  insert into t2 values (1);
478  reset master;
480 # execute
482  --error ER_DUP_ENTRY
483  insert into t2 values (bug27417(1)); 
484   
485 # check
487  source include/show_binlog_events.inc; /* the output must denote there is the query */;
488  select count(*) from t1 /* must be 1 */;
491 # INSERT SELECT
494 # prepare
495  delete from t1;
496  delete from t2;
497  insert into t2 values (2);
498  reset master;
500 # execute
502  --error ER_DUP_ENTRY
503  insert into t2 select bug27417(1) union select bug27417(2); 
504   
505 # check
507  source include/show_binlog_events.inc; /* the output must denote there is the query */;
508  select count(*) from t1 /* must be 2 */;
511 # UPDATE inc multi-update
514 # prepare
515  delete from t1;
516  insert into t3 values (1,1),(2,3),(3,4);
517  reset master;
519 # execute
520  --error ER_DUP_ENTRY
521  update t3 set b=b+bug27417(1);
523 # check
524  source include/show_binlog_events.inc; /* the output must denote there is the query */;
525  select count(*) from t1 /* must be 2 */;
527 ## multi_update::send_eof() branch
529 # prepare
530  delete from t3;
531  delete from t4;
532  insert into t3 values (1,1);
533  insert into t4 values (1,1),(2,2);
535  reset master;
537 # execute
538  --error ER_DUP_ENTRY
539  UPDATE t4,t3 SET t4.a=t3.a + bug27417(1) /* top level non-ta table */;
541 # check
542  source include/show_binlog_events.inc; /* the output must denote there is the query */;
543  select count(*) from t1 /* must be 4 */;
545 ## send_error() branch of multi_update
547 # prepare
548  delete from t1;
549  delete from t3;
550  delete from t4;
551  insert into t3 values (1,1),(2,2);
552  insert into t4 values (1,1),(2,2);
554  reset master;
556 # execute
557  --error ER_DUP_ENTRY
558  UPDATE t3,t4 SET t3.a=t4.a + bug27417(1);
560 # check
561  select count(*) from t1 /* must be 1 */;
563 # cleanup
564  drop table t4;
568 # DELETE incl multi-delete
571 # prepare
572  delete from t1;
573  delete from t2;
574  delete from t3;
575  insert into t2 values (1);
576  insert into t3 values (1,1);
577  create trigger trg_del before delete on t2 for each row 
578    insert into t3 values (bug27417(1), 2);
579  reset master;
581 # execute
582  --error ER_DUP_ENTRY
583  delete from t2;
584 # check
585  source include/show_binlog_events.inc; /* the output must denote there is the query */;
586  select count(*) from t1 /* must be 1 */;
588 # cleanup
589  drop trigger trg_del;
591 # prepare
592  delete from t1;
593  delete from t2;
594  delete from t5;
595  create trigger trg_del_t2 after  delete on t2 for each row
596    insert into t1 values (1);
597  insert into t2 values (2),(3);
598  insert into t5 values (1),(2);
599  reset master;
601 # execute
602  --error ER_DUP_ENTRY
603  delete t2.* from t2,t5 where t2.a=t5.a + 1;
605 # check
606  source include/show_binlog_events.inc; /* the output must denote there is the query */;
607  select count(*) from t1 /* must be 1 */;
611 # LOAD DATA
614 # prepare
615  delete from t1;
616  create table t4 (a int default 0, b int primary key) engine=innodb;
617  insert into t4 values (0, 17);
618  reset master;
620 # execute
621  --error ER_DUP_ENTRY
622  load data infile '../../std_data/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
623 # check
624  select * from t4;
625  select count(*) from t1 /* must be 2 */;
626  source include/show_binlog_events.inc; /* the output must denote there is the query */;
629 # bug#23333 cleanup
633 drop trigger trg_del_t2;
634 drop table t1,t2,t3,t4,t5;
635 drop function bug27417;
638 --echo end of tests