From 6ac1930117741bb7847d35fcef5ecd83eff55857 Mon Sep 17 00:00:00 2001 From: calvin <> Date: Thu, 24 Apr 2008 11:25:30 +0000 Subject: [PATCH] branches/5.1: Fix bug#29507 TRUNCATE shows to many rows effected In InnoDB, the row count is only a rough estimate used by SQL optimization. InnoDB is now return row count 0 for TRUNCATE operation. --- handler/ha_innodb.cc | 7 +++++++ mysql-test/innodb.result | 11 +++++++++++ mysql-test/innodb.test | 15 +++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/handler/ha_innodb.cc b/handler/ha_innodb.cc index 67d9a9543f0..a52b1cb283c 100644 --- a/handler/ha_innodb.cc +++ b/handler/ha_innodb.cc @@ -5782,6 +5782,13 @@ ha_innobase::info( n_rows++; } + /* Fix bug#29507: TRUNCATE shows too many rows affected. + Do not show the estimates for TRUNCATE command. */ + if (thd_sql_command(user_thd) == SQLCOM_TRUNCATE) { + + n_rows = 0; + } + stats.records = (ha_rows)n_rows; stats.deleted = 0; stats.data_file_length = ((ulonglong) diff --git a/mysql-test/innodb.result b/mysql-test/innodb.result index 0cd276852bf..1ecf3ef5f60 100644 --- a/mysql-test/innodb.result +++ b/mysql-test/innodb.result @@ -3264,3 +3264,14 @@ AUTO_INCREMENT 200 DROP TABLE t2; DROP TABLE t1; +CREATE TABLE t1 (c1 int default NULL, +c2 int default NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +TRUNCATE TABLE t1; +affected rows: 0 +INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +affected rows: 5 +info: Records: 5 Duplicates: 0 Warnings: 0 +TRUNCATE TABLE t1; +affected rows: 0 +DROP TABLE t1; diff --git a/mysql-test/innodb.test b/mysql-test/innodb.test index d7c5f00564d..1073f5535df 100644 --- a/mysql-test/innodb.test +++ b/mysql-test/innodb.test @@ -2458,7 +2458,22 @@ SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; DROP TABLE t2; DROP TABLE t1; # End 34920 test +# Bug #29507 TRUNCATE shows to many rows effected +# +CONNECTION default; +CREATE TABLE t1 (c1 int default NULL, + c2 int default NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +--enable_info +TRUNCATE TABLE t1; + +INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5); +TRUNCATE TABLE t1; + +--disable_info +DROP TABLE t1; +# ####################################################################### # # # Please, DO NOT TOUCH this file as well as the innodb.result file. #