#At file:///media/sdb2/hezx/work/mysql/bzrwork/b35583/5.0/
2636 He Zhenxing 2009-01-09
BUG#35583 mysqlbinlog replay fails with ERROR 1146 when temp tables are used
When using CREATE TEMPORARY TABLE LIKE to create a temporary table,
or using TRUNCATE to delete all rows of a temporary table, they
did not set the tmp_table_used flag, and cause the omission of
"SET @@session.pseudo_thread_id" when dumping binlog with mysqlbinlog,
and cause error when replay the statements.
This patch fixed the problem by setting tmp_table_used in these two
cases.
added:
mysql-test/r/binlog_tmp_table.result
mysql-test/t/binlog_tmp_table.test
modified:
sql/sql_delete.cc
sql/sql_table.cc
per-file messages:
mysql-test/r/binlog_tmp_table.result
Add test case for BUG#35583
mysql-test/t/binlog_tmp_table.test
Add test case for BUG#35583
sql/sql_delete.cc
set thd->tmp_table_used when truncate temporary table
sql/sql_table.cc
set thd->tmp_table_used when using create like to create temporary tables
=== added file 'mysql-test/r/binlog_tmp_table.result'
--- a/mysql-test/r/binlog_tmp_table.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/binlog_tmp_table.result 2009-01-09 08:47:53 +0000
@@ -0,0 +1,22 @@
+create table foo (a int);
+flush logs;
+create temporary table tmp1_foo like foo;
+create temporary table tmp2_foo like foo;
+insert into tmp1_foo values (1);
+insert into tmp2_foo values (2);
+insert into foo select * from tmp1_foo;
+insert into foo select * from tmp2_foo;
+truncate table tmp1_foo;
+truncate table tmp2_foo;
+flush logs;
+select * from foo;
+a
+1
+2
+drop table foo;
+create table foo (a int);
+select * from foo;
+a
+1
+2
+drop table foo;
=== added file 'mysql-test/t/binlog_tmp_table.test'
--- a/mysql-test/t/binlog_tmp_table.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/binlog_tmp_table.test 2009-01-09 08:47:53 +0000
@@ -0,0 +1,58 @@
+# ==== Purpose ====
+#
+# Test if statements used temporary tables are binlogged correctly
+#
+# ==== Method ====
+#
+# Use two connections, use temporary tables on both of them, and by
+# switching connections between statements, the test can check if the
+# statements are logged with the correct thread id.
+#
+# ==== Related bugs ====
+#
+# BUG#35583 mysqlbinlog replay fails with ERROR 1146 when temp tables are used
+#
+source include/have_log_bin.inc;
+
+connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
+connect (master1,127.0.0.1,root,,test,$MASTER_MYPORT,);
+
+create table foo (a int);
+
+flush logs;
+
+connection master;
+create temporary table tmp1_foo like foo;
+connection master1;
+create temporary table tmp2_foo like foo;
+
+connection master;
+insert into tmp1_foo values (1);
+connection master1;
+insert into tmp2_foo values (2);
+
+connection master;
+insert into foo select * from tmp1_foo;
+connection master1;
+insert into foo select * from tmp2_foo;
+
+connection master;
+truncate table tmp1_foo;
+connection master1;
+truncate table tmp2_foo;
+
+flush logs;
+
+connection master;
+select * from foo;
+
+# prepare for the replay
+drop table foo;
+create table foo (a int);
+
+# replay from binary log
+exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000002 | $MYSQL;
+select * from foo;
+
+# clean up
+drop table foo;
=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc 2008-03-27 11:52:55 +0000
+++ b/sql/sql_delete.cc 2009-01-09 08:47:53 +0000
@@ -918,6 +918,9 @@ bool mysql_truncate(THD *thd, TABLE_LIST
if ((error= (int) !(open_temporary_table(thd, path, table_list->db,
table_list->table_name, 1))))
(void) rm_temporary_table(table_type, path);
+ else
+ thd->tmp_table_used= 1;
+
/*
If we return here we will not have logged the truncation to the bin log
and we will not send_ok() to the client.
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2008-05-12 16:01:13 +0000
+++ b/sql/sql_table.cc 2009-01-09 08:47:53 +0000
@@ -2876,6 +2876,7 @@ bool mysql_create_like_table(THD* thd, T
dst_path); /* purecov: inspected */
goto err; /* purecov: inspected */
}
+ thd->tmp_table_used= 1;
}
else if (err)
{