| Bug #18274 | InnoDB auto_increment field reset on OPTIMIZE TABLE | ||
|---|---|---|---|
| Submitted: | 16 Mar 2006 9:57 | Modified: | 16 Mar 2006 10:40 |
| Reporter: | Andrejs Dubovskis | ||
| Status: | Verified | ||
| Category: | Server: InnoDB | Severity: | S4 (Feature request) |
| Version: | 4.1.18, 5.0, 5.1 | OS: | Any (*) |
| Assigned to: | Heikki Tuuri | Target Version: | |
| Triage: | Triaged: D5 (Feature request) | ||
[16 Mar 2006 9:57]
Andrejs Dubovskis
[16 Mar 2006 10:27]
Hartmut Holzgraefe
verified, also happens with 5.0 and 5.1
[16 Mar 2006 10:34]
Heikki Tuuri
OPTIMIZE TABLE recreates the whole table. That is why the counter gets reset. Workaround: use ALTER TABLE ... AUTO_INCREMENT=... to set the correct value after the OPTIMIZE. Fix: InnoDB should store the value of the internal auto-inc counter and restore it after OPTIMIZE TABLE (or an ALTER TABLE where it should not change). Regards, Heikki
[16 Mar 2006 10:44]
Heikki Tuuri
I am putting this as a feature request. This can be bundled with another feature request: InnoDB should remember the value of the internal auto-inc counter also after a mysqld shutdown.
[15 Feb 2007 18:02]
Tobias Asplund
Similar situation that could potentially be bad, when a fix for this comes, maybe make sure that the following works too? mysql> CREATE TABLE t1 (a INT PRIMARY KEY AUTO_INCREMENT) ENGINE = MyISAM; Query OK, 0 rows affected (0.07 sec) mysql> INSERT INTO t1 VALUES (), (), (), (), (); Query OK, 5 rows affected (0.00 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM t1; +---+ | a | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | +---+ 5 rows in set (0.00 sec) mysql> DELETE FROM t1 WHERE a > 3; Query OK, 2 rows affected (0.00 sec) mysql> ALTER TABLE t1 ENGINE = InnoDB; Query OK, 3 rows affected (0.28 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> INSERT INTO t1 VALUES (), (), (), (), (); Query OK, 5 rows affected (0.00 sec) Records: 5 Duplicates: 0 Warnings: 0 mysql> SELECT * FROM t1; +---+ | a | +---+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | +---+ 8 rows in set (0.00 sec)
