diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2022-05-06 10:45:18 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2022-05-06 15:11:02 +0300 |
commit | 706a8232da40fee3e89d0ba2f419142bf5335f45 (patch) | |
tree | bc02ccbfe93fd6b462dfe94345c40470eb98389a /sql/sql_delete.cc | |
parent | 92bfc0e8c4bb5c86359c29458d67f3e7836ec18a (diff) | |
download | mariadb-git-706a8232da40fee3e89d0ba2f419142bf5335f45.tar.gz |
MDEV-25477 Auto-create breaks replication when triggering event was not replicated
If UPDATE/DELETE does not change data it is skipped from
replication. We now force replication of such events when they trigger
partition auto-creation.
For ROLLBACK it is as simple as set OPTION_KEEP_LOG
flag. trans_cannot_safely_rollback() does the rest.
For UPDATE/DELETE .. LIMIT 0 we make additional binlog_query() calls
at the early points of return.
As a safety measure we also convert row format into statement if it is
needed. The condition is decided by
binlog_need_stmt_format(). Basically if there are some row events in
cache we don't need that: table open of row event will trigger
auto-creation anyway.
Multi-update/delete works via mysql_select(). There is no early points
of return, so binlogging is always checked by
send_eof()/abort_resultset(). But we must comply with the above
measure of converting into statement.
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r-- | sql/sql_delete.cc | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 95adf17987c..65a3a76e98b 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -450,6 +450,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, */ has_triggers= table->triggers && table->triggers->has_delete_triggers(); + transactional_table= table->file->has_transactions_and_rollback(); if (!returning && !using_limit && const_cond_result && (!thd->is_current_stmt_binlog_format_row() && !has_triggers) @@ -508,6 +509,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (thd->lex->describe || thd->lex->analyze_stmt) goto produce_explain_and_leave; + if (thd->binlog_for_noop_dml(transactional_table)) + DBUG_RETURN(1); + my_ok(thd, 0); DBUG_RETURN(0); } @@ -538,6 +542,10 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, */ if (unlikely(thd->is_error())) DBUG_RETURN(TRUE); + + if (thd->binlog_for_noop_dml(transactional_table)) + DBUG_RETURN(1); + my_ok(thd, 0); DBUG_RETURN(0); // Nothing to delete } @@ -916,14 +924,14 @@ cleanup: deltempfile=NULL; delete select; select= NULL; - transactional_table= table->file->has_transactions_and_rollback(); if (!transactional_table && deleted > 0) thd->transaction->stmt.modified_non_trans_table= thd->transaction->all.modified_non_trans_table= TRUE; /* See similar binlogging code in sql_update.cc, for comments */ - if (likely((error < 0) || thd->transaction->stmt.modified_non_trans_table)) + if (likely((error < 0) || thd->transaction->stmt.modified_non_trans_table + || thd->log_current_statement())) { if (WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open()) { @@ -933,8 +941,8 @@ cleanup: else errcode= query_error_code(thd, killed_status == NOT_KILLED); - ScopedStatementReplication scoped_stmt_rpl( - table->versioned(VERS_TRX_ID) ? thd : NULL); + StatementBinlog stmt_binlog(thd, table->versioned(VERS_TRX_ID) || + thd->binlog_need_stmt_format(transactional_table)); /* [binlog]: If 'handler::delete_all_rows()' was called and the storage engine does not inject the rows itself, we replicate @@ -1438,13 +1446,15 @@ void multi_delete::abort_result_set() DBUG_VOID_RETURN; } - if (thd->transaction->stmt.modified_non_trans_table) + if (thd->transaction->stmt.modified_non_trans_table || + thd->log_current_statement()) { /* there is only side effects; to binlog with the error */ if (WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open()) { + StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(transactional_tables)); int errcode= query_error_code(thd, thd->killed == NOT_KILLED); /* possible error of writing binary log is ignored deliberately */ (void) thd->binlog_query(THD::ROW_QUERY_TYPE, @@ -1618,7 +1628,8 @@ bool multi_delete::send_eof() query_cache_invalidate3(thd, delete_tables, 1); } if (likely((local_error == 0) || - thd->transaction->stmt.modified_non_trans_table)) + thd->transaction->stmt.modified_non_trans_table) || + thd->log_current_statement()) { if(WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open()) { @@ -1628,6 +1639,7 @@ bool multi_delete::send_eof() else errcode= query_error_code(thd, killed_status == NOT_KILLED); thd->thread_specific_used= TRUE; + StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(transactional_tables)); if (unlikely(thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query(), thd->query_length(), transactional_tables, FALSE, FALSE, |