From 339deb0c07eab5f563a4a72b08bf0162953b4f62 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jun 2006 10:40:36 +0200 Subject: [PATCH] Fix for BUG#20522 "RBR: CREATE TEMPORARY TABLE SELECT writes to binlog though unneeded". It's indeed unneeded, as slave is only interested in permanent tables, and permanent tables don't depend on temporary tables when in row-based binlogging mode. And other CREATE TEMPORARY TABLE (referring no table or with LIKE) already don't write the CREATE to binlog in row-based mode. mysql-test/r/rpl_row_create_table.result: result update (note that no lines appear in SHOW BINLOG EVENTS further below, which is how we see the bug is fixed) mysql-test/t/rpl_row_create_table.test: testing if a CREATE TEMPORARY TABLE SELECT goes to binlog (it should not) when in row-based binlogging mode. A few lines after, there is a SHOW BINLOG EVENTS; before the bugfix it showed the CREATE TEMPORARY TABLE. sql/sql_class.h: a method to access select_create::create_info from outside of select_create ("read-only" access). Making get_thd() "read-only" too. sql/sql_insert.cc: The function (hook) which writes CREATE TABLE to binlog when in row-based binlogging mode, for CREATE TABLE SELECT, now does nothing if the table is temporary (as in row-based mode, temp tables are not replicated). This is consistent with CREATE TEMPORARY TABLE LIKE and CREATE TEMPORARY TABLE, which don't write any CREATE to binlog in row-based mode. --- mysql-test/r/rpl_row_create_table.result | 1 + mysql-test/t/rpl_row_create_table.test | 1 + sql/sql_class.h | 3 ++- sql/sql_insert.cc | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/rpl_row_create_table.result b/mysql-test/r/rpl_row_create_table.result index b3a8f5e1a0f..75807c8bfc9 100644 --- a/mysql-test/r/rpl_row_create_table.result +++ b/mysql-test/r/rpl_row_create_table.result @@ -178,6 +178,7 @@ CREATE TABLE t8 LIKE t4; CREATE TABLE t9 LIKE tt4; CREATE TEMPORARY TABLE tt5 LIKE t4; CREATE TEMPORARY TABLE tt6 LIKE tt4; +CREATE TEMPORARY TABLE tt7 SELECT 1; **** On Master **** SHOW CREATE TABLE t8; Table t8 diff --git a/mysql-test/t/rpl_row_create_table.test b/mysql-test/t/rpl_row_create_table.test index 0cb0fd766a3..4f01d7e5459 100644 --- a/mysql-test/t/rpl_row_create_table.test +++ b/mysql-test/t/rpl_row_create_table.test @@ -97,6 +97,7 @@ CREATE TABLE t8 LIKE t4; CREATE TABLE t9 LIKE tt4; CREATE TEMPORARY TABLE tt5 LIKE t4; CREATE TEMPORARY TABLE tt6 LIKE tt4; +CREATE TEMPORARY TABLE tt7 SELECT 1; --echo **** On Master **** --query_vertical SHOW CREATE TABLE t8 --query_vertical SHOW CREATE TABLE t9 diff --git a/sql/sql_class.h b/sql/sql_class.h index 723dad715bd..b5328d4c56b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1610,7 +1610,8 @@ public: virtual bool can_rollback_data() { return 1; } // Needed for access from local class MY_HOOKS in prepare(), since thd is proteted. - THD *get_thd(void) { return thd; } + const THD *get_thd(void) { return thd; } + const HA_CREATE_INFO *get_create_info() { return create_info; }; }; #include diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index f1f97400283..dc27adb853a 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -2714,7 +2714,8 @@ public: MY_HOOKS(select_create *x) : ptr(x) { } virtual void do_prelock(TABLE **tables, uint count) { - if (ptr->get_thd()->current_stmt_binlog_row_based) + if (ptr->get_thd()->current_stmt_binlog_row_based && + !(ptr->get_create_info()->options & HA_LEX_CREATE_TMP_TABLE)) ptr->binlog_show_create_table(tables, count); }