revision-id: 6cf39249150c4f1033f6acde443b5aeb7e20ceff (mariadb-10.0.35-1-g6cf39249150) parent(s): 42fac3241368ad72f8cfef2b8521269e6c173558 author: sachin committer: sachin timestamp: 2018-05-24 14:49:25 +0530 message: MDEV-9266 Creating index on temporaray table breaks replication Problem:- Create index was logged into binlog. Goal:- Operation on temporary table should not be binlog when binlog format is row. Solution:- 1st- We should add CF_FORCE_ORIGINAL_BINLOG_FORMAT when there is ddl on temp table. 2nd- For optimize, analyze and repair we dont check if binlog format is row and this is tmp table, we dont need to log that. --- .../suite/binlog/include/check_binlog_size.inc | 31 +++++++++++ .../suite/binlog/r/binlog_tmp_table_row.result | 41 +++++++++++++++ .../suite/binlog/t/binlog_tmp_table_row.test | 60 ++++++++++++++++++++++ sql/sql_table.cc | 5 ++ 4 files changed, 137 insertions(+) diff --git a/mysql-test/suite/binlog/include/check_binlog_size.inc b/mysql-test/suite/binlog/include/check_binlog_size.inc new file mode 100644 index 00000000000..9df161ec843 --- /dev/null +++ b/mysql-test/suite/binlog/include/check_binlog_size.inc @@ -0,0 +1,31 @@ +# This file runs the query and checks +# whether the size of binlog is increased or not +# If size is changed it issue die command +# Parameters +# $sql_query = query to run + +#Only last row of show binlog events matter +--let $tmp= 0 +--let $counter= 1 +while ($tmp != "No such row") +{ + --let $initial_binlog_size= $tmp + --let $tmp= query_get_value(show binary logs, File_size, $counter) + --inc $counter +} + +--eval $sql_query + +--let $tmp= 0 +--let $counter= 1 +while ($tmp != "No such row") +{ + --let $current_binlog_size= $tmp + --let $tmp= query_get_value(show binary logs, File_size, $counter) + --inc $counter +} + +if ($initial_binlog_size != $current_binlog_size) +{ + die "Binlog size changed"; +} diff --git a/mysql-test/suite/binlog/r/binlog_tmp_table_row.result b/mysql-test/suite/binlog/r/binlog_tmp_table_row.result new file mode 100644 index 00000000000..3f2ef6d5e64 --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_tmp_table_row.result @@ -0,0 +1,41 @@ +RESET MASTER; +#Create table test +create temporary table t1(a int, b int); +#Add index test +create index index_a on t1(a); +#drop index test +drop index index_a on t1; +#Analyze test +analyze table t1; +Table Op Msg_type Msg_text +test.t1 analyze status Table is already up to date +#Optimize test +optimize table t1; +Table Op Msg_type Msg_text +test.t1 optimize status Table is already up to date +#Repair test +repair table t1; +Table Op Msg_type Msg_text +test.t1 repair status OK +#Check test +check table t1; +Table Op Msg_type Msg_text +test.t1 check status OK +#Checksum test +checksum table t1; +Table Checksum +test.t1 0 +#Rename test +rename table t1 to temp_t1; +analyze table non_existing; +Table Op Msg_type Msg_text +test.non_existing analyze Error Table 'test.non_existing' doesn't exist +test.non_existing analyze status Operation failed +optimize table non_existing; +Table Op Msg_type Msg_text +test.non_existing optimize Error Table 'test.non_existing' doesn't exist +test.non_existing optimize status Operation failed +repair table non_existing; +Table Op Msg_type Msg_text +test.non_existing repair Error Table 'test.non_existing' doesn't exist +test.non_existing repair status Operation failed diff --git a/mysql-test/suite/binlog/t/binlog_tmp_table_row.test b/mysql-test/suite/binlog/t/binlog_tmp_table_row.test new file mode 100644 index 00000000000..2f409b28012 --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_tmp_table_row.test @@ -0,0 +1,60 @@ +# ==== Purpose ==== +# +# Test if statements used temporary tables are not binlogged in the case of +# binlog_format=row +# +# ==== Method ==== +# +# We will see if binlog file size is increased or not, It should be constant for the +# entire period of test. +# +# ==== Related bugs ==== +# +# Mdev-9266 +# +source include/have_log_bin.inc; +source include/have_binlog_format_row.inc; + +RESET MASTER; + +--echo #Create table test +--let $sql_query= create temporary table t1(a int, b int) +--source suite/binlog/include/check_binlog_size.inc + +--echo #Add index test +--let $sql_query= create index index_a on t1(a) +--source suite/binlog/include/check_binlog_size.inc + +--echo #drop index test +--let $sql_query= drop index index_a on t1 +--source suite/binlog/include/check_binlog_size.inc + +--echo #Analyze test +--let $sql_query= analyze table t1 +--source suite/binlog/include/check_binlog_size.inc + +--echo #Optimize test +--let $sql_query= optimize table t1 +--source suite/binlog/include/check_binlog_size.inc + +--echo #Repair test +--let $sql_query= repair table t1 +--source suite/binlog/include/check_binlog_size.inc + +--echo #Check test +--let $sql_query= check table t1 +--source suite/binlog/include/check_binlog_size.inc + +--echo #Checksum test +--let $sql_query= checksum table t1 +--source suite/binlog/include/check_binlog_size.inc + +--echo #Rename test +--let $sql_query= rename table t1 to temp_t1 +--source suite/binlog/include/check_binlog_size.inc + + +#should not crash the server +analyze table non_existing; +optimize table non_existing; +repair table non_existing; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 8f3468a44db..74cd15f0a49 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1985,6 +1985,11 @@ int write_bin_log(THD *thd, bool clear_error, char const *query, ulong query_length, bool is_trans) { int error= 0; + TABLE_LIST *first_table= thd->lex->select_lex.table_list.first; + if (!(thd->is_current_stmt_binlog_format_row() && + first_table->table && + first_table->table->s->tmp_table != NO_TMP_TABLE )) + return 0; if (mysql_bin_log.is_open()) { int errcode= 0;