diff options
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r-- | sql/sql_delete.cc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 4fc618ca050..ddb6af97865 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -50,6 +50,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SELECT_LEX *select_lex= &thd->lex->select_lex; THD::killed_state killed_status= THD::NOT_KILLED; DBUG_ENTER("mysql_delete"); + bool save_binlog_row_based; THD::enum_binlog_query_type query_type= thd->lex->sql_command == SQLCOM_TRUNCATE ? @@ -147,12 +148,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, query_type= THD::STMT_QUERY_TYPE; error= -1; // ok deleted= maybe_deleted; + save_binlog_row_based= thd->current_stmt_binlog_row_based; goto cleanup; } if (error != HA_ERR_WRONG_COMMAND) { table->file->print_error(error,MYF(0)); error=0; + save_binlog_row_based= thd->current_stmt_binlog_row_based; goto cleanup; } /* Handler didn't support fast delete; Delete rows one by one */ @@ -293,13 +296,17 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, table->mark_columns_needed_for_delete(); + save_binlog_row_based= thd->current_stmt_binlog_row_based; + if (thd->lex->sql_command == SQLCOM_TRUNCATE && + thd->current_stmt_binlog_row_based) + thd->clear_current_stmt_binlog_row_based(); + while (!(error=info.read_record(&info)) && !thd->killed && ! thd->is_error()) { // thd->is_error() is tested to disallow delete row on error - if (!(select && select->skip_record())&& ! thd->is_error() ) + if (!select || select->skip_record(thd) > 0) { - if (triggers_applicable && table->triggers->process_triggers(thd, TRG_EVENT_DELETE, TRG_ACTION_BEFORE, FALSE)) @@ -393,7 +400,10 @@ cleanup: /* See similar binlogging code in sql_update.cc, for comments */ if ((error < 0) || thd->transaction.stmt.modified_non_trans_table) { - if (mysql_bin_log.is_open()) + if (mysql_bin_log.is_open() && + !(thd->lex->sql_command == SQLCOM_TRUNCATE && + thd->current_stmt_binlog_row_based && + find_temporary_table(thd, table_list))) { bool const is_trans= thd->lex->sql_command == SQLCOM_TRUNCATE ? @@ -427,6 +437,7 @@ cleanup: if (thd->transaction.stmt.modified_non_trans_table) thd->transaction.all.modified_non_trans_table= TRUE; } + thd->current_stmt_binlog_row_based= save_binlog_row_based; DBUG_ASSERT(transactional_table || !deleted || thd->transaction.stmt.modified_non_trans_table); free_underlaid_joins(thd, select_lex); if (error < 0 || @@ -1062,15 +1073,13 @@ bool multi_delete::send_eof() static bool mysql_truncate_by_delete(THD *thd, TABLE_LIST *table_list) { - bool error, save_binlog_row_based= thd->current_stmt_binlog_row_based; + bool error; DBUG_ENTER("mysql_truncate_by_delete"); table_list->lock_type= TL_WRITE; mysql_init_select(thd->lex); - thd->clear_current_stmt_binlog_row_based(); error= mysql_delete(thd, table_list, NULL, NULL, HA_POS_ERROR, LL(0), TRUE); ha_autocommit_or_rollback(thd, error); end_trans(thd, error ? ROLLBACK : COMMIT); - thd->current_stmt_binlog_row_based= save_binlog_row_based; DBUG_RETURN(error); } |