Hi Zhenxing,
Nice work. Patch approved.
From my analysis this patch seems to fix the issue. I have written a
small mtr test case during the review (based mostly on the "how to
reproduce" procedure from the bug report). I am attaching it in case you
feel like having a look at it.
Regards,
Luís
He Zhenxing wrote:
> #At file:///media/sdb2/hezx/work/mysql/bzrwork/b35583/5.0/
>
> 2636 He Zhenxing 2008-12-15
> 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.
> modified:
> sql/sql_delete.cc
> sql/sql_table.cc
>
> per-file messages:
> 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
> === modified file 'sql/sql_delete.cc'
> --- a/sql/sql_delete.cc 2008-03-27 11:52:55 +0000
> +++ b/sql/sql_delete.cc 2008-12-15 07:20:29 +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 2008-12-15 07:20:29 +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)
> {
>
>
-- source include/have_log_bin.inc
CREATE TABLE IF NOT EXISTS t1(id serial, t varchar(255)) auto_increment=5;
FLUSH LOGS;
CREATE TEMPORARY TABLE tempt LIKE t1;
INSERT INTO tempt(t) VALUES('abc');
INSERT INTO t1 SELECT id,t FROM tempt;
FLUSH LOGS;
RENAME TABLE t1 TO t_old;
CREATE TABLE t1 LIKE t_old;
--exec $MYSQL_BINLOG $MYSQLTEST_VARDIR/log/master-bin.000002 | $MYSQL $DB
DROP TABLE t1;
DROP TABLE t_old;
DROP TABLE tempt;