Bug #43795 | Autoincrement increased by 2 on duplicate key condition | ||
---|---|---|---|
Submitted: | 23 Mar 2009 5:28 | Modified: | 23 Mar 2009 6:15 |
Reporter: | Susan Cai | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: InnoDB storage engine | Severity: | S2 (Serious) |
Version: | 5.1.32-community | OS: | Windows |
Assigned to: | CPU Architecture: | Any | |
Tags: | autoincrement, DUPLICATE KEY UPDATE, unique key |
[23 Mar 2009 5:28]
Susan Cai
[23 Mar 2009 6:15]
Valeriy Kravchuk
Sorry, but this is not a bug. This behavior looks intended and is somehow documented. Read http://dev.mysql.com/doc/refman/5.1/en/innodb-auto-increment-handling.html: "A similar situation exists if you use INSERT ... ON DUPLICATE KEY UPDATE. This statement is also classified as a “mixed-mode insert” since an auto-increment value is not necessarily generated for each row. Because InnoDB allocates the auto-increment value before the insert is actually attempted, it cannot know whether an inserted value will be a duplicate of an existing value and thus cannot know whether the auto-increment value it generates will be used for a new row."
[28 Apr 2009 12:34]
Michael Davies
Afternoon all.. I'm a little confused by this issue and perhaps someone from the MySQL team could clarify. On this issue you state that this is not a bug but is being caused by the system not knowing if the row already exists before the auto-increment is updated.. I can understand this logic and was prepared to leave it at that until I found this issue raised in June last year http://bugs.mysql.com/bug.php?id=37560 It reports the same issue but says that it was fixed sometime before 5.0.51b (see results from Miguel's test, numbers incremented as expected). I've run his test here on 5.1.31-community and see the same problem initially reported by Nathan. Could someone please clarify if this is a bug or not? Thanks