Bug #84598 ARCHIVE auto_increment field reset on OPTIMIZE TABLE
Submitted: 21 Jan 2017 20:08 Modified: 23 Jan 2017 4:26
Reporter: gz — Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Archive storage engine Severity:S2 (Serious)
Version:5.7.15 OS:Any
Assigned to: CPU Architecture:Any

[21 Jan 2017 20:08] gz —
Description:
ARCHIVE auto_increment table field reset on OPTIMIZE TABLE or REPAIR TABLE.
On InnoDB or MyISAM tables this works fine.

How to repeat:
CREATE TABLE `_test` (
	`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`logged` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
	PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=Archive
;

INSERT INTO _test
(logged, `data`)
VALUES
(NOW()),
(NOW())
;

SELECT `AUTO_INCREMENT` AS 'ai_before_optimize'
FROM INFORMATION_SCHEMA.TABLES
WHERE
	TABLE_SCHEMA = 'db'
	AND TABLE_NAME = '_test';

OPTIMIZE TABLE _test
;

SELECT `AUTO_INCREMENT` AS 'ai_after_optimize'
FROM INFORMATION_SCHEMA.TABLES
WHERE
	TABLE_SCHEMA = 'db'
	AND TABLE_NAME = '_test'
;

#DROP TABLE _test
#;

Result:
+--------------------+
| ai_before_optimize |
+--------------------+
|                  3 |
+--------------------+
…
+-------------------+
| ai_after_optimize |
+-------------------+
|                 1 |
+-------------------+

InnoDB table, for example:
+--------------------+
| ai_before_optimize |
+--------------------+
|                  3 |
+--------------------+
…
+-------------------+
| ai_after_optimize |
+-------------------+
|                 3 |
+-------------------+

Documentation advises "To achieve better compression, you can use OPTIMIZE TABLE or REPAIR TABLE", but this reset ID sequence generation.
http://dev.mysql.com/doc/refman/5.7/en/archive-storage-engine.html
[21 Jan 2017 20:27] gz —
INSERT INTO _test
(logged)
VALUES
(NOW()),
(NOW())
;

Forgot to remove unnecessary field.
[23 Jan 2017 4:26] MySQL Verification Team
Hello!

Thank you for the report.
This is duplicate of Bug #40216

Thanks,
Umesh