Skip to content

Commit 29cc2c2

Browse files
author
Venkatesh Duggirala
committed
BUG#20574550 MAIN.MERGE TEST CASE FAILS IF BINLOG_FORMAT=ROW
The main.merge test case was failing when tested using row based binlog format. While analyzing the issue it was found the following issues: a) The server is calling binlog related code even when a statement will not be binlogged; b) The child table list was not present into table structure by the time to generate the create table statement; c) The tables in the child table list will not be opened yet when generating table create info using row based replication; d) CREATE TABLE LIKE TEMP_TABLE does not preserve original table storage engine when using row based replication; This patch addressed all above issues. @ sql/sql_class.h Added a function to determine if the binary log is disabled to the current session. This is related with issue (a) above. @ sql/sql_table.cc Added code to skip binary logging related code if the statement will not be binlogged. This is related with issue (a) above. Added code to add the children to the query list of the table that will have its CREATE TABLE generated. This is related with issue (b) above. Added code to force the storage engine to be generated into the CREATE TABLE. This is related with issue (d) above. @ storage/myisammrg/ha_myisammrg.cc Added a test to skip a table getting info about a child table if the child table is not opened. This is related to issue (c) above.
1 parent 4ed09d5 commit 29cc2c2

File tree

8 files changed

+104
-10
lines changed

8 files changed

+104
-10
lines changed

mysql-test/suite/binlog/r/binlog_row_binlog.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t2` (
12031203
master-bin.000001 # Query # # COMMIT
12041204
master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t3` (
12051205
`a` int(11) DEFAULT NULL
1206-
)
1206+
) ENGINE=MyISAM
12071207
master-bin.000001 # Query # # BEGIN
12081208
master-bin.000001 # Table_map # # table_id: # (mysql.user)
12091209
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F
@@ -1238,7 +1238,7 @@ master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t2` (
12381238
master-bin.000001 # Query # # COMMIT
12391239
master-bin.000001 # Query # # use `test`; CREATE TABLE IF NOT EXISTS `t3` (
12401240
`a` int(11) DEFAULT NULL
1241-
)
1241+
) ENGINE=MyISAM
12421242
master-bin.000001 # Query # # BEGIN
12431243
master-bin.000001 # Table_map # # table_id: # (mysql.user)
12441244
master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F

mysql-test/suite/rpl/r/rpl_row_merge_engine.result

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ CREATE TABLE t1 (a int) ENGINE=MyISAM;
44
CREATE TABLE t2 (a int) ENGINE=MyISAM;
55
INSERT INTO t1 VALUES (1), (2), (3);
66
INSERT INTO t2 VALUES (4), (5), (6);
7-
CREATE TABLE IF NOT EXISTS t1_merge LIKE t1;
8-
ALTER TABLE t1_merge ENGINE=MERGE UNION (t2, t1);
7+
CREATE TEMPORARY TABLE IF NOT EXISTS tt1_merge LIKE t1;
8+
ALTER TABLE tt1_merge ENGINE=MERGE UNION (t2, t1);
9+
CREATE TABLE t1_merge LIKE tt1_merge;
910
include/diff_tables.inc [master:test.t1, slave:test.t1]
1011
include/diff_tables.inc [master:test.t2, slave:test.t2]
1112
UPDATE t1_merge SET a=10 WHERE a=1;

mysql-test/suite/rpl/r/rpl_tmp_table_and_DDL.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,14 @@ DROP FUNCTION f2;
192192
DROP PROCEDURE p2;
193193
DROP EVENT e2;
194194
DROP TABLE t1, t2;
195+
CREATE TEMPORARY TABLE temp_t1 (c1 INT) ENGINE=InnoDB;
196+
CREATE TEMPORARY TABLE temp_t2 (c1 INT) ENGINE=MyISAM;
197+
CREATE TABLE t1 LIKE temp_t1;
198+
CREATE TABLE t2 LIKE temp_t2;
199+
include/assert.inc ["t1 on master and temp_t1 have the same storage engine"]
200+
include/assert.inc ["t2 on master and temp_t2 have the same storage engine"]
201+
include/assert.inc ["t1 on slave and temp_t1 have the same storage engine"]
202+
include/assert.inc ["t2 on slave and temp_t2 have the same storage engine"]
203+
DROP TEMPORARY TABLE temp_t1, temp_t2;
204+
DROP TABLE t1, t2;
195205
include/rpl_end.inc

mysql-test/suite/rpl/t/rpl_row_merge_engine.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ CREATE TABLE t1 (a int) ENGINE=MyISAM;
2020
CREATE TABLE t2 (a int) ENGINE=MyISAM;
2121
INSERT INTO t1 VALUES (1), (2), (3);
2222
INSERT INTO t2 VALUES (4), (5), (6);
23-
CREATE TABLE IF NOT EXISTS t1_merge LIKE t1;
24-
ALTER TABLE t1_merge ENGINE=MERGE UNION (t2, t1);
23+
# Changed a little to check also an issue reported on BUG#20574550
24+
CREATE TEMPORARY TABLE IF NOT EXISTS tt1_merge LIKE t1;
25+
ALTER TABLE tt1_merge ENGINE=MERGE UNION (t2, t1);
26+
CREATE TABLE t1_merge LIKE tt1_merge;
2527

2628
--sync_slave_with_master
2729

mysql-test/suite/rpl/t/rpl_tmp_table_and_DDL.test

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,55 @@ DROP PROCEDURE p2;
166166
DROP EVENT e2;
167167
DROP TABLE t1, t2;
168168

169+
--sync_slave_with_master
170+
#
171+
# BUG#20574550
172+
# CREATE TABLE LIKE <TEMP_TABLE> does not preserve original table storage
173+
# engine when using row based replication
174+
#
175+
--connection master
176+
177+
# Define temp_t1 and temp_t2 storage engines
178+
--let $engine_temp_t1= InnoDB
179+
--let $engine_temp_t2= MyISAM
180+
181+
# Create the two temporary tables
182+
--eval CREATE TEMPORARY TABLE temp_t1 (c1 INT) ENGINE=$engine_temp_t1
183+
--eval CREATE TEMPORARY TABLE temp_t2 (c1 INT) ENGINE=$engine_temp_t2
184+
185+
# Create t1 and t2 based on temporary tables
186+
CREATE TABLE t1 LIKE temp_t1;
187+
CREATE TABLE t2 LIKE temp_t2;
188+
--sync_slave_with_master
189+
190+
# On master
191+
--connection master
192+
# Assert that t1 and t2 have the same storage engines as temp_t1 and temp_t2
193+
--let $engine_t1= query_get_value(SHOW TABLE STATUS WHERE Name='t1', Engine, 1)
194+
--let $assert_cond= "$engine_t1" = "$engine_temp_t1"
195+
--let $assert_text= "t1 on master and temp_t1 have the same storage engine"
196+
--source include/assert.inc
197+
198+
--let $engine_t2= query_get_value(SHOW TABLE STATUS WHERE Name='t2', Engine, 1)
199+
--let $assert_cond= "$engine_t2" = "$engine_temp_t2"
200+
--let $assert_text= "t2 on master and temp_t2 have the same storage engine"
201+
--source include/assert.inc
202+
203+
# On slave
204+
--connection slave
205+
# Assert that t1 and t2 have the same storage engines as temp_t1 and temp_t2
206+
--let $engine_t1= query_get_value(SHOW TABLE STATUS WHERE Name='t1', Engine, 1)
207+
--let $assert_cond= "$engine_t1" = "$engine_temp_t1"
208+
--let $assert_text= "t1 on slave and temp_t1 have the same storage engine"
209+
--source include/assert.inc
210+
211+
--let $engine_t2= query_get_value(SHOW TABLE STATUS WHERE Name='t2', Engine, 1)
212+
--let $assert_cond= "$engine_t2" = "$engine_temp_t2"
213+
--let $assert_text= "t2 on slave and temp_t2 have the same storage engine"
214+
--source include/assert.inc
215+
216+
# Cleanup
217+
--connection master
218+
DROP TEMPORARY TABLE temp_t1, temp_t2;
219+
DROP TABLE t1, t2;
169220
--source include/rpl_end.inc

sql/sql_class.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -1662,6 +1662,18 @@ class THD :public Statement,
16621662
current_stmt_binlog_format == BINLOG_FORMAT_ROW);
16631663
return current_stmt_binlog_format == BINLOG_FORMAT_ROW;
16641664
}
1665+
/**
1666+
Determine if binlogging is disabled for this session
1667+
@retval 0 if the current statement binlogging is disabled
1668+
(could be because of binlog closed/binlog option
1669+
is set to false).
1670+
@retval 1 if the current statement will be binlogged
1671+
*/
1672+
inline bool is_current_stmt_binlog_disabled() const
1673+
{
1674+
return (!(variables.option_bits & OPTION_BIN_LOG) ||
1675+
!mysql_bin_log.is_open());
1676+
}
16651677

16661678
private:
16671679
/**

sql/sql_table.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -4709,7 +4709,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
47094709
/*
47104710
We have to write the query before we unlock the tables.
47114711
*/
4712-
if (thd->is_current_stmt_binlog_format_row())
4712+
if (!thd->is_current_stmt_binlog_disabled() &&
4713+
thd->is_current_stmt_binlog_format_row())
47134714
{
47144715
/*
47154716
Since temporary tables are not replicated under row-based
@@ -4751,6 +4752,21 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
47514752
if (open_table(thd, table, thd->mem_root, &ot_ctx))
47524753
goto err;
47534754

4755+
/*
4756+
After opening a MERGE table add the children to the query list of
4757+
tables, so that children tables info can be used on "CREATE TABLE"
4758+
statement generation by the binary log.
4759+
Note that placeholders don't have the handler open.
4760+
*/
4761+
if (table->table->file->extra(HA_EXTRA_ADD_CHILDREN_LIST))
4762+
goto err;
4763+
4764+
/*
4765+
As the reference table is temporary and may not exist on slave, we must
4766+
force the ENGINE to be present into CREATE TABLE.
4767+
*/
4768+
create_info->used_fields|= HA_CREATE_USED_ENGINE;
4769+
47544770
int result __attribute__((unused))=
47554771
store_create_info(thd, table, &query,
47564772
create_info, TRUE /* show_database */);

storage/myisammrg/ha_myisammrg.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -1481,6 +1481,8 @@ void ha_myisammrg::update_create_info(HA_CREATE_INFO *create_info)
14811481
open_table != file->end_table ;
14821482
open_table++)
14831483
{
1484+
if (!open_table->table)
1485+
continue;
14841486
TABLE_LIST *ptr;
14851487
LEX_STRING db, name;
14861488
LINT_INIT(db.str);

0 commit comments

Comments
 (0)