From 02e70f1691bdbd9001e4d17b69606624f1f1fa39 Mon Sep 17 00:00:00 2001 From: Satya B Date: Wed, 8 Jul 2009 17:41:34 +0530 Subject: [PATCH] Bug#35111 - Truncate a MyISAM partitioned table does not reset the auto_increment value This is an alternative patch that instead of allowing RECREATE TABLE on TRUNCATE TABLE it implements reset_auto_increment that is called after delete_all_rows. Note: this bug was fixed by Mattias Jonsson: Pusing this patch: http://lists.mysql.com/commits/70370 mysql-test/suite/parts/r/partition_auto_increment_memory.result: Bug#35111: Truncate a MyISAM partitioned table does not reset the auto_increment value mysql-test/suite/parts/r/partition_auto_increment_myisam.result: Bug#35111: Truncate a MyISAM partitioned table does not reset the auto_increment value sql/ha_partition.cc: Bug#35111: Truncate a MyISAM partitioned table does not reset the auto_increment value Added reset_auto_increment, to be used after delete_all_rows to simulate truncate. storage/heap/ha_heap.cc: Bug#35111: Truncate a MyISAM partitioned table does not reset the auto_increment value Added reset_auto_increment, to be used after delete_all_rows to simulate truncate storage/heap/ha_heap.h: Bug#35111: Truncate a MyISAM partitioned table does not reset the auto_increment value Added reset_auto_increment, to be used after delete_all_rows to simulate truncate storage/myisam/ha_myisam.cc: Bug#35111: Truncate a MyISAM partitioned table does not reset the auto_increment value Added reset_auto_increment, to be used after delete_all_rows to simulate truncate. storage/myisam/ha_myisam.h: Bug#35111: Truncate a MyISAM partitioned table does not reset the auto_increment value Added reset_auto_increment, to be used after delete_all_rows to simulate truncate. --- .../suite/parts/r/partition_auto_increment_memory.result | 4 ++-- .../suite/parts/r/partition_auto_increment_myisam.result | 4 ++-- sql/ha_partition.cc | 5 +++++ storage/heap/ha_heap.cc | 8 ++++++++ storage/heap/ha_heap.h | 1 + storage/myisam/ha_myisam.cc | 6 ++++++ storage/myisam/ha_myisam.h | 1 + 7 files changed, 25 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/parts/r/partition_auto_increment_memory.result b/mysql-test/suite/parts/r/partition_auto_increment_memory.result index 77bab79f020..f4d783825f4 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_memory.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_memory.result @@ -381,12 +381,12 @@ Table Create Table t1 CREATE TABLE `t1` ( `c1` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`c1`) -) ENGINE=MEMORY AUTO_INCREMENT=28 DEFAULT CHARSET=latin1 +) ENGINE=MEMORY AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ SELECT * FROM t1 ORDER BY c1; c1 -27 +1 INSERT INTO t1 VALUES (100); INSERT INTO t1 VALUES (NULL); DELETE FROM t1 WHERE c1 >= 100; diff --git a/mysql-test/suite/parts/r/partition_auto_increment_myisam.result b/mysql-test/suite/parts/r/partition_auto_increment_myisam.result index b5b001ec17a..6abf08b68a0 100644 --- a/mysql-test/suite/parts/r/partition_auto_increment_myisam.result +++ b/mysql-test/suite/parts/r/partition_auto_increment_myisam.result @@ -381,12 +381,12 @@ Table Create Table t1 CREATE TABLE `t1` ( `c1` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`c1`) -) ENGINE=MyISAM AUTO_INCREMENT=28 DEFAULT CHARSET=latin1 +) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (c1) PARTITIONS 2 */ SELECT * FROM t1 ORDER BY c1; c1 -27 +1 INSERT INTO t1 VALUES (100); INSERT INTO t1 VALUES (NULL); DELETE FROM t1 WHERE c1 >= 100; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 67bc3156260..74742f58028 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3179,6 +3179,7 @@ int ha_partition::delete_row(const uchar *buf) int ha_partition::delete_all_rows() { int error; + bool truncate= FALSE; handler **file; THD *thd= ha_thd(); DBUG_ENTER("ha_partition::delete_all_rows"); @@ -3190,12 +3191,16 @@ int ha_partition::delete_all_rows() ha_data->next_auto_inc_val= 0; ha_data->auto_inc_initialized= FALSE; unlock_auto_increment(); + truncate= TRUE; } file= m_file; do { if ((error= (*file)->ha_delete_all_rows())) DBUG_RETURN(error); + /* Ignore the error */ + if (truncate) + (void) (*file)->ha_reset_auto_increment(0); } while (*(++file)); DBUG_RETURN(0); } diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 19863d83874..fb7c13e4e41 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -419,6 +419,14 @@ int ha_heap::delete_all_rows() return 0; } + +int ha_heap::reset_auto_increment(ulonglong value) +{ + file->s->auto_increment= value; + return 0; +} + + int ha_heap::external_lock(THD *thd, int lock_type) { return 0; // No external locking diff --git a/storage/heap/ha_heap.h b/storage/heap/ha_heap.h index 5c5ad43658e..22722129f4c 100644 --- a/storage/heap/ha_heap.h +++ b/storage/heap/ha_heap.h @@ -98,6 +98,7 @@ public: int reset(); int external_lock(THD *thd, int lock_type); int delete_all_rows(void); + int reset_auto_increment(ulonglong value); int disable_indexes(uint mode); int enable_indexes(uint mode); int indexes_are_disabled(void); diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index efdd9c35b0a..d0e5f5a5c88 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1870,6 +1870,12 @@ int ha_myisam::delete_all_rows() return mi_delete_all_rows(file); } +int ha_myisam::reset_auto_increment(ulonglong value) +{ + file->s->state.auto_increment= value; + return 0; +} + int ha_myisam::delete_table(const char *name) { return mi_delete_table(name); diff --git a/storage/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h index ca44ae9ad87..55a5eac92de 100644 --- a/storage/myisam/ha_myisam.h +++ b/storage/myisam/ha_myisam.h @@ -101,6 +101,7 @@ class ha_myisam: public handler int reset(void); int external_lock(THD *thd, int lock_type); int delete_all_rows(void); + int reset_auto_increment(ulonglong value); int disable_indexes(uint mode); int enable_indexes(uint mode); int indexes_are_disabled(void);