MDEV-32008 auto_increment value on table increments by one after restart

- This issue caused by commit 4700f2ac(MDEV-30796)
During bulk insert operation, InnoDB wrongly stores the next autoincrement
value as current autoincrement value. So update the current autoincrement
value rather than next auto increment value.
parent cd5808eb
......@@ -28,6 +28,7 @@ DROP DATABASE db1;
#
# End of 10.6 tests
#
SET foreign_key_checks=0, unique_checks=0;
#
# MDEV-30796 Auto_increment values not updated after bulk
# insert operation
......@@ -35,7 +36,21 @@ DROP DATABASE db1;
CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT,
f2 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
INSERT INTO t1 VALUES(1, 2), (25, 3), (2, 4);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` int(11) NOT NULL AUTO_INCREMENT,
`f2` int(11) NOT NULL,
PRIMARY KEY (`f1`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
# restart
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` int(11) NOT NULL AUTO_INCREMENT,
`f2` int(11) NOT NULL,
PRIMARY KEY (`f1`)
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1(f2) VALUES(5);
SELECT max(f1) FROM t1;
max(f1)
......
......@@ -42,6 +42,7 @@ DROP DATABASE db1;
--echo # End of 10.6 tests
--echo #
SET foreign_key_checks=0, unique_checks=0;
--echo #
--echo # MDEV-30796 Auto_increment values not updated after bulk
--echo # insert operation
......@@ -49,7 +50,9 @@ DROP DATABASE db1;
CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT,
f2 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
INSERT INTO t1 VALUES(1, 2), (25, 3), (2, 4);
SHOW CREATE TABLE t1;
--source include/restart_mysqld.inc
SHOW CREATE TABLE t1;
INSERT INTO t1(f2) VALUES(5);
SELECT max(f1) FROM t1;
DROP TABLE t1;
......
......@@ -5344,7 +5344,7 @@ dberr_t row_merge_bulk_t::write_to_index(ulint index_no, trx_t *trx)
if (err != DB_SUCCESS)
trx->error_info= index;
else if (index->is_primary() && table->persistent_autoinc)
btr_write_autoinc(index, table->autoinc);
btr_write_autoinc(index, table->autoinc - 1);
err= btr_bulk.finish(err);
return err;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment