summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <guilhem@gbichot3.local>2006-07-10 18:41:03 +0200
committerunknown <guilhem@gbichot3.local>2006-07-10 18:41:03 +0200
commit20c59f9c4b45e22f0f2083fa8174c59c1bfb787f (patch)
tree2acef150990f6c534e432582eddabf5785f13f1d
parent3a3a5622ab8509a90504faf7bddbd45800bdc3d3 (diff)
downloadmariadb-git-20c59f9c4b45e22f0f2083fa8174c59c1bfb787f.tar.gz
fixes after merge. Updates to test's results.
We now reset the THD members related to auto_increment+binlog in MYSQL_LOG::write(). This is better than in THD::cleanup_after_query(), which was not able to distinguish between SELECT myfunc1(),myfunc2() and INSERT INTO t SELECT myfunc1(),myfunc2() from a binlogging point of view. Rows_log_event::exec_event() now calls lex_start() instead of mysql_init_query() because the latter now does too much (it resets the binlog format). mysql-test/extra/rpl_tests/rpl_insert_id.test: fix after merge mysql-test/mysql-test-run.pl: -v does not bring useful information when running valgrind; I remove it; if you think it's useful add it back. mysql-test/r/binlog_stm_mix_innodb_myisam.result: Position columns of SHOW BINLOG EVENTS are replaced by # (more robust if the size of an event changes). mysql-test/r/rpl_insert_id.result: fix after merge mysql-test/r/rpl_loaddata.result: The binlog positions change, because one event disappeared; indeed there was this in the binlog (in the current 5.1!): SET INSERT_ID=2; SET INSERT_ID=1; SET TIMESTAMP=1152540671; load data LOCAL INFILE '/tmp/SQL_LOAD_MB-1-2' INTO table t1; Two INSERT_ID events, useless and a bug. Goes away afer cleaning up auto_increment handling. mysql-test/r/rpl_switch_stm_row_mixed.result: INSERT_ID=5 appears, it's a consequence of having merged the fix for BUG#20341 "stored function inserting into one auto_increment puts bad data in slave". In mixed mode, if one substatement of a stored procedure requires row-based, the entire procedure uses row-based (was already true for stored functions); this is a consequence of not doing the resetting of binlog format inside lock_tables() (which didn't work with how the slave thread executes row-based binlog events). mysql-test/t/rpl_switch_stm_row_mixed.test: removing the multi-row delayed insert because in RBR the number of events which it generates, is not repeatable (probably depends on how the delayed thread groups rows, i.e. dependent on timing). sql/ha_partition.cc: update to new prototype sql/ha_partition.h: update to new prototype of the handler:: method. sql/handler.cc: after-merge fixes (manually merging part which was hard to merge in fmtool) sql/log.cc: When we write to the binary log, THD's parameters which influenced this write are reset: stmt_depends_on_first_successful_insert_id_in_prev_stmt and auto_inc_intervals_in_cur_stmt_for_binlog. This is so that future writes are not influenced by those and can write their own values. As a consequence, when we don't write to the binlog we do not reset. This is to abide by the rule that in a complex statement (using triggers etc), the first top- or substatement to generate auto_increment ids wins their writing to the binlog (that writing may be done by the statement itself or by the caller); so for example for INSERT INTO t SELECT myfunc() where myfunc() inserts into auto_increment and INSERT INTO t does not, myfunc() will fill auto_inc_intervals_in_cur_stmt_for_binlog, which will not be reset when myfunc() ends, then INSERT INTO t will write to the binlog and thus write the preserved auto_inc_intervals_in_cur_stmt_for_binlog. sql/log_event.cc: mysql_init_query() does too much now to be called in Rows_log_event::exec_event (it call mysql_reset_thd_for_next_command() which may switch the binlog format now). It's ok to call it in Table_map_log_event::exec_event() but its call must be before setting the binlog format to "row". sql/sql_base.cc: Resetting the binlog format in lock_tables() was a bad idea of mine; it causes problems in execution of row-based binlog events, where the thread sets the binlog format by itself and does not want a next lock_tables() to reset the binlog format. It is also misleading, for a function named lock_tables(), to reset the binlog format. As a consequence of this change, in mixed binlogging mode, a routine is logged either entirely statement-based or entirely row-based, we don't switch in the middle (this was already true for prelocked routines, now it's also true for stored procedures). sql/sql_class.cc: resetting of auto_increment variables used for binlogging is now done when writing to the binary log, no need to do the resetting at the end of the statement. It is also more correct this way; consider SELECT myfunc1(),myfunc2(); where both functions insert into the same auto_increment column. Binlogging is done in 2 events: "SELECT myfunc1()" and "SELECT myfunc2()". So each of those needs to have, in binlog, the INSERT_ID which it inserted. But as the 2 function calls are executed under prelocked mode, the old code didn't reset auto_inc_intervals_in_cur_stmt_for_binlog after the first SELECT was binlogged, and so the INSERT_ID of the first SELECT was binlogged for the first SELECT and (wrong) also for the 2nd SELECT event. stmt_depends_on_first_... has the same logic. sql/sql_class.h: clearer comment sql/sql_delete.cc: unneeded #ifdef. As we temporarily change the binlog format to "statement" before calling mysql_delete(), we must restore it afterwards. sql/sql_insert.cc: after-merge fixes. No need to reset auto_inc_intervals_in_cur_stmt_for_binlog for every row in the delayed insert system thread, because we already reset it when writing to the binlog. sql/sql_parse.cc: unneeded #ifdef
-rw-r--r--mysql-test/extra/rpl_tests/rpl_insert_id.test2
-rwxr-xr-xmysql-test/mysql-test-run.pl2
-rw-r--r--mysql-test/r/binlog_stm_mix_innodb_myisam.result190
-rw-r--r--mysql-test/r/rpl_insert_id.result72
-rw-r--r--mysql-test/r/rpl_loaddata.result6
-rw-r--r--mysql-test/r/rpl_switch_stm_row_mixed.result32
-rw-r--r--mysql-test/t/rpl_switch_stm_row_mixed.test12
-rw-r--r--sql/ha_partition.cc2
-rw-r--r--sql/ha_partition.h2
-rw-r--r--sql/handler.cc62
-rw-r--r--sql/log.cc3
-rw-r--r--sql/log_event.cc18
-rw-r--r--sql/sql_base.cc4
-rw-r--r--sql/sql_class.cc12
-rw-r--r--sql/sql_class.h5
-rw-r--r--sql/sql_delete.cc4
-rw-r--r--sql/sql_insert.cc9
-rw-r--r--sql/sql_parse.cc7
18 files changed, 245 insertions, 199 deletions
diff --git a/mysql-test/extra/rpl_tests/rpl_insert_id.test b/mysql-test/extra/rpl_tests/rpl_insert_id.test
index 29a07df2d3c..652ff8881c5 100644
--- a/mysql-test/extra/rpl_tests/rpl_insert_id.test
+++ b/mysql-test/extra/rpl_tests/rpl_insert_id.test
@@ -170,7 +170,7 @@ connection master;
drop function bug15728;
drop function bug15728_insert;
-drop table t1, t2;
+drop table t1;
drop procedure foo;
# test of BUG#20188 REPLACE or ON DUPLICATE KEY UPDATE in
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index fb000906e1e..6f20e7c55b6 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -291,7 +291,7 @@ our $opt_user_test;
our $opt_valgrind= 0;
our $opt_valgrind_mysqld= 0;
our $opt_valgrind_mysqltest= 0;
-our $default_valgrind_options= "-v --show-reachable=yes";
+our $default_valgrind_options= "--show-reachable=yes";
our $opt_valgrind_options;
our $opt_valgrind_path;
diff --git a/mysql-test/r/binlog_stm_mix_innodb_myisam.result b/mysql-test/r/binlog_stm_mix_innodb_myisam.result
index e836cae0b15..95b6eb953a2 100644
--- a/mysql-test/r/binlog_stm_mix_innodb_myisam.result
+++ b/mysql-test/r/binlog_stm_mix_innodb_myisam.result
@@ -8,10 +8,10 @@ insert into t2 select * from t1;
commit;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(1)
-master-bin.000001 257 Query 1 # use `test`; insert into t2 select * from t1
-master-bin.000001 351 Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(1)
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
delete from t1;
delete from t2;
reset master;
@@ -23,10 +23,10 @@ Warnings:
Warning 1196 Some non-transactional changed tables couldn't be rolled back
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(2)
-master-bin.000001 257 Query 1 # use `test`; insert into t2 select * from t1
-master-bin.000001 351 Query 1 # use `test`; ROLLBACK
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(2)
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Query 1 # use `test`; ROLLBACK
delete from t1;
delete from t2;
reset master;
@@ -41,13 +41,13 @@ Warning 1196 Some non-transactional changed tables couldn't be rolled back
commit;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(3)
-master-bin.000001 257 Query 1 # use `test`; savepoint my_savepoint
-master-bin.000001 342 Query 1 # use `test`; insert into t1 values(4)
-master-bin.000001 429 Query 1 # use `test`; insert into t2 select * from t1
-master-bin.000001 523 Query 1 # use `test`; rollback to savepoint my_savepoint
-master-bin.000001 620 Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(3)
+master-bin.000001 # Query 1 # use `test`; savepoint my_savepoint
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(4)
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Query 1 # use `test`; rollback to savepoint my_savepoint
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
delete from t1;
delete from t2;
reset master;
@@ -67,14 +67,14 @@ a
7
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(5)
-master-bin.000001 257 Query 1 # use `test`; savepoint my_savepoint
-master-bin.000001 342 Query 1 # use `test`; insert into t1 values(6)
-master-bin.000001 429 Query 1 # use `test`; insert into t2 select * from t1
-master-bin.000001 523 Query 1 # use `test`; rollback to savepoint my_savepoint
-master-bin.000001 620 Query 1 # use `test`; insert into t1 values(7)
-master-bin.000001 707 Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(5)
+master-bin.000001 # Query 1 # use `test`; savepoint my_savepoint
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(6)
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Query 1 # use `test`; rollback to savepoint my_savepoint
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(7)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
delete from t1;
delete from t2;
reset master;
@@ -89,10 +89,10 @@ get_lock("a",10)
1
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(8)
-master-bin.000001 257 Query 1 # use `test`; insert into t2 select * from t1
-master-bin.000001 351 Query 1 # use `test`; ROLLBACK
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(8)
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Query 1 # use `test`; ROLLBACK
delete from t1;
delete from t2;
reset master;
@@ -100,9 +100,9 @@ insert into t1 values(9);
insert into t2 select * from t1;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; insert into t1 values(9)
-master-bin.000001 189 Xid 1 # COMMIT /* xid= */
-master-bin.000001 216 Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(9)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
delete from t1;
delete from t2;
reset master;
@@ -111,19 +111,19 @@ begin;
insert into t2 select * from t1;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; insert into t1 values(10)
-master-bin.000001 190 Xid 1 # COMMIT /* xid= */
-master-bin.000001 217 Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(10)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
insert into t1 values(11);
commit;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; insert into t1 values(10)
-master-bin.000001 190 Xid 1 # COMMIT /* xid= */
-master-bin.000001 217 Query 1 # use `test`; insert into t2 select * from t1
-master-bin.000001 311 Query 1 # use `test`; BEGIN
-master-bin.000001 379 Query 1 # use `test`; insert into t1 values(11)
-master-bin.000001 467 Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(10)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(11)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
alter table t2 engine=INNODB;
delete from t1;
delete from t2;
@@ -134,10 +134,10 @@ insert into t2 select * from t1;
commit;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(12)
-master-bin.000001 258 Query 1 # use `test`; insert into t2 select * from t1
-master-bin.000001 352 Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(12)
+master-bin.000001 # Query 1 # use `test`; insert into t2 select * from t1
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
delete from t1;
delete from t2;
reset master;
@@ -159,9 +159,9 @@ rollback to savepoint my_savepoint;
commit;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(14)
-master-bin.000001 258 Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(14)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
delete from t1;
delete from t2;
reset master;
@@ -179,10 +179,10 @@ a
18
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(16)
-master-bin.000001 258 Query 1 # use `test`; insert into t1 values(18)
-master-bin.000001 346 Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(16)
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(18)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
delete from t1;
delete from t2;
alter table t2 engine=MyISAM;
@@ -229,29 +229,29 @@ get_lock("lock1",60)
1
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 # use `test`; BEGIN
-master-bin.000001 170 Query 1 # use `test`; insert into t1 values(16)
-master-bin.000001 258 Query 1 # use `test`; insert into t1 values(18)
-master-bin.000001 346 Xid 1 # COMMIT /* xid= */
-master-bin.000001 373 Query 1 # use `test`; delete from t1
-master-bin.000001 450 Xid 1 # COMMIT /* xid= */
-master-bin.000001 477 Query 1 # use `test`; delete from t2
-master-bin.000001 554 Xid 1 # COMMIT /* xid= */
-master-bin.000001 581 Query 1 # use `test`; alter table t2 engine=MyISAM
-master-bin.000001 672 Query 1 # use `test`; insert into t1 values (1)
-master-bin.000001 760 Xid 1 # COMMIT /* xid= */
-master-bin.000001 787 Query 1 # use `test`; insert into t2 values (20)
-master-bin.000001 876 Query 1 # use `test`; drop table t1,t2
-master-bin.000001 955 Query 1 # use `test`; create temporary table ti (a int) engine=innodb
-master-bin.000001 1065 Query 1 # use `test`; insert into ti values(1)
-master-bin.000001 1152 Xid 1 # COMMIT /* xid= */
-master-bin.000001 1179 Query 1 # use `test`; create temporary table t1 (a int) engine=myisam
-master-bin.000001 1289 Query 1 # use `test`; insert t1 values (1)
-master-bin.000001 1372 Query 1 # use `test`; create table t0 (n int)
-master-bin.000001 1458 Query 1 # use `test`; insert t0 select * from t1
-master-bin.000001 1547 Query 1 # use `test`; insert into t0 select GET_LOCK("lock1",null)
-master-bin.000001 1654 Query 1 # use `test`; create table t2 (n int) engine=innodb
-master-bin.000001 1754 Query 1 # use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `test`.`t1`,`test`.`ti`
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(16)
+master-bin.000001 # Query 1 # use `test`; insert into t1 values(18)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; delete from t1
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; delete from t2
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; alter table t2 engine=MyISAM
+master-bin.000001 # Query 1 # use `test`; insert into t1 values (1)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; insert into t2 values (20)
+master-bin.000001 # Query 1 # use `test`; drop table t1,t2
+master-bin.000001 # Query 1 # use `test`; create temporary table ti (a int) engine=innodb
+master-bin.000001 # Query 1 # use `test`; insert into ti values(1)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; create temporary table t1 (a int) engine=myisam
+master-bin.000001 # Query 1 # use `test`; insert t1 values (1)
+master-bin.000001 # Query 1 # use `test`; create table t0 (n int)
+master-bin.000001 # Query 1 # use `test`; insert t0 select * from t1
+master-bin.000001 # Query 1 # use `test`; insert into t0 select GET_LOCK("lock1",null)
+master-bin.000001 # Query 1 # use `test`; create table t2 (n int) engine=innodb
+master-bin.000001 # Query 1 # use `test`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `test`.`t1`,`test`.`ti`
do release_lock("lock1");
drop table t0,t2;
set autocommit=0;
@@ -333,28 +333,28 @@ a b
DROP TABLE t1,t2;
show binlog events from 102;
Log_name Pos Event_type Server_id End_log_pos Info
-master-bin.000001 102 Query 1 198 use `test`; INSERT INTO t1 values (1,1),(1,2)
-master-bin.000001 198 Query 1 284 use `test`; DROP TABLE if exists t2
-master-bin.000001 284 Query 1 374 use `test`; INSERT INTO t1 values (3,3)
-master-bin.000001 374 Query 1 460 use `test`; DROP TABLE IF EXISTS t2
-master-bin.000001 460 Query 1 584 use `test`; CREATE TABLE t2 (a int, b int, primary key (a)) engine=innodb
-master-bin.000001 584 Query 1 674 use `test`; INSERT INTO t1 VALUES (4,4)
-master-bin.000001 674 Query 1 80 use `test`; TRUNCATE table t2
-master-bin.000001 754 Xid 1 781 COMMIT /* xid= */
-master-bin.000001 781 Query 1 871 use `test`; INSERT INTO t1 VALUES (5,5)
-master-bin.000001 871 Query 1 947 use `test`; DROP TABLE t2
-master-bin.000001 947 Query 1 1037 use `test`; INSERT INTO t1 values (6,6)
-master-bin.000001 1037 Query 1 1171 use `test`; CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a)) engine=innodb
-master-bin.000001 1171 Query 1 1261 use `test`; INSERT INTO t1 values (7,7)
-master-bin.000001 1261 Query 1 1351 use `test`; INSERT INTO t1 values (8,8)
-master-bin.000001 1351 Query 1 1441 use `test`; INSERT INTO t1 values (9,9)
-master-bin.000001 1441 Query 1 80 use `test`; TRUNCATE table t2
-master-bin.000001 1521 Xid 1 1548 COMMIT /* xid= */
-master-bin.000001 1548 Query 1 1640 use `test`; INSERT INTO t1 values (10,10)
-master-bin.000001 1640 Query 1 1708 use `test`; BEGIN
-master-bin.000001 1708 Query 1 94 use `test`; INSERT INTO t2 values (100,100)
-master-bin.000001 1802 Xid 1 1829 COMMIT /* xid= */
-master-bin.000001 1829 Query 1 1908 use `test`; DROP TABLE t1,t2
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 values (1,1),(1,2)
+master-bin.000001 # Query 1 # use `test`; DROP TABLE if exists t2
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 values (3,3)
+master-bin.000001 # Query 1 # use `test`; DROP TABLE IF EXISTS t2
+master-bin.000001 # Query 1 # use `test`; CREATE TABLE t2 (a int, b int, primary key (a)) engine=innodb
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES (4,4)
+master-bin.000001 # Query 1 # use `test`; TRUNCATE table t2
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 VALUES (5,5)
+master-bin.000001 # Query 1 # use `test`; DROP TABLE t2
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 values (6,6)
+master-bin.000001 # Query 1 # use `test`; CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a)) engine=innodb
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 values (7,7)
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 values (8,8)
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 values (9,9)
+master-bin.000001 # Query 1 # use `test`; TRUNCATE table t2
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t1 values (10,10)
+master-bin.000001 # Query 1 # use `test`; BEGIN
+master-bin.000001 # Query 1 # use `test`; INSERT INTO t2 values (100,100)
+master-bin.000001 # Xid 1 # COMMIT /* xid= */
+master-bin.000001 # Query 1 # use `test`; DROP TABLE t1,t2
reset master;
create table t1 (a int) engine=innodb;
create table t2 (a int) engine=myisam;
diff --git a/mysql-test/r/rpl_insert_id.result b/mysql-test/r/rpl_insert_id.result
index 56e31b87c89..dbdbcf70944 100644
--- a/mysql-test/r/rpl_insert_id.result
+++ b/mysql-test/r/rpl_insert_id.result
@@ -153,43 +153,8 @@ id last_id
3 5
drop function bug15728;
drop function bug15728_insert;
-drop procedure foo;
drop table t1;
-truncate table t2;
-create table t1 (id tinyint primary key);
-create function insid() returns int
-begin
-insert into t2 (last_id) values (0);
-return 0;
-end|
-set sql_log_bin=0;
-insert into t2 (id) values(1),(2),(3);
-delete from t2;
-set sql_log_bin=1;
-select insid();
-insid()
-0
-set sql_log_bin=0;
-insert into t2 (id) values(5),(6),(7);
-delete from t2 where id>=5;
-set sql_log_bin=1;
-insert into t1 select insid();
-select * from t1;
-id
-0
-select * from t2;
-id last_id
-4 0
-8 0
-select * from t1;
-id
-0
-select * from t2;
-id last_id
-4 0
-8 0
-drop table t1, t2;
-drop function insid;
+drop procedure foo;
create table t1 (n int primary key auto_increment not null,
b int, unique(b));
set sql_log_bin=0;
@@ -255,3 +220,38 @@ n b
2 100
3 350
drop table t1;
+truncate table t2;
+create table t1 (id tinyint primary key);
+create function insid() returns int
+begin
+insert into t2 (last_id) values (0);
+return 0;
+end|
+set sql_log_bin=0;
+insert into t2 (id) values(1),(2),(3);
+delete from t2;
+set sql_log_bin=1;
+select insid();
+insid()
+0
+set sql_log_bin=0;
+insert into t2 (id) values(5),(6),(7);
+delete from t2 where id>=5;
+set sql_log_bin=1;
+insert into t1 select insid();
+select * from t1;
+id
+0
+select * from t2;
+id last_id
+4 0
+8 0
+select * from t1;
+id
+0
+select * from t2;
+id last_id
+4 0
+8 0
+drop table t1, t2;
+drop function insid;
diff --git a/mysql-test/r/rpl_loaddata.result b/mysql-test/r/rpl_loaddata.result
index 4ffa65c2c82..5f8da2ee384 100644
--- a/mysql-test/r/rpl_loaddata.result
+++ b/mysql-test/r/rpl_loaddata.result
@@ -28,7 +28,7 @@ day id category name
2003-03-22 2416 a bbbbb
show master status;
File Position Binlog_Do_DB Binlog_Ignore_DB
-slave-bin.000001 1276
+slave-bin.000001 1248
drop table t1;
drop table t2;
drop table t3;
@@ -39,7 +39,7 @@ set global sql_slave_skip_counter=1;
start slave;
show slave status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
-# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1793 # # master-bin.000001 Yes Yes # 0 0 1793 # None 0 No #
+# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1765 # # master-bin.000001 Yes Yes # 0 0 1765 # None 0 No #
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
@@ -49,7 +49,7 @@ change master to master_user='test';
change master to master_user='root';
show slave status;
Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master
-# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1828 # # master-bin.000001 No No # 0 0 1828 # None 0 No #
+# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 1800 # # master-bin.000001 No No # 0 0 1800 # None 0 No #
set global sql_slave_skip_counter=1;
start slave;
set sql_log_bin=0;
diff --git a/mysql-test/r/rpl_switch_stm_row_mixed.result b/mysql-test/r/rpl_switch_stm_row_mixed.result
index 9e8770ce108..50fdeff2fa1 100644
--- a/mysql-test/r/rpl_switch_stm_row_mixed.result
+++ b/mysql-test/r/rpl_switch_stm_row_mixed.result
@@ -228,7 +228,6 @@ end|
insert into t11 values("try_560_");
insert delayed into t2 values("delay_1_");
insert delayed into t2 values(concat("delay_2_",UUID()));
-insert delayed into t2 values("delay_3_"),(concat("delay_4_",UUID())),("delay_5_");
insert delayed into t2 values("delay_6_");
insert delayed into t2 values(rand());
set @a=2.345;
@@ -274,6 +273,7 @@ create table t13 select * from t1;
drop table t1;
create table t1 (a int primary key auto_increment, b varchar(100));
drop function f;
+create table t14 (unique (a)) select * from t2;
truncate table t2;
create function f1 (x varchar(100)) returns int deterministic
begin
@@ -342,7 +342,7 @@ count(*)
66
select count(*) from t21;
count(*)
-22
+19
select count(*) from t22;
count(*)
2
@@ -352,6 +352,9 @@ count(*)
select count(*) from t13;
count(*)
1
+select count(*) from t14;
+count(*)
+4
select count(*) from t16;
count(*)
3
@@ -455,22 +458,27 @@ begin
insert into t1 values(concat("work_250_",x));
insert into t1 select "yesterday_270_";
end
-master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values("work_25_")
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
-master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 select "yesterday_27_"
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
-master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values("work_29_")
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
-master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values(concat("work_250_", NAME_CONST('x',...
-master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 select "yesterday_270_"
-master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values(concat("work_250_", NAME_CONST('x',...
+master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values(concat("work_250_", NAME_CONST('x',_latin1'hello')))
master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 select "yesterday_270_"
-master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values(concat("work_250_", NAME_CONST('x',...
+master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t1)
+master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
+master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values(concat("work_250_", NAME_CONST('x',_latin1'world')))
master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 select "yesterday_270_"
master-bin.000001 # Query 1 # use `mysqltest1`; drop function foo3
master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` function foo3() returns bigint unsigned
@@ -560,10 +568,6 @@ master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
-master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
-master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
-master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
-master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Query 1 # use `mysqltest1`; create table t20 select * from t1
master-bin.000001 # Query 1 # use `mysqltest1`; create table t21 select * from t2
master-bin.000001 # Query 1 # use `mysqltest1`; create table t22 select * from t3
@@ -600,6 +604,7 @@ master-bin.000001 # Query 1 # use `mysqltest1`; create table t13 select * from t
master-bin.000001 # Query 1 # use `mysqltest1`; drop table t1
master-bin.000001 # Query 1 # use `mysqltest1`; create table t1 (a int primary key auto_increment, b varchar(100))
master-bin.000001 # Query 1 # use `mysqltest1`; drop function f
+master-bin.000001 # Query 1 # use `mysqltest1`; create table t14 (unique (a)) select * from t2
master-bin.000001 # Query 1 # use `mysqltest1`; truncate table t2
master-bin.000001 # Query 1 # use `mysqltest1`; CREATE DEFINER=`root`@`localhost` function f1 (x varchar(100)) returns int deterministic
begin
@@ -647,6 +652,7 @@ master-bin.000001 # Table_map 1 # table_id: # (mysqltest1.t2)
master-bin.000001 # Write_rows 1 # table_id: #
master-bin.000001 # Write_rows 1 # table_id: # flags: STMT_END_F
master-bin.000001 # Query 1 # use `mysqltest1`; alter table t1 modify a int, drop primary key
+master-bin.000001 # Intvar 1 # INSERT_ID=5
master-bin.000001 # Query 1 # use `mysqltest1`; insert into t1 values(null,"try_57_")
master-bin.000001 # Query 1 # use `mysqltest1`; CREATE TABLE `t16` (
`UUID()` varchar(36) CHARACTER SET utf8 NOT NULL DEFAULT ''
diff --git a/mysql-test/t/rpl_switch_stm_row_mixed.test b/mysql-test/t/rpl_switch_stm_row_mixed.test
index aef69df914a..6d282069ba1 100644
--- a/mysql-test/t/rpl_switch_stm_row_mixed.test
+++ b/mysql-test/t/rpl_switch_stm_row_mixed.test
@@ -257,7 +257,6 @@ insert into t11 values("try_560_");
# Test that INSERT DELAYED works in mixed mode (BUG#20649)
insert delayed into t2 values("delay_1_");
insert delayed into t2 values(concat("delay_2_",UUID()));
-insert delayed into t2 values("delay_3_"),(concat("delay_4_",UUID())),("delay_5_");
insert delayed into t2 values("delay_6_");
# Test for BUG#20633 (INSERT DELAYED RAND()/user_variable does not
@@ -364,9 +363,8 @@ create table t1 (a int primary key auto_increment, b varchar(100));
# now test if it's two functions, each of them inserts in one table
drop function f;
-# Manifestation of BUG#20341! re-enable this line after merging fix
-# for that bug
-#create table t14 select * from t2;
+# we need a unique key to have sorting of rows by mysqldump
+create table t14 (unique (a)) select * from t2;
truncate table t2;
delimiter |;
create function f1 (x varchar(100)) returns int deterministic
@@ -453,7 +451,7 @@ select count(*) from t21;
select count(*) from t22;
select count(*) from t12;
select count(*) from t13;
-#select count(*) from t14;
+select count(*) from t14;
select count(*) from t16;
if ($you_want_to_test_UDF)
{
@@ -476,10 +474,8 @@ sync_slave_with_master;
--exec diff $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_master.sql $MYSQLTEST_VARDIR/tmp/rpl_switch_stm_row_mixed_slave.sql;
connection master;
-# As one stored function's parameter is UUID(), its value ends up in a
-# NAME_CONST in the binlog, we must hide it for repeatability
--replace_column 2 # 5 #
---replace_regex /table_id: [0-9]+/table_id: #/ /NAME_CONST\('x',.*/NAME_CONST('x',.../
+--replace_regex /table_id: [0-9]+/table_id: #/
show binlog events from 102;
# Now test that mysqlbinlog works fine on a binlog generated by the
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index c0257e08537..8ed967a0d36 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -5263,7 +5263,7 @@ int ha_partition::cmp_ref(const byte *ref1, const byte *ref2)
MODULE auto increment
****************************************************************************/
-void ha_partition::restore_auto_increment()
+void ha_partition::restore_auto_increment(ulonglong)
{
DBUG_ENTER("ha_partition::restore_auto_increment");
diff --git a/sql/ha_partition.h b/sql/ha_partition.h
index 4c627cd50f8..f9fe5f2501f 100644
--- a/sql/ha_partition.h
+++ b/sql/ha_partition.h
@@ -811,7 +811,7 @@ public:
auto_increment_column_changed
-------------------------------------------------------------------------
*/
- virtual void restore_auto_increment();
+ virtual void restore_auto_increment(ulonglong prev_insert_id);
virtual void get_auto_increment(ulonglong offset, ulonglong increment,
ulonglong nb_desired_values,
ulonglong *first_value,
diff --git a/sql/handler.cc b/sql/handler.cc
index 51b95030929..b356102a61a 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1538,6 +1538,58 @@ compute_next_insert_id(ulonglong nr,struct system_variables *variables)
}
+void handler::adjust_next_insert_id_after_explicit_value(ulonglong nr)
+{
+ /*
+ If we have set THD::next_insert_id previously and plan to insert an
+ explicitely-specified value larger than this, we need to increase
+ THD::next_insert_id to be greater than the explicit value.
+ */
+ if ((next_insert_id > 0) && (nr >= next_insert_id))
+ set_next_insert_id(compute_next_insert_id(nr, &table->in_use->variables));
+}
+
+
+/*
+ Computes the largest number X:
+ - smaller than or equal to "nr"
+ - of the form: auto_increment_offset + N * auto_increment_increment
+ where N>=0.
+
+ SYNOPSIS
+ prev_insert_id
+ nr Number to "round down"
+ variables variables struct containing auto_increment_increment and
+ auto_increment_offset
+
+ RETURN
+ The number X if it exists, "nr" otherwise.
+*/
+
+inline ulonglong
+prev_insert_id(ulonglong nr, struct system_variables *variables)
+{
+ if (unlikely(nr < variables->auto_increment_offset))
+ {
+ /*
+ There's nothing good we can do here. That is a pathological case, where
+ the offset is larger than the column's max possible value, i.e. not even
+ the first sequence value may be inserted. User will receive warning.
+ */
+ DBUG_PRINT("info",("auto_increment: nr: %lu cannot honour "
+ "auto_increment_offset: %lu",
+ nr, variables->auto_increment_offset));
+ return nr;
+ }
+ if (variables->auto_increment_increment == 1)
+ return nr; // optimization of the formula below
+ nr= (((nr - variables->auto_increment_offset)) /
+ (ulonglong) variables->auto_increment_increment);
+ return (nr * (ulonglong) variables->auto_increment_increment +
+ variables->auto_increment_offset);
+}
+
+
/*
Update the auto_increment field if necessary
@@ -1643,8 +1695,7 @@ bool handler::update_auto_increment()
the last NULL needs to insert 3764, not the value of the first NULL plus
1).
*/
- if ((next_insert_id > 0) && (nr >= next_insert_id))
- set_next_insert_id(compute_next_insert_id(nr, variables));
+ adjust_next_insert_id_after_explicit_value(nr);
insert_id_for_cur_row= 0; // didn't generate anything
DBUG_RETURN(0);
}
@@ -1736,12 +1787,15 @@ bool handler::update_auto_increment()
{
/*
field refused this value (overflow) and truncated it, use the result of
- the truncation (which is going to be inserted).
+ the truncation (which is going to be inserted); however we try to
+ decrease it to honour auto_increment_* variables.
That will shift the left bound of the reserved interval, we don't
bother shifting the right bound (anyway any other value from this
interval will cause a duplicate key).
*/
- nr= table->next_number_field->val_int();
+ nr= prev_insert_id(table->next_number_field->val_int(), variables);
+ if (unlikely(table->next_number_field->store((longlong) nr, TRUE)))
+ nr= table->next_number_field->val_int();
}
if (append)
{
diff --git a/sql/log.cc b/sql/log.cc
index c5f5743c51a..b8b9de112ff 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -3401,6 +3401,9 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info)
}
}
}
+ /* Forget those values, for next binlogger: */
+ thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
+ thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
}
/*
diff --git a/sql/log_event.cc b/sql/log_event.cc
index b61f71a4dcf..5541007e0c1 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -5334,10 +5334,10 @@ int Rows_log_event::exec_event(st_relay_log_info *rli)
/*
lock_tables() reads the contents of thd->lex, so they must be
- initialized, so we should call lex_start(); to be even safer, we
- call mysql_init_query() which does a more complete set of inits.
+ initialized. Contrary to in Table_map_log_event::exec_event() we don't
+ call mysql_init_query() as that may reset the binlog format.
*/
- mysql_init_query(thd, NULL, 0);
+ lex_start(thd, NULL, 0);
while ((error= lock_tables(thd, rli->tables_to_lock,
rli->tables_to_lock_count, &need_reopen)))
@@ -5841,6 +5841,12 @@ int Table_map_log_event::exec_event(st_relay_log_info *rli)
else
{
/*
+ open_tables() reads the contents of thd->lex, so they must be
+ initialized, so we should call lex_start(); to be even safer, we
+ call mysql_init_query() which does a more complete set of inits.
+ */
+ mysql_init_query(thd, NULL, 0);
+ /*
Check if the slave is set to use SBR. If so, it should switch
to using RBR until the end of the "statement", i.e., next
STMT_END_F or next error.
@@ -5856,12 +5862,6 @@ int Table_map_log_event::exec_event(st_relay_log_info *rli)
Note that for any table that should not be replicated, a filter is needed.
*/
uint count;
- /*
- open_tables() reads the contents of thd->lex, so they must be
- initialized, so we should call lex_start(); to be even safer, we
- call mysql_init_query() which does a more complete set of inits.
- */
- mysql_init_query(thd, NULL, 0);
if ((error= open_tables(thd, &table_list, &count, 0)))
{
if (thd->query_error || thd->is_fatal_error)
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index a938287ece3..468bdde77e3 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -3319,11 +3319,7 @@ int lock_tables(THD *thd, TABLE_LIST *tables, uint count, bool *need_reopen)
#ifdef HAVE_ROW_BASED_REPLICATION
/*
CREATE ... SELECT UUID() locks no tables, we have to test here.
- Note that we will not do the resetting if inside a stored
- function/trigger, because the binlogging of those is decided earlier (by
- the caller) and can't be changed afterwards.
*/
- thd->reset_current_stmt_binlog_row_based();
if (thd->lex->binlog_row_based_if_mixed)
thd->set_current_stmt_binlog_row_based_if_mixed();
#endif /*HAVE_ROW_BASED_REPLICATION*/
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 634e873fb00..1817697186f 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -631,18 +631,6 @@ bool THD::store_globals()
void THD::cleanup_after_query()
{
- /*
- If in stored function or trigger, where statement-based binlogging logs
- only the caller, the insert_id/last_insert_id stored in binlog must
- describe their first values inside the routine or caller (the values when
- they were first set). Otherwise (e.g. stored procedure) it must describe
- their values for the current substatement.
- */
- if (!prelocked_mode)
- {
- stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
- auto_inc_intervals_in_cur_stmt_for_binlog.empty();
- }
if (first_successful_insert_id_in_cur_stmt > 0)
{
/* set what LAST_INSERT_ID() will return */
diff --git a/sql/sql_class.h b/sql/sql_class.h
index fa1205976f4..3a305d984bf 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1149,8 +1149,9 @@ public:
column; our rules are
a) on master, while executing a top statement involving substatements,
first top- or sub- statement to generate auto_increment values wins the
- exclusive right to write them to binlog (so the losers won't write their
- values to binlog).
+ exclusive right to see its values be written to binlog (the write
+ will be done by the statement or its caller), and the losers won't see
+ their values be written to binlog.
b) on slave, while replicating a top statement involving substatements,
first top- or sub- statement to need to read auto_increment values from
the master's binlog wins the exclusive right to read them (so the losers
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index b9ce1a53aaf..fae1d90cc9a 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -986,12 +986,12 @@ trunc_by_del:
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
ha_enable_transaction(thd, FALSE);
mysql_init_select(thd->lex);
-#ifdef HAVE_ROW_BASED_REPLICATION
+ bool save_binlog_row_based= thd->current_stmt_binlog_row_based;
thd->clear_current_stmt_binlog_row_based();
-#endif
error= mysql_delete(thd, table_list, (COND*) 0, (SQL_LIST*) 0,
HA_POS_ERROR, LL(0), TRUE);
ha_enable_transaction(thd, TRUE);
thd->options= save_options;
+ thd->current_stmt_binlog_row_based= save_binlog_row_based;
DBUG_RETURN(error);
}
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index 1648c6ee198..cd4fb6ace59 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1076,7 +1076,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if (info->ignore &&
!table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
{
- table->file->restore_auto_increment();
+ table->file->restore_auto_increment(prev_insert_id);
goto ok_or_after_trg_err;
}
goto err;
@@ -1096,7 +1096,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
trg_error= (table->triggers &&
table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
TRG_ACTION_AFTER, TRUE));
- info->copiedgoto ok_or_after_trg_err;
+ info->copied++;
+ goto ok_or_after_trg_err;
}
else /* DUP_REPLACE */
{
@@ -1193,7 +1194,7 @@ err:
table->file->print_error(error,MYF(0));
before_trg_err:
- table->file->restore_auto_increment();
+ table->file->restore_auto_increment(prev_insert_id);
if (key)
my_safe_afree(key, table->s->max_unique_length, MAX_KEY_LENGTH);
table->column_bitmaps_set(save_read_set, save_write_set);
@@ -2054,7 +2055,7 @@ bool delayed_insert::handle_inserts(void)
thd.start_time=row->start_time;
thd.query_start_used=row->query_start_used;
/* for the binlog, forget auto_increment ids generated by previous rows */
- thd.auto_inc_intervals_in_cur_stmt_for_binlog.empty();
+// thd.auto_inc_intervals_in_cur_stmt_for_binlog.empty();
thd.first_successful_insert_id_in_prev_stmt=
row->first_successful_insert_id_in_prev_stmt;
thd.stmt_depends_on_first_successful_insert_id_in_prev_stmt=
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 3eeb5bedf41..732aaf2212e 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -5843,10 +5843,11 @@ void mysql_reset_thd_for_next_command(THD *thd)
thd->rand_used= 0;
thd->sent_row_count= thd->examined_row_count= 0;
}
-#ifdef HAVE_ROW_BASED_REPLICATION
- /* If in a routine, we reset only at end of top statement. */
+ /*
+ Because we come here only for start of top-statements, binlog format is
+ constant inside a complex statement (using stored functions) etc.
+ */
thd->reset_current_stmt_binlog_row_based();
-#endif /*HAVE_ROW_BASED_REPLICATION*/
DBUG_VOID_RETURN;
}