diff options
author | Mats Kindahl <mats@sun.com> | 2009-02-06 17:06:41 +0100 |
---|---|---|
committer | Mats Kindahl <mats@sun.com> | 2009-02-06 17:06:41 +0100 |
commit | bd53d21417e2d340758abfeb29f7057221e0da03 (patch) | |
tree | 51ee9ccf78d6f32d654f5e6454ef1832b94056ff /sql/sql_delete.cc | |
parent | 75e1ed96180cc96721ebb32946001c4b84aabda9 (diff) | |
download | mariadb-git-bd53d21417e2d340758abfeb29f7057221e0da03.tar.gz |
Bug #36763
TRUNCATE TABLE fails to replicate when stmt-based binlogging is not supported.
There were two separate problems with the code, both of which are fixed with
this patch:
1. An error was printed by InnoDB for TRUNCATE TABLE in statement mode when
the in isolation levels READ COMMITTED and READ UNCOMMITTED since InnoDB
does permit statement-based replication for DML statements. However,
the TRUNCATE TABLE is not transactional, but is a DDL, and should therefore
be allowed to be replicated as a statement.
2. The statement was not logged in mixed mode because of the error above, but
the error was not reported to the client.
This patch fixes the problem by treating TRUNCATE TABLE a DDL, that is, it is
always logged as a statement and not reporting an error from InnoDB for TRUNCATE
TABLE.
mysql-test/extra/binlog_tests/binlog_truncate.test:
Adding new test to check that TRUNCATE TABLE is written correctly
to the binary log.
mysql-test/extra/rpl_tests/rpl_truncate.test:
Removing redundant testing by eliminating settings of BINLOG_FORMAT.
mysql-test/extra/rpl_tests/rpl_truncate_helper.test:
Replacing slave and master reset code with include file.
Removing settings of BINLOG_FORMAT.
Replacing printing of table contents to compare master and slave
with diff_tables.inc.
mysql-test/suite/binlog/t/binlog_truncate_innodb.test:
Adding test for testing that TRUNCATE TABLE is logged correctly for InnoDB
in all isolation levels.
mysql-test/suite/binlog/t/binlog_truncate_myisam.test:
Adding test for testing that TRUNCATE TABLE is logged correctly for MyISAM.
mysql-test/suite/binlog/t/disabled.def:
Disabling binlog_truncate_innodb since it does not work (yet).
sql/sql_base.cc:
Correcting setting of capabilities flags to make the comparison with 0
later in the code work correctly.
sql/sql_delete.cc:
Re-organizing code to ensure that TRUNCATE TABLE is logged in statement
format and that row format is not used unless there are rows to log (which
there are not when delete_all_rows() is called, so this has to be logged
as a statement).
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r-- | sql/sql_delete.cc | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index b56e042e3d5..b37e2a24895 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -51,6 +51,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_delete"); + THD::enum_binlog_query_type query_type= + thd->lex->sql_command == SQLCOM_TRUNCATE ? + THD::STMT_QUERY_TYPE : + THD::ROW_QUERY_TYPE; + if (open_and_lock_tables(thd, table_list)) DBUG_RETURN(TRUE); if (!(table= table_list->table)) @@ -135,6 +140,11 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, DBUG_PRINT("debug", ("Trying to use delete_all_rows()")); if (!(error=table->file->ha_delete_all_rows())) { + /* + If delete_all_rows() is used, it is not possible to log the + query in row format, so we have to log it in statement format. + */ + query_type= THD::STMT_QUERY_TYPE; error= -1; // ok deleted= maybe_deleted; goto cleanup; @@ -374,6 +384,11 @@ cleanup: { if (mysql_bin_log.is_open()) { + bool const is_trans= + thd->lex->sql_command == SQLCOM_TRUNCATE ? + FALSE : + transactional_table; + if (error < 0) thd->clear_error(); /* @@ -381,10 +396,13 @@ cleanup: storage engine does not inject the rows itself, we replicate statement-based; otherwise, 'ha_delete_row()' was used to delete specific rows which we might log row-based. + + Note that TRUNCATE TABLE is not transactional and should + therefore be treated as a DDL. */ - int log_result= thd->binlog_query(THD::ROW_QUERY_TYPE, + int log_result= thd->binlog_query(query_type, thd->query, thd->query_length, - transactional_table, FALSE, killed_status); + is_trans, FALSE, killed_status); if (log_result && transactional_table) { |