diff options
author | Thirunarayanan B <thirunarayanan.balathandayuth@oracle.com> | 2014-02-10 10:13:35 +0530 |
---|---|---|
committer | Thirunarayanan B <thirunarayanan.balathandayuth@oracle.com> | 2014-02-10 10:13:35 +0530 |
commit | 7c12a9e5c3200688612d59160e8f45b1c8451635 (patch) | |
tree | 407483acf7b199ce206366d6c8216741417fbbfe | |
parent | 92971b9b3140149090da0ddde27ec68e7b006203 (diff) | |
download | mariadb-git-7c12a9e5c3200688612d59160e8f45b1c8451635.tar.gz |
Bug #14049391 INNODB MISCALCULATES AUTO-INCREMENT AFTER DECREASING
AUTO_INCREMENT_INCREMENT
Problem:
=======
When auto_increment_increment system variable decreases,
immediate next value of auto increment column is not affected.
Solution:
========
Get the previous inserted value of auto increment column by
subtracting the previous auto_increment_increment from next
auto increment value. After that calculate the current autoinc value
using newly changed auto_increment_increment variable.
Approved by Sunny [rb#4394]
-rw-r--r-- | mysql-test/suite/innodb/r/innodb-autoinc.result | 27 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/innodb-autoinc.test | 14 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 15 |
3 files changed, 56 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/r/innodb-autoinc.result b/mysql-test/suite/innodb/r/innodb-autoinc.result index ef45255fc7b..6f168ecbce6 100644 --- a/mysql-test/suite/innodb/r/innodb-autoinc.result +++ b/mysql-test/suite/innodb/r/innodb-autoinc.result @@ -1357,3 +1357,30 @@ t1 CREATE TABLE `t1` ( INSERT INTO t1 VALUES (); ERROR HY000: Failed to read auto-increment value from storage engine DROP TABLE t1; +# +# Bug #14049391 INNODB MISCALCULATES AUTO-INCREMENT +# AFTER CHANGING AUTO_INCREMENT_INCREMEMENT +# +CREATE TABLE t ( i INT AUTO_INCREMENT, KEY(i) ) ENGINE=InnoDB; +SET auto_increment_increment = 300; +INSERT INTO t VALUES (NULL), (NULL); +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `i` int(11) NOT NULL AUTO_INCREMENT, + KEY `i` (`i`) +) ENGINE=InnoDB AUTO_INCREMENT=601 DEFAULT CHARSET=latin1 +SET auto_increment_increment = 50; +INSERT INTO t VALUES (NULL); +SELECT * FROM t; +i +1 +301 +351 +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `i` int(11) NOT NULL AUTO_INCREMENT, + KEY `i` (`i`) +) ENGINE=InnoDB AUTO_INCREMENT=401 DEFAULT CHARSET=latin1 +DROP TABLE t; diff --git a/mysql-test/suite/innodb/t/innodb-autoinc.test b/mysql-test/suite/innodb/t/innodb-autoinc.test index 38038de732f..3d9f5916d8c 100644 --- a/mysql-test/suite/innodb/t/innodb-autoinc.test +++ b/mysql-test/suite/innodb/t/innodb-autoinc.test @@ -685,3 +685,17 @@ SHOW CREATE TABLE t1; --error 1467 INSERT INTO t1 VALUES (); DROP TABLE t1; + +--echo # +--echo # Bug #14049391 INNODB MISCALCULATES AUTO-INCREMENT +--echo # AFTER CHANGING AUTO_INCREMENT_INCREMEMENT +--echo # +CREATE TABLE t ( i INT AUTO_INCREMENT, KEY(i) ) ENGINE=InnoDB; +SET auto_increment_increment = 300; +INSERT INTO t VALUES (NULL), (NULL); +SHOW CREATE TABLE t; +SET auto_increment_increment = 50; +INSERT INTO t VALUES (NULL); +SELECT * FROM t; +SHOW CREATE TABLE t; +DROP TABLE t; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index b95a1f52ed5..adedc4fa961 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -10235,6 +10235,21 @@ ha_innobase::get_auto_increment( current = *first_value > col_max_value ? autoinc : *first_value; + /* If the increment step of the auto increment column + decreases then it is not affecting the immediate + next value in the series. */ + if (prebuilt->autoinc_increment > increment) { + + current = autoinc - prebuilt->autoinc_increment; + + current = innobase_next_autoinc( + current, 1, increment, 1, col_max_value); + + dict_table_autoinc_initialize(prebuilt->table, current); + + *first_value = current; + } + /* Compute the last value in the interval */ next_value = innobase_next_autoinc( current, *nb_reserved_values, increment, offset, |