From 6827c26fcf12f94ea7c0eb2b509f5ea9b83101f7 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 12 Nov 2004 17:04:07 +0300 Subject: Fix for bug #5890 "Triggers fail for DELETE without WHERE". If we have DELETE with always true WHERE clause we should not use optimized delete_all_rows() method for tables with DELETE triggers, because in this case we will lose side-effect of deletion. mysql-test/r/trigger.result: Added test for bug #5890 "Triggers fail for DELETE without WHERE". mysql-test/t/trigger.test: Added test for bug #5890 "Triggers fail for DELETE without WHERE". sql/sql_delete.cc: mysql_delete(): We should not use optimized delete_all_rows() method for tables with DELETE triggers, because in this case we will lose side-effect of deletion. sql/sql_trigger.h: Added new Table_triggers_list::has_delete_triggers() method which allows to understand quickly if we have some DELETE triggers in our list. --- sql/sql_delete.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'sql/sql_delete.cc') diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 8bdf19195f3..1cd0d0177f6 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -62,9 +62,14 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, SQL_LIST *order, if (thd->lex->duplicates == DUP_IGNORE) thd->lex->select_lex.no_error= 1; - /* Test if the user wants to delete all rows */ + /* + 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 (!using_limit && const_cond && (!conds || conds->val_int()) && - !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE))) + !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) && + !(table->triggers && table->triggers->has_delete_triggers())) { deleted= table->file->records; if (!(error=table->file->delete_all_rows())) -- cgit v1.2.1