Commit a2ed6829 authored by unknown's avatar unknown

Bug #48350 truncate temporary table crashes replication

In RBR, All statements operating on temporary tables should not be binlogged.
Despite this fact, after executing 'TRUNCATE... ' on a temporary table, 
the command is still logged, even if in row-based mode. Consequently, this raises
problems in the slave as the table may not exist, resulting in an
execution failure. Ultimately, this causes the slave to report
an error and abort.

After this patch, 'TRUNCATE ...' statement on a temporary table will not be
binlogged in RBR.
parent 897d87f6
stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master;
reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
start slave;
CREATE TEMPORARY TABLE t1(c1 INTEGER);
CREATE TABLE t2(c1 INTEGER);
CREATE TABLE t1(c1 INTEGER);
INSERT INTO t1 VALUES(1), (2);
INSERT INTO t2 VALUES(1), (2);
SELECT * FROM t1;
c1
1
2
SELECT * FROM t2;
c1
1
2
TRUNCATE t1;
TRUNCATE t2;
SELECT * FROM t1;
c1
1
2
SELECT * FROM t2;
c1
DROP TABLE t1;
DROP TABLE t2;
#
# Bug#48350 truncate temporary table crashes replication
#
# All statements operating on temporary tables should not be binlogged in RBR.
# However, before fix of bug#48350, 'TRUNCATE ...' statement on a temporary
# table was binlogged in RBR.
#
--source include/master-slave.inc
--source include/have_binlog_format_row.inc
#This statement is not binlogged in RBR.
CREATE TEMPORARY TABLE t1(c1 INTEGER);
CREATE TABLE t2(c1 INTEGER);
sync_slave_with_master;
CREATE TABLE t1(c1 INTEGER);
INSERT INTO t1 VALUES(1), (2);
INSERT INTO t2 VALUES(1), (2);
SELECT * FROM t1;
SELECT * FROM t2;
connection master;
TRUNCATE t1;
TRUNCATE t2;
sync_slave_with_master;
# t1 will have nothing, if 'TRUNCATE t1' has been replicate from master to
# slave.
SELECT * FROM t1;
SELECT * FROM t2;
DROP TABLE t1;
connection master;
DROP TABLE t2;
--source include/master-slave-end.inc
......@@ -1090,6 +1090,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
TABLE *table;
bool error;
uint path_length;
bool is_temporary_table= false;
DBUG_ENTER("mysql_truncate");
bzero((char*) &create_info,sizeof(create_info));
......@@ -1100,6 +1101,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
/* If it is a temporary table, close and regenerate it */
if (!dont_send_ok && (table= find_temporary_table(thd, table_list)))
{
is_temporary_table= true;
handlerton *table_type= table->s->db_type();
TABLE_SHARE *share= table->s;
if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE))
......@@ -1163,10 +1165,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
{
if (!error)
{
/*
TRUNCATE must always be statement-based binlogged (not row-based) so
we don't test current_stmt_binlog_row_based.
*/
/* In RBR, the statement is not binlogged if the table is temporary. */
if (!is_temporary_table || !thd->current_stmt_binlog_row_based)
write_bin_log(thd, TRUE, thd->query(), thd->query_length());
my_ok(thd); // This should return record count
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment