From: Jon Olav Hauglid Date: January 4 2011 1:36pm Subject: bzr commit into mysql-5.1 branch (jon.hauglid:3532) Bug#50619 List-Archive: http://lists.mysql.com/commits/127874 X-Bug: 50619 Message-Id: <201101041339.p04Ddk1e028048@rcsinet15.oracle.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8751604966706083354==" --===============8751604966706083354== MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline #At file:///export/home/x/mysql-5.1-bug50619/ based on revid:guilhem.bichot@stripped 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. modified: mysql-test/r/auto_increment.result mysql-test/t/auto_increment.test === modified file 'mysql-test/r/auto_increment.result' --- a/mysql-test/r/auto_increment.result 2010-12-13 11:48:12 +0000 +++ b/mysql-test/r/auto_increment.result 2011-01-04 13:36:37 +0000 @@ -497,3 +497,22 @@ SET @@SESSION.AUTO_INCREMENT_INCREMENT=d SET @@SESSION.AUTO_INCREMENT_OFFSET=default; DROP TABLE t1; End of 5.1 tests +# +# Bug#50619 assert in handler::update_auto_increment +# +CREATE TABLE t1 (pk INT AUTO_INCREMENT, PRIMARY KEY (pk)); +INSERT INTO t1 VALUES (NULL), (-1), (NULL); +SELECT * FROM t1; +pk +-1 +1 +2 +DROP TABLE t1; +CREATE TABLE t1 (pk BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY (pk)); +INSERT INTO t1 VALUES (NULL), (18446744073709551615-1), (NULL); +ERROR HY000: Failed to read auto-increment value from storage engine +SELECT * FROM t1; +pk +1 +18446744073709551614 +DROP TABLE t1; === modified file 'mysql-test/t/auto_increment.test' --- a/mysql-test/t/auto_increment.test 2010-12-13 11:48:12 +0000 +++ b/mysql-test/t/auto_increment.test 2011-01-04 13:36:37 +0000 @@ -363,3 +363,20 @@ SET @@SESSION.AUTO_INCREMENT_OFFSET=defa DROP TABLE t1; --echo End of 5.1 tests + +--echo # +--echo # Bug#50619 assert in handler::update_auto_increment +--echo # + +CREATE TABLE t1 (pk INT AUTO_INCREMENT, PRIMARY KEY (pk)); +# This triggered the assert +INSERT INTO t1 VALUES (NULL), (-1), (NULL); +SELECT * FROM t1; +DROP TABLE t1; + +# Check that that true overflow still gives error +CREATE TABLE t1 (pk BIGINT UNSIGNED AUTO_INCREMENT, PRIMARY KEY (pk)); +--error ER_AUTOINC_READ_FAILED +INSERT INTO t1 VALUES (NULL), (18446744073709551615-1), (NULL); +SELECT * FROM t1; +DROP TABLE t1; --===============8751604966706083354== MIME-Version: 1.0 Content-Type: text/bzr-bundle; charset="us-ascii"; name="bzr/jon.hauglid@stripped" Content-Transfer-Encoding: 7bit Content-Disposition: inline # Bazaar merge directive format 2 (Bazaar 0.90) # revision_id: jon.hauglid@stripped # target_branch: file:///export/home/x/mysql-5.1-bug50619/ # testament_sha1: f29578ba7f70adf060387de834a27f02b4c9b84d # timestamp: 2011-01-04 14:36:42 +0100 # base_revision_id: guilhem.bichot@stripped\ # mf0jvafrh6kbwdek # # Begin bundle IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTW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