diff options
author | Luis Soares <luis.soares@sun.com> | 2010-02-24 19:01:53 +0000 |
---|---|---|
committer | Luis Soares <luis.soares@sun.com> | 2010-02-24 19:01:53 +0000 |
commit | 48d65a645ec7962d8d861de050c65c215e827996 (patch) | |
tree | fbfa8db2f805d21ec08361aceb5feac162447423 /mysql-test/suite | |
parent | 32058ba9c6365f1190e36c290ced9779f79cbdfe (diff) | |
download | mariadb-git-48d65a645ec7962d8d861de050c65c215e827996.tar.gz |
BUG#51251: Wrong binlogging in case of TRUNCATE <temporary InnoDB table>
For temporary tables that are created with an engine that does
not provide the HTON_CAN_RECREATE, the truncate operation is
performed resorting to the optimized handler::ha_delete_all_rows
method. However, this means that the truncate will share
execution path, from mysql_delete, with truncate on regular
tables and other delete operations. As a consequence the truncate
operation, for the temporary table is logged, even if in row mode
because there is no distinction between this and the other delete
operations at binlogging time.
We fix this by checking if: (i) the binlog format, when the
truncate operation was issued, is ROW; (ii) if the operation is a
truncate; and (iii) if the table is a temporary table; before
writing to the binary log. If all three conditions are met, we
skip writing to the binlog. A side effect of this fix is that we
limit the scope of setting and resetting the
current_stmt_binlog_row_based. Now we just set and reset it
inside mysql_delete in the boundaries of the
handler::ha_write_row loop. This way we have access to
thd->current_stmt_binlog_row_based real value inside
mysql_delete.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
Updated result for spurious truncate table.
mysql-test/suite/binlog/t/binlog_row_innodb_truncate.test:
Test case.
sql/sql_delete.cc:
Added check in mysql_delete before writing the TRUNCATE statement
to the binary log. Additionally, removed the set/reset of
current_stmt_binlog_row_based so that it happens just in the
boundaries of the handler::ha_write_row loop inside mysql_delete.
Diffstat (limited to 'mysql-test/suite')
3 files changed, 65 insertions, 1 deletions
diff --git a/mysql-test/suite/binlog/r/binlog_row_innodb_truncate.result b/mysql-test/suite/binlog/r/binlog_row_innodb_truncate.result new file mode 100644 index 00000000000..39f8b43f207 --- /dev/null +++ b/mysql-test/suite/binlog/r/binlog_row_innodb_truncate.result @@ -0,0 +1,28 @@ +CREATE TABLE t1 ( c1 int , primary key (c1)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TEMPORARY TABLE IF NOT EXISTS t2 LIKE t1; +TRUNCATE TABLE t2; +DROP TABLE t1; +############################################### +### assertion: No event for 'TRUNCATE TABLE t2' +############################################### +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 ( c1 int , primary key (c1)) ENGINE=InnoDB +master-bin.000001 # Query # # BEGIN +master-bin.000001 # Table_map # # table_id: # (test.t1) +master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F +master-bin.000001 # Xid # # COMMIT /* XID */ +master-bin.000001 # Query # # use `test`; DROP TABLE t1 +############################################### +RESET MASTER; +CREATE TEMPORARY TABLE t1 (c1 int) Engine=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +TRUNCATE t1; +DROP TEMPORARY TABLE t1; +############################################### +### assertion: No event for 'TRUNCATE TABLE t1' +############################################### +show binlog events from <binlog_start>; +Log_name Pos Event_type Server_id End_log_pos Info +############################################### diff --git a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result index 87e9b7f8685..a41961cd2ce 100644 --- a/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result +++ b/mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result @@ -413,7 +413,6 @@ master-bin.000001 # Query # # BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F master-bin.000001 # Query # # COMMIT -master-bin.000001 # Query # # use `test`; TRUNCATE table t2 master-bin.000001 # Query # # BEGIN master-bin.000001 # Table_map # # table_id: # (test.t1) master-bin.000001 # Write_rows # # table_id: # flags: STMT_END_F diff --git a/mysql-test/suite/binlog/t/binlog_row_innodb_truncate.test b/mysql-test/suite/binlog/t/binlog_row_innodb_truncate.test new file mode 100644 index 00000000000..d7c177d4632 --- /dev/null +++ b/mysql-test/suite/binlog/t/binlog_row_innodb_truncate.test @@ -0,0 +1,37 @@ +-- source include/have_binlog_format_row.inc +-- source include/have_innodb.inc + +# +# BUG#51251 +# +# The test case checks if truncating a temporary table created with +# engine InnoDB will not cause the truncate statement to be binlogged. + +# Before patch for BUG#51251, the TRUNCATE statements below would be +# binlogged, which would cause the slave to fail with "table does not +# exist". + +CREATE TABLE t1 ( c1 int , primary key (c1)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +CREATE TEMPORARY TABLE IF NOT EXISTS t2 LIKE t1; +TRUNCATE TABLE t2; +DROP TABLE t1; + +-- echo ############################################### +-- echo ### assertion: No event for 'TRUNCATE TABLE t2' +-- echo ############################################### +-- source include/show_binlog_events.inc +-- echo ############################################### + +RESET MASTER; + +CREATE TEMPORARY TABLE t1 (c1 int) Engine=InnoDB; +INSERT INTO t1 VALUES (1), (2), (3); +TRUNCATE t1; +DROP TEMPORARY TABLE t1; + +-- echo ############################################### +-- echo ### assertion: No event for 'TRUNCATE TABLE t1' +-- echo ############################################### +-- source include/show_binlog_events.inc +-- echo ############################################### |