mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
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]
This commit is contained in:
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user