summaryrefslogtreecommitdiff
path: root/sql/sql_delete.cc
diff options
context:
space:
mode:
authorunknown <mats@mysql.com>2006-06-01 11:53:27 +0200
committerunknown <mats@mysql.com>2006-06-01 11:53:27 +0200
commitddc25698262f3a1b9ebedd0e07a92b78fb736c90 (patch)
tree4d52734e028ebab6510c5185b289737375dafd9e /sql/sql_delete.cc
parent564a94da7b744442cb4721cd53cb2d6c28452e51 (diff)
downloadmariadb-git-ddc25698262f3a1b9ebedd0e07a92b78fb736c90.tar.gz
Bug#19066 (DELETE FROM inconsistency for NDB):
Under row-based replication, DELETE FROM will now always be replicated as individual row deletions, while TRUNCATE TABLE will always be replicated as a statement. mysql-test/extra/rpl_tests/rpl_ddl.test: Using --echo instead of SELECT to print message. mysql-test/r/binlog_row_mix_innodb_myisam.result: Result change. mysql-test/r/federated.result: Result change. mysql-test/r/range.result: Result change. mysql-test/r/rpl_sp_effects.result: Result change. mysql-test/r/show_check.result: Result change. mysql-test/r/sp-error.result: Result change. mysql-test/r/sp.result: Result change. mysql-test/r/timezone2.result: Result change. mysql-test/r/trigger-grant.result: Result change. mysql-test/r/type_datetime.result: Result change. mysql-test/r/type_ranges.result: Result change. mysql-test/r/type_timestamp.result: Result change. mysql-test/r/view.result: Result change. mysql-test/t/archive.test: Test contain statements that only works for statement-based logging. mysql-test/t/disabled.def: Disabling test due to reported bug. mysql-test/t/federated.test: Adding ORDER BY clause to SELECT statements mysql-test/t/range.test: Adding ORDER BY clause to SELECT (sub-)statement mysql-test/t/rpl_sp_effects.test: Adding ORDER BY clause to SELECT statement. mysql-test/t/show_check.test: Replacing DELETE FROM without WHERE with TRUNCATE TABLE. mysql-test/t/sp-error.test: Replacing DELETE FROM without WHERE with TRUNCATE TABLE. mysql-test/t/sp.test: Adding ORDER BY clause to SELECT statement. mysql-test/t/timezone2.test: Replacing DELETE FROM without WHERE with TRUNCATE TABLE. mysql-test/t/trigger-grant.test: Replacing DELETE FROM without WHERE with TRUNCATE TABLE. mysql-test/t/type_datetime.test: Adding ORDER BY clause to SELECT statement. mysql-test/t/type_ranges.test: Replacing DELETE FROM without WHERE with TRUNCATE TABLE. mysql-test/t/type_timestamp.test: Replacing DELETE FROM without WHERE with TRUNCATE TABLE. mysql-test/t/view.test: Adding ORDER BY clause to SELECT statement. sql/sql_class.h: Adding member function to set replication to statement-based. sql/sql_delete.cc: When row-based replication is used, DELETE FROM will always delete the contents of the table row-by-row and not use delete_all_rows(). mysql-test/extra/rpl_tests/rpl_truncate.test: New BitKeeper file ``mysql-test/extra/rpl_tests/rpl_truncate.test'' mysql-test/extra/rpl_tests/rpl_truncate_helper.inc: New BitKeeper file ``mysql-test/extra/rpl_tests/rpl_truncate_helper.inc'' mysql-test/r/rpl_truncate_2myisam.result: New BitKeeper file ``mysql-test/r/rpl_truncate_2myisam.result'' mysql-test/r/rpl_truncate_3innodb.result: New BitKeeper file ``mysql-test/r/rpl_truncate_3innodb.result'' mysql-test/r/rpl_truncate_7ndb.result: New BitKeeper file ``mysql-test/r/rpl_truncate_7ndb.result'' mysql-test/t/rpl_truncate_2myisam.test: New BitKeeper file ``mysql-test/t/rpl_truncate_2myisam.test'' mysql-test/t/rpl_truncate_3innodb.test: New BitKeeper file ``mysql-test/t/rpl_truncate_3innodb.test'' mysql-test/t/rpl_truncate_7ndb.test: New BitKeeper file ``mysql-test/t/rpl_truncate_7ndb.test''
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r--sql/sql_delete.cc36
1 files changed, 8 insertions, 28 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 44b0fe1a2f1..92ddff58dd5 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -42,8 +42,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
ha_rows deleted= 0;
uint usable_index= MAX_KEY;
SELECT_LEX *select_lex= &thd->lex->select_lex;
- bool ha_delete_all_rows= 0;
- ulonglong const saved_options= thd->options;
DBUG_ENTER("mysql_delete");
if (open_and_lock_tables(thd, table_list))
@@ -75,20 +73,19 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
Test if the user wants to delete all rows and deletion doesn't have
any side-effects (because of triggers), so we can use optimized
handler::delete_all_rows() method.
+
+ If row-based replication is used, we also delete the table row by
+ row.
*/
if (!using_limit && const_cond && (!conds || conds->val_int()) &&
!(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) &&
- !(table->triggers && table->triggers->has_delete_triggers()))
+ !(table->triggers && table->triggers->has_delete_triggers()) &&
+ !thd->current_stmt_binlog_row_based)
{
/* Update the table->file->records number */
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
ha_rows const maybe_deleted= table->file->records;
- /*
- If all rows shall be deleted, we (almost) always log this
- statement-based (see [binlog], below), so we set this flag and
- test it below.
- */
- ha_delete_all_rows= 1;
+ DBUG_PRINT("debug", ("Trying to use delete_all_rows()"));
if (!(error=table->file->delete_all_rows()))
{
error= -1; // ok
@@ -218,14 +215,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
thd->proc_info="updating";
will_batch= !table->file->start_bulk_delete();
- /*
- We saved the thread options above before clearing the
- OPTION_BIN_LOG, and will restore below, effectively disabling the
- binary log (unless it was already disabled, of course).
- */
- if (ha_delete_all_rows)
- thd->options&= ~static_cast<ulonglong>(OPTION_BIN_LOG);
-
while (!(error=info.read_record(&info)) && !thd->killed &&
!thd->net.report_error)
{
@@ -317,12 +306,6 @@ cleanup:
delete select;
transactional_table= table->file->has_transactions();
- /*
- Restore the saved value of the OPTION_BIN_LOG bit in the thread
- options before executing binlog_query() below.
- */
- thd->options|= (saved_options & OPTION_BIN_LOG);
-
/* See similar binlogging code in sql_update.cc, for comments */
if ((error < 0) || (deleted && !transactional_table))
{
@@ -337,11 +320,7 @@ cleanup:
statement-based; otherwise, 'ha_delete_row()' was used to
delete specific rows which we might log row-based.
*/
- THD::enum_binlog_query_type const
- query_type(ha_delete_all_rows && !table->file->is_injective() ?
- THD::STMT_QUERY_TYPE :
- THD::ROW_QUERY_TYPE);
- int log_result= thd->binlog_query(query_type,
+ int log_result= thd->binlog_query(THD::ROW_QUERY_TYPE,
thd->query, thd->query_length,
transactional_table, FALSE);
@@ -998,6 +977,7 @@ trunc_by_del:
thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_NOT_AUTOCOMMIT);
ha_enable_transaction(thd, FALSE);
mysql_init_select(thd->lex);
+ thd->clear_current_stmt_binlog_row_based();
error= mysql_delete(thd, table_list, (COND*) 0, (SQL_LIST*) 0,
HA_POS_ERROR, LL(0), TRUE);
ha_enable_transaction(thd, TRUE);