Commit 77f73116 authored by Satya B's avatar Satya B

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
parent 70f6351b
......@@ -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;
......
......@@ -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;
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment