diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 8ba70ffd535..e64954e9f7e 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -1086,6 +1086,39 @@ n d 1 30 2 20 drop table t1,t2; +CREATE TABLE `t1` ( +`a` int(11) NOT NULL auto_increment, +`b` int(11) default NULL, +PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; +CREATE TABLE `t2` ( +`a` int(11) NOT NULL auto_increment, +`b` int(11) default NULL, +PRIMARY KEY (`a`) +) ENGINE=INNODB DEFAULT CHARSET=latin1 ; +insert into t1 values (1,1),(2,2); +insert into t2 values (1,1),(4,4); +reset master; +UPDATE t2,t1 SET t2.a=t1.a+2; +ERROR 23000: Duplicate entry '3' for key 'PRIMARY' +select * from t2 /* must be (3,1), (4,4) */; +a b +1 1 +4 4 +show master status /* there must no UPDATE in binlog */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 106 +delete from t1; +delete from t2; +insert into t1 values (1,2),(3,4),(4,4); +insert into t2 values (1,2),(3,4),(4,4); +reset master; +UPDATE t2,t1 SET t2.a=t2.b where t2.a=t1.a; +ERROR 23000: Duplicate entry '4' for key 'PRIMARY' +show master status /* there must be no UPDATE query event */; +File Position Binlog_Do_DB Binlog_Ignore_DB +master-bin.000001 106 +drop table t1, t2; create table t1 (a int, b int) engine=innodb; insert into t1 values(20,null); select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on @@ -1775,13 +1808,13 @@ Variable_name Value Innodb_page_size 16384 show status like "Innodb_rows_deleted"; Variable_name Value -Innodb_rows_deleted 2070 +Innodb_rows_deleted 2072 show status like "Innodb_rows_inserted"; Variable_name Value -Innodb_rows_inserted 3083 +Innodb_rows_inserted 3088 show status like "Innodb_rows_updated"; Variable_name Value -Innodb_rows_updated 886 +Innodb_rows_updated 888 show status like "Innodb_row_lock_waits"; Variable_name Value Innodb_row_lock_waits 0 diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index 7b0b917cf1a..55e47756312 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -614,27 +614,28 @@ CREATE TABLE `t2` ( `b` int(11) default NULL, PRIMARY KEY (`a`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; +set @@session.binlog_format= mixed; insert into t1 values (1,1),(2,2); insert into t2 values (1,1),(4,4); reset master; UPDATE t2,t1 SET t2.a=t1.a+2; -ERROR 23000: Duplicate entry '3' for key 1 +ERROR 23000: Duplicate entry '3' for key 'PRIMARY' select * from t2 /* must be (3,1), (4,4) */; a b 3 1 4 4 show master status /* there must be the UPDATE query event */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 189 +master-bin.000001 197 delete from t1; delete from t2; insert into t1 values (1,2),(3,4),(4,4); insert into t2 values (1,2),(3,4),(4,4); reset master; UPDATE t2,t1 SET t2.a=t2.b where t2.a=t1.a; -ERROR 23000: Duplicate entry '4' for key 1 +ERROR 23000: Duplicate entry '4' for key 'PRIMARY' show master status /* there must be the UPDATE query event */; File Position Binlog_Do_DB Binlog_Ignore_DB -master-bin.000001 204 +master-bin.000001 212 drop table t1, t2; end of tests diff --git a/mysql-test/r/rpl_row_basic_11bugs.result b/mysql-test/r/rpl_row_basic_11bugs.result index 1025b965589..ca9ba023b1d 100644 --- a/mysql-test/r/rpl_row_basic_11bugs.result +++ b/mysql-test/r/rpl_row_basic_11bugs.result @@ -218,3 +218,27 @@ k HEX(a) HEX(b) 2 0 8 **** On Master **** DROP TABLE IF EXISTS t1_myisam, t1_innodb, t2_myisam, t2_innodb; +drop table if exists t1, t2; +CREATE TABLE `t1` ( +`a` int(11) NOT NULL auto_increment, +`b` int(11) default NULL, +PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; +CREATE TABLE `t2` ( +`a` int(11) NOT NULL auto_increment, +`b` int(11) default NULL, +PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; +insert into t1 values (1,1),(2,2); +insert into t2 values (1,1),(4,4); +UPDATE t2,t1 SET t2.a=t1.a+2; +ERROR 23000: Duplicate entry '3' for key 'PRIMARY' +select * from t2 /* must be (3,1), (4,4) */; +a b +3 1 +4 4 +select * from t2 /* must be (3,1), (4,4) */; +a b +3 1 +4 4 +drop table t1,t2; diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index ec8f1c9a3c1..1ea15664047 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -774,7 +774,7 @@ CREATE TABLE `t2` ( insert into t1 values (1,1),(2,2); insert into t2 values (1,1),(4,4); reset master; ---error ER_DUP_ENTRY +--error ER_DUP_ENTRY_WITH_KEY_NAME UPDATE t2,t1 SET t2.a=t1.a+2; # check select * from t2 /* must be (3,1), (4,4) */; @@ -786,7 +786,7 @@ delete from t2; insert into t1 values (1,2),(3,4),(4,4); insert into t2 values (1,2),(3,4),(4,4); reset master; ---error ER_DUP_ENTRY +--error ER_DUP_ENTRY_WITH_KEY_NAME UPDATE t2,t1 SET t2.a=t2.b where t2.a=t1.a; show master status /* there must be no UPDATE query event */; diff --git a/mysql-test/t/multi_update.test b/mysql-test/t/multi_update.test index baab1c4c468..79d3d18dd13 100644 --- a/mysql-test/t/multi_update.test +++ b/mysql-test/t/multi_update.test @@ -570,10 +570,10 @@ delete t1.*,t2.* from t1,t2 where t1.i2=t2.id; select * from t1 order by i1; select * from t2 order by id; drop table t1, t2; + # # Bug#27716 multi-update did partially and has not binlogged # - CREATE TABLE `t1` ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL, @@ -586,23 +586,28 @@ CREATE TABLE `t2` ( PRIMARY KEY (`a`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; -# A. testing multi_update::send_eof() execution branch +# as the test is about to see erroed queries in binlog +set @@session.binlog_format= mixed; + + +# A. testing multi_update::send_error() effective update insert into t1 values (1,1),(2,2); insert into t2 values (1,1),(4,4); reset master; ---error ER_DUP_ENTRY +--error ER_DUP_ENTRY_WITH_KEY_NAME UPDATE t2,t1 SET t2.a=t1.a+2; # check select * from t2 /* must be (3,1), (4,4) */; show master status /* there must be the UPDATE query event */; -# B. testing multi_update::send_error() execution branch +# B. testing multi_update::send_error() ineffective update +# (as there is a policy described at mysql_update() still go to binlog) delete from t1; delete from t2; insert into t1 values (1,2),(3,4),(4,4); insert into t2 values (1,2),(3,4),(4,4); reset master; ---error ER_DUP_ENTRY +--error ER_DUP_ENTRY_WITH_KEY_NAME UPDATE t2,t1 SET t2.a=t2.b where t2.a=t1.a; show master status /* there must be the UPDATE query event */; diff --git a/mysql-test/t/rpl_row_basic_11bugs.test b/mysql-test/t/rpl_row_basic_11bugs.test index 0109edf4264..6008ce638de 100644 --- a/mysql-test/t/rpl_row_basic_11bugs.test +++ b/mysql-test/t/rpl_row_basic_11bugs.test @@ -184,3 +184,42 @@ SELECT k, HEX(a),HEX(b) FROM t2_innodb; connection master; DROP TABLE IF EXISTS t1_myisam, t1_innodb, t2_myisam, t2_innodb; sync_slave_with_master; + +# +# Bug#27716 multi-update did partially and has not binlogged +# + +connection master; + +--disable_warnings +drop table if exists t1, t2; +--enable_warnings +CREATE TABLE `t1` ( + `a` int(11) NOT NULL auto_increment, + `b` int(11) default NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; + +CREATE TABLE `t2` ( + `a` int(11) NOT NULL auto_increment, + `b` int(11) default NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ; + +# testing multi_update::send_error() effective update +insert into t1 values (1,1),(2,2); +insert into t2 values (1,1),(4,4); + +connection master; +--error ER_DUP_ENTRY_WITH_KEY_NAME +UPDATE t2,t1 SET t2.a=t1.a+2; +select * from t2 /* must be (3,1), (4,4) */; +sync_slave_with_master; + +connection slave; +select * from t2 /* must be (3,1), (4,4) */; + +connection master; +drop table t1,t2; + +sync_slave_with_master; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index c51f7558280..faa5d576e04 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1589,9 +1589,9 @@ void multi_update::send_error(uint errcode,const char *err) */ if (mysql_bin_log.is_open()) { - Query_log_event qinfo(thd, thd->query, thd->query_length, - transactional_tables, FALSE); - mysql_bin_log.write(&qinfo); + thd->binlog_query(THD::ROW_QUERY_TYPE, + thd->query, thd->query_length, + transactional_tables, FALSE); } if (!trans_safe) thd->no_trans_update.all= TRUE;