diff options
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r-- | sql/sql_delete.cc | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 440d404056b..9e425f86579 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -205,15 +205,24 @@ cleanup: query_cache_invalidate3(thd, table_list, 1); } + delete select; transactional_table= table->file->has_transactions(); log_delayed= (transactional_table || table->tmp_table); - if (deleted && (error <= 0 || !transactional_table)) + /* + We write to the binary log even if we deleted no row, because maybe the + user is using this command to ensure that a table is clean on master *and + on slave*. Think of the case of a user having played separately with the + master's table and slave's table and wanting to take a fresh identical + start now. + error < 0 means "really no error". error <= 0 means "maybe some error". + */ + if ((deleted || (error < 0)) && (error <= 0 || !transactional_table)) { if (mysql_bin_log.is_open()) { if (error <= 0) thd->clear_error(); - Query_log_event qinfo(thd, thd->query, thd->query_length, + Query_log_event qinfo(thd, thd->query, thd->query_length, log_delayed); if (mysql_bin_log.write(&qinfo) && transactional_table) error=1; @@ -232,7 +241,6 @@ cleanup: mysql_unlock_tables(thd, thd->lock); thd->lock=0; } - delete select; free_underlaid_joins(thd, &thd->lex->select_lex); if (error >= 0 || thd->net.report_error) send_error(thd,thd->killed_errno()); @@ -560,6 +568,8 @@ bool multi_delete::send_eof() rows and we succeeded, or also in an error case when there was a non-transaction-safe table involved, since modifications in it cannot be rolled back. + Note that if we deleted nothing we don't write to the binlog (TODO: + fix this). */ if (deleted && (error <= 0 || normal_tables)) { |