Bug #727 | auto_increment after mysqld restart | ||
---|---|---|---|
Submitted: | 26 Jun 2003 1:01 | Modified: | 26 Jun 2003 1:38 |
Reporter: | Thomas Mayer | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 4.0.13 | OS: | Linux (Redhat 7.3) |
Assigned to: | CPU Architecture: | Any |
[26 Jun 2003 1:01]
Thomas Mayer
[26 Jun 2003 1:13]
Thomas Mayer
I've just seen this has already been reported (#199 in suspended) months ago and the behaviour should even be documented: " [22 Apr 10:37am] Heikki Tuuri Does no break replication as the binlog contains the auto-inc column value for each new insert / replace. This behavior is a documented feature which will be fixed in the future at the same time a fast COUNT(*) is introduced to InnoDB.[26 Apr 7:25am] Michael Widenius I have now documented this behaviour in the MySQL manual " Sorry for duplicate entry. Hope, this is solved soon.
[26 Jun 2003 1:38]
Heikki Tuuri
Hi! Yes, this is the documented behavior. http://www.innodb.com/ibman.html#InnoDB_auto_inc " InnoDB uses the following algorith to initialize the auto-increment counter. After a database startup, when a user the first time does an insert to a table T or calls SHOW TABLE STATUS where the table T is shown, then InnoDB executes SELECT MAX(auto-inc-column) FROM T FOR UPDATE, and assigns that value incremented by one to the column and the auto-increment counter of the table. " You should not assume that the auto-inc counter survives over a mysqld restart. In the future we will probably make it to survive, though it will consume some CPU time. Regards, Heikki
[8 Mar 2011 17:49]
Sergio Cardoso
I have the same problem. I'm using MySQL 5.1.52-enterprise-commercial-advanced, on an Red Hat 5.4 x64. Exists any patch for this problem?
[20 Jan 2012 15:33]
Thomas Mayer
Sergio, starting from MySQL 5.0 you can use triggers to address this problem. A workaround for me is to use the auto_increment of an archive_table: delimiter // drop trigger if exists trigger_autoinc_tbl; CREATE TRIGGER trigger_autoinc_tbl BEFORE INSERT ON tbl FOR EACH ROW BEGIN declare auto_incr1 BIGINT; declare auto_incr2 BIGINT; SELECT AUTO_INCREMENT INTO auto_incr1 FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='tbl'; SELECT AUTO_INCREMENT INTO auto_incr2 FROM information_schema.TABLES WHERE table_schema=DATABASE() AND table_name='tbl_archiv'; IF (auto_incr2 > auto_incr1 and NEW.id<auto_incr2) THEN SET NEW.id = auto_incr2; END IF; END;// delimiter ; Further reading: http://www.slicewise.net/index.php?id=82
[9 Jul 2015 18:30]
Sveta Smirnova
This is duplicate of bug #199.