Bug #50619 | assert in handler::update_auto_increment | ||
---|---|---|---|
Submitted: | 26 Jan 2010 11:02 | Modified: | 10 Jan 2011 3:31 |
Reporter: | Matthias Leich | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 5.1.44,5.5.99-m3,6.0.14-alpha | OS: | Any |
Assigned to: | Jon Olav Hauglid | CPU Architecture: | Any |
Tags: | assert, auto_increment |
[26 Jan 2010 11:02]
Matthias Leich
[23 Feb 2010 12:17]
Matthias Leich
Test hitting the same assert: CREATE TABLE t1 ( pk INT AUTO_INCREMENT, PRIMARY KEY (pk)); INSERT INTO t1 ( pk ) VALUES (-1); CREATE TRIGGER tr1 BEFORE DELETE ON t1 FOR EACH ROW SET @aux = 1 ; COMMIT ; REPLACE INTO t1 ( pk ) VALUES ( NULL ) , ( -1 );
[10 Nov 2010 15:06]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/123436 3179 Jon Olav Hauglid 2010-11-10 Bug #50619 assert in handler::update_auto_increment This assert could happen during subsequent inserts if -1 had already been inserted into an auto increment column. The root cause of the problem is that auto increment values are internally stored unsigned while auto increment column types can be signed values. When an explict value is set for the auto increment column, the internal auto increment value is reset to the explicit value + 1. However, if the explicit value is -1, converting this value to unsigned and adding 1 will yield 0 as a result (due to overflow). Since 0 would be outside the reserved auto increment interval for the insert (auto increment values should start at 1), the assert would be triggered. This patch fixes the problem by checking if the explicit value is negative. If this is the case, auto increment values are not reset. Test case added to auto_increment.test.
[13 Dec 2010 14:47]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/126652 3424 Jon Olav Hauglid 2010-12-13 Bug #50619 assert in handler::update_auto_increment This assert could be triggered if -1 was inserted into an auto increment column by a statement writing more than one row. Unless explicitly given, an interval of auto increment values is generated when a statement first needs an auto increment value. The triggered assert checks that the auto increment counter is equal to or higher than the lower bound of this interval. Generally, the auto increment counter starts at 1 and is incremented by 1 each time it is used. However, inserting an explicit value into the auto increment column, sets the auto increment counter to this value + 1 if this value is higher than the current value of the auto increment counter. This bug was triggered if the explicit value was -1. Since the value was converted to unsigned before any comparisons were made, it was found to be higher than the current vale of the auto increment counter and the counter was set to -1 + 1. This value was below the reserved interval and caused the assert to be triggered the next time the statement tried to write a row. This patch fixes the problem by only allowing the auto increment counter to be set if the given explicit value is positive. Test case added to auto_increment.test.
[4 Jan 2011 13:40]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/127874 3532 Jon Olav Hauglid 2011-01-04 Bug #50619 assert in handler::update_auto_increment This assert could be triggered if -1 was inserted into an auto increment column by a statement writing more than one row. Unless explicitly given, an interval of auto increment values is generated when a statement first needs an auto increment value. The triggered assert checks that the auto increment counter is equal to or higher than the lower bound of this interval. Generally, the auto increment counter starts at 1 and is incremented by 1 each time it is used. However, inserting an explicit value into the auto increment column, sets the auto increment counter to this value + 1 if this value is higher than the current value of the auto increment counter. This bug was triggered if the explicit value was -1. Since the value was converted to unsigned before any comparisons were made, it was found to be higher than the current vale of the auto increment counter and the counter was set to -1 + 1. This value was below the reserved interval and caused the assert to be triggered the next time the statement tried to write a row. With the patch for Bug#39828, this bug is no longer repeatable. Now, -1 + 1 is detected as an "overflow" which causes the auto increment counter to be set to ULONGLONG_MAX. This avoids hitting the assert for the next insert and causes a new interval of auto increment values to be generated. This resolves the issue. This patch therefore only contains a regression test and no code changes. Test case added to auto_increment.test.
[4 Jan 2011 14:31]
Bugs System
Pushed into mysql-trunk 5.6.2 (revid:jon.hauglid@oracle.com-20110104143005-920jhiyi67x17kez) (version source revid:jon.hauglid@oracle.com-20110104143005-920jhiyi67x17kez) (merge vers: 5.6.2) (pib:24)
[4 Jan 2011 14:32]
Bugs System
Pushed into mysql-5.5 5.5.9 (revid:jon.hauglid@oracle.com-20110104142803-kxkbv0ud3x8g2ejd) (version source revid:jon.hauglid@oracle.com-20110104142803-kxkbv0ud3x8g2ejd) (merge vers: 5.5.9) (pib:24)
[4 Jan 2011 14:32]
Bugs System
Pushed into mysql-5.1 5.1.55 (revid:jon.hauglid@oracle.com-20110104133637-33qff7ri9vz47r27) (version source revid:jon.hauglid@oracle.com-20110104133637-33qff7ri9vz47r27) (merge vers: 5.1.55) (pib:24)
[4 Jan 2011 14:34]
Jon Olav Hauglid
Bug#46902 was marked as a duplicate of this bug.
[10 Jan 2011 3:31]
Paul DuBois
Noted in 5.1.55, 5.5.9, 5.6.2 changelogs. An assertion could be raised if -1 was inserted into an AUTO_INCREMENT column by a statement writing more than one row.