#At file:///Users/mattiasj/clones/bzrroot/b35111-51-main_storage/ based on revid:alik@stripped
2773 Mattias Jonsson 2009-03-25
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.
@ mysql-test/suite/parts/r/partition_auto_increment_memory.result
Bug#35111: Truncate a MyISAM partitioned table does not reset
the auto_increment value
Now correct result
@ mysql-test/suite/parts/r/partition_auto_increment_myisam.result
Bug#35111: Truncate a MyISAM partitioned table does not reset
the auto_increment value
Now correct result
@ sql/ha_partition.cc
Bug#35111: Truncate a MyISAM partitioned table does not reset
the auto_increment value
Added reset_auto_increment after delete_all_rows if 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.
modified:
mysql-test/suite/parts/r/partition_auto_increment_memory.result
mysql-test/suite/parts/r/partition_auto_increment_myisam.result
sql/ha_partition.cc
storage/heap/ha_heap.cc
storage/heap/ha_heap.h
storage/myisam/ha_myisam.cc
storage/myisam/ha_myisam.h
=== modified file 'mysql-test/suite/parts/r/partition_auto_increment_memory.result'
--- a/mysql-test/suite/parts/r/partition_auto_increment_memory.result 2009-02-05 17:47:24 +0000
+++ b/mysql-test/suite/parts/r/partition_auto_increment_memory.result 2009-03-25 14:56:16 +0000
@@ -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;
=== modified file 'mysql-test/suite/parts/r/partition_auto_increment_myisam.result'
--- a/mysql-test/suite/parts/r/partition_auto_increment_myisam.result 2009-02-05 17:47:24 +0000
+++ b/mysql-test/suite/parts/r/partition_auto_increment_myisam.result 2009-03-25 14:56:16 +0000
@@ -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;
=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc 2009-02-20 15:56:32 +0000
+++ b/sql/ha_partition.cc 2009-03-25 14:56:16 +0000
@@ -3179,6 +3179,7 @@ int ha_partition::delete_row(const uchar
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);
}
=== modified file 'storage/heap/ha_heap.cc'
--- a/storage/heap/ha_heap.cc 2008-12-16 12:12:22 +0000
+++ b/storage/heap/ha_heap.cc 2009-03-25 14:56:16 +0000
@@ -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
=== modified file 'storage/heap/ha_heap.h'
--- a/storage/heap/ha_heap.h 2007-08-13 13:11:25 +0000
+++ b/storage/heap/ha_heap.h 2009-03-25 14:56:16 +0000
@@ -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);
=== modified file 'storage/myisam/ha_myisam.cc'
--- a/storage/myisam/ha_myisam.cc 2009-02-24 11:17:50 +0000
+++ b/storage/myisam/ha_myisam.cc 2009-03-25 14:56:16 +0000
@@ -1813,6 +1813,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);
=== modified file 'storage/myisam/ha_myisam.h'
--- a/storage/myisam/ha_myisam.h 2007-11-15 19:25:43 +0000
+++ b/storage/myisam/ha_myisam.h 2009-03-25 14:56:16 +0000
@@ -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);
Attachment: [text/bzr-bundle] bzr/mattias.jonsson@sun.com-20090325145616-4hrybvf5nea1knj4.bundle