Skip to content

Commit ada5410

Browse files
MDEV-9266 Creating index on temporaray table breaks replication
Problem:- Create/drop index was logged into binlog. Goal:- Operation on temporary table should not be binlog when binlog format is row. Solution:- We should add CF_FORCE_ORIGINAL_BINLOG_FORMAT when there is ddl on temp table. For optimize, analyze, repair we wont change anything ,Then will be logged in binlog , But they also dont throw any error if operation fails Since slave wont be having any temp table , but these operation on tmp table will be processed without breaking replication. For rename we need a different logic MDEV-16728 will solve it.
1 parent e5c26fd commit ada5410

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This file runs the query and checks
2+
# whether the size of binlog is increased or not
3+
# If size is changed it issue die command
4+
# Parameters
5+
# $sql_query = query to run
6+
7+
#Only last row of show binlog events matter
8+
--let $tmp= 0
9+
--let $counter= 1
10+
while ($tmp != "No such row")
11+
{
12+
--let $initial_binlog_size= $tmp
13+
--let $tmp= query_get_value(show binary logs, File_size, $counter)
14+
--inc $counter
15+
}
16+
17+
--eval $sql_query
18+
19+
--let $tmp= 0
20+
--let $counter= 1
21+
while ($tmp != "No such row")
22+
{
23+
--let $current_binlog_size= $tmp
24+
--let $tmp= query_get_value(show binary logs, File_size, $counter)
25+
--inc $counter
26+
}
27+
28+
if ($initial_binlog_size != $current_binlog_size)
29+
{
30+
die "Binlog size changed";
31+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RESET MASTER;
2+
#Create table test
3+
create temporary table t1(a int, b int);
4+
#Add index test
5+
create index index_a on t1(a);
6+
#drop index test
7+
drop index index_a on t1;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# ==== Purpose ====
2+
#
3+
# Test if statements used temporary tables are not binlogged in the case of
4+
# binlog_format=row
5+
#
6+
# ==== Method ====
7+
#
8+
# We will see if binlog file size is increased or not, It should be constant for the
9+
# entire period of test.
10+
#
11+
# ==== Related bugs ====
12+
#
13+
# Mdev-9266
14+
#
15+
source include/have_log_bin.inc;
16+
source include/have_binlog_format_row.inc;
17+
18+
RESET MASTER;
19+
20+
--echo #Create table test
21+
--let $sql_query= create temporary table t1(a int, b int)
22+
--source suite/binlog/include/check_binlog_size.inc
23+
24+
--echo #Add index test
25+
--let $sql_query= create index index_a on t1(a)
26+
--source suite/binlog/include/check_binlog_size.inc
27+
28+
--echo #drop index test
29+
--let $sql_query= drop index index_a on t1
30+
--source suite/binlog/include/check_binlog_size.inc

sql/sql_parse.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,9 @@ void init_update_queries(void)
457457
sql_command_flags[SQLCOM_TRUNCATE]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
458458
/* We don't want to replicate DROP for temp tables in row format */
459459
sql_command_flags[SQLCOM_DROP_TABLE]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
460+
/* We don't want to replicate CREATE/DROP INDEX for temp tables in row format */
461+
sql_command_flags[SQLCOM_CREATE_INDEX]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
462+
sql_command_flags[SQLCOM_DROP_INDEX]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
460463
/* One can change replication mode with SET */
461464
sql_command_flags[SQLCOM_SET_OPTION]|= CF_FORCE_ORIGINAL_BINLOG_FORMAT;
462465

0 commit comments

Comments
 (0)