summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/suite/innodb/r/innodb-autoinc.result27
-rw-r--r--mysql-test/suite/innodb/t/innodb-autoinc.test14
-rw-r--r--storage/innobase/handler/ha_innodb.cc15
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,