From ccc3a468562d195505ee458faad71897889d58fe Mon Sep 17 00:00:00 2001 From: Date: Thu, 31 Dec 2009 11:33:10 +0800 Subject: [PATCH] Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE In statement-based or mixed-mode replication, use DROP TEMPORARY TABLE to drop multiple tables causes different errors on master and slave, when one or more of these tables do not exist. Because when executed on slave, it would automatically add IF EXISTS to the query to ignore all ER_BAD_TABLE_ERROR errors. To fix the problem, do not add IF EXISTS when executing DROP TEMPORARY TABLE on the slave, and clear the ER_BAD_TABLE_ERROR error after execution if the query does not expect any errors. --- mysql-test/r/rpl_drop_temp.result | 14 +++++++++++++ mysql-test/t/rpl_drop_temp.test | 33 +++++++++++++++++++++++++++++++ sql/log_event.cc | 12 ++++++++++- sql/sql_parse.cc | 11 ----------- 4 files changed, 58 insertions(+), 12 deletions(-) diff --git a/mysql-test/r/rpl_drop_temp.result b/mysql-test/r/rpl_drop_temp.result index fff179d7056..48a21b1702b 100644 --- a/mysql-test/r/rpl_drop_temp.result +++ b/mysql-test/r/rpl_drop_temp.result @@ -18,3 +18,17 @@ show status like 'Slave_open_temp_tables'; Variable_name Value Slave_open_temp_tables 0 drop database mysqltest; +DROP TEMPORARY TABLE IF EXISTS tmp1; +Warnings: +Note 1051 Unknown table 'tmp1' +CREATE TEMPORARY TABLE t1 ( a int ); +DROP TEMPORARY TABLE t1, t2; +ERROR 42S02: Unknown table 't2' +DROP TEMPORARY TABLE tmp2; +ERROR 42S02: Unknown table 'tmp2' +stop slave; +**** On Master **** +CREATE TEMPORARY TABLE tmp3 (a int); +DROP TEMPORARY TABLE tmp3; +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; diff --git a/mysql-test/t/rpl_drop_temp.test b/mysql-test/t/rpl_drop_temp.test index c22bcbe63d0..c2dc8b0ea49 100644 --- a/mysql-test/t/rpl_drop_temp.test +++ b/mysql-test/t/rpl_drop_temp.test @@ -20,5 +20,38 @@ connection slave; show status like 'Slave_open_temp_tables'; connection master; drop database mysqltest; +sync_slave_with_master; + +# +# Bug#49137 +# This test verifies if DROP MULTI TEMPORARY TABLE +# will cause different errors on master and slave, +# when one or more of these tables do not exist. +# + +connection master; +DROP TEMPORARY TABLE IF EXISTS tmp1; +CREATE TEMPORARY TABLE t1 ( a int ); +--error 1051 +DROP TEMPORARY TABLE t1, t2; +--error 1051 +DROP TEMPORARY TABLE tmp2; +sync_slave_with_master; + +connection slave; +stop slave; +wait_for_slave_to_stop; + +--echo **** On Master **** +connection master; +CREATE TEMPORARY TABLE tmp3 (a int); +DROP TEMPORARY TABLE tmp3; + +connection slave; +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +START SLAVE; + +connection master; +sync_slave_with_master; # End of 4.1 tests diff --git a/sql/log_event.cc b/sql/log_event.cc index 40e29e58ab6..35d53c4fede 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2103,7 +2103,17 @@ START SLAVE; . Query: '%s'", expected_error, thd->query); compare_errors: - /* + /* + In the slave thread, we may sometimes execute some DROP / * 40005 + TEMPORARY * / TABLE that come from parts of binlogs (likely if we + use RESET SLAVE or CHANGE MASTER TO), while the temporary table + has already been dropped. To ignore such irrelevant "table does + not exist errors", we silently clear the error if TEMPORARY was used. + */ + if (thd->lex->drop_temporary && + thd->net.last_errno == ER_BAD_TABLE_ERROR && !expected_error) + thd->clear_error(); + /* If we expected a non-zero error code, and we don't get the same error code, and none of them should be ignored. */ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 48df40f2614..61c2d70a563 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4038,17 +4038,6 @@ end_with_restore_list: } else { - /* - If this is a slave thread, we may sometimes execute some - DROP / * 40005 TEMPORARY * / TABLE - that come from parts of binlogs (likely if we use RESET SLAVE or CHANGE - MASTER TO), while the temporary table has already been dropped. - To not generate such irrelevant "table does not exist errors", - we silently add IF EXISTS if TEMPORARY was used. - */ - if (thd->slave_thread) - lex->drop_if_exists= 1; - /* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */ thd->transaction.all.modified_non_trans_table= TRUE; }