MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:kgeorge Date:November 21 2006 8:11am
Subject:bk commit into 5.0 tree (gkodinov:1.2315) BUG#23556
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kgeorge. When kgeorge does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-11-21 10:11:43+02:00, gkodinov@stripped +3 -0
  Bug#23556: TRUNCATE TABLE still maps to DELETE
   This is the 5.0 part of the fix.
   Currently TRUNCATE command will not call
   delete_all_rows() in the handler (that implements
   the "fast" TRUNCATE for InnoDB) when there are
   triggers on the table.
   As decided by the architecture team TRUNCATE must
   use "fast" TRUNCATE even when there are triggers.
   Thus it must ignore the triggers. 
   Made TRUNCATE to ignore the triggers and call
   delete_all_rows() for all storage engines
   to maintain engine consistency.

  mysql-test/r/trigger.result@stripped, 2006-11-21 10:11:37+02:00, gkodinov@stripped +25 -0
    Bug#23556: TRUNCATE TABLE still maps to DELETE
     - test case

  mysql-test/t/trigger.test@stripped, 2006-11-21 10:11:37+02:00, gkodinov@stripped +25 -0
    Bug#23556: TRUNCATE TABLE still maps to DELETE
     - test case

  sql/sql_delete.cc@stripped, 2006-11-21 10:11:38+02:00, gkodinov@stripped +5 -1
    Bug#23556: TRUNCATE TABLE still maps to DELETE
     - We implemenent fast TRUNCATE for InnoDB even
       if triggers are present.  
     - TRUNCATE ignores triggers.
       

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	gkodinov
# Host:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B23556-5.0-opt

--- 1.185/sql/sql_delete.cc	2006-11-03 17:10:59 +02:00
+++ 1.186/sql/sql_delete.cc	2006-11-21 10:11:38 +02:00
@@ -76,10 +76,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *
     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.
+    We implement fast TRUNCATE for InnoDB even if triggers are present. 
+    TRUNCATE ignores triggers.
   */
   if (!using_limit && const_cond && (!conds || conds->val_int()) &&
       !(specialflag & (SPECIAL_NO_NEW_FUNC | SPECIAL_SAFE_MODE)) &&
-      !(table->triggers && table->triggers->has_delete_triggers()))
+      (thd->lex->sql_command == SQLCOM_TRUNCATE ||
+       !(table->triggers && table->triggers->has_delete_triggers()))
+     )
   {
     deleted= table->file->records;
     if (!(error=table->file->delete_all_rows()))

--- 1.48/mysql-test/r/trigger.result	2006-10-19 21:39:48 +03:00
+++ 1.49/mysql-test/r/trigger.result	2006-11-21 10:11:37 +02:00
@@ -1241,4 +1241,29 @@ i	j
 2	2
 13	13
 drop table t1;
+CREATE TABLE t1 (a INT PRIMARY KEY);
+CREATE TABLE t2 (a INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+CREATE TRIGGER trg_t1 BEFORE DELETE on t1 FOR EACH ROW 
+INSERT INTO t2 VALUES (OLD.a);
+FLUSH STATUS;
+TRUNCATE t1;
+SHOW STATUS LIKE 'handler_delete';
+Variable_name	Value
+Handler_delete	0
+SELECT COUNT(*) FROM t2;
+COUNT(*)
+0
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+DELETE FROM t2;
+FLUSH STATUS;
+DELETE FROM t1;
+SHOW STATUS LIKE 'handler_delete';
+Variable_name	Value
+Handler_delete	8
+SELECT COUNT(*) FROM t2;
+COUNT(*)
+8
+DROP TRIGGER trg_t1;
+DROP TABLE t1,t2;
 End of 5.0 tests

--- 1.54/mysql-test/t/trigger.test	2006-10-19 21:39:48 +03:00
+++ 1.55/mysql-test/t/trigger.test	2006-11-21 10:11:37 +02:00
@@ -1498,5 +1498,30 @@ update t1 set i= i+ 10 where j > 2;
 select * from t1;
 drop table t1;
 
+#
+# Bug#23556 TRUNCATE TABLE still maps to DELETE
+#
+CREATE TABLE t1 (a INT PRIMARY KEY);
+CREATE TABLE t2 (a INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+
+CREATE TRIGGER trg_t1 BEFORE DELETE on t1 FOR EACH ROW 
+  INSERT INTO t2 VALUES (OLD.a);
+
+FLUSH STATUS;
+TRUNCATE t1;
+SHOW STATUS LIKE 'handler_delete';
+SELECT COUNT(*) FROM t2;
+
+INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
+DELETE FROM t2;
+
+FLUSH STATUS;
+DELETE FROM t1;
+SHOW STATUS LIKE 'handler_delete';
+SELECT COUNT(*) FROM t2;
+
+DROP TRIGGER trg_t1;
+DROP TABLE t1,t2;
 
 --echo End of 5.0 tests
Thread
bk commit into 5.0 tree (gkodinov:1.2315) BUG#23556kgeorge21 Nov