1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

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

- This issue caused by commit 4700f2ac70f8c79f2ac1968b6b59d18716f492bf(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.
This commit is contained in:
Thirunarayanan Balathandayuthapani
2023-08-29 10:37:08 +05:30
parent cd5808eb8d
commit cb384d0d04
3 changed files with 19 additions and 1 deletions

View File

@ -28,6 +28,7 @@ DROP DATABASE db1;
# #
# End of 10.6 tests # End of 10.6 tests
# #
SET foreign_key_checks=0, unique_checks=0;
# #
# MDEV-30796 Auto_increment values not updated after bulk # MDEV-30796 Auto_increment values not updated after bulk
# insert operation # insert operation
@ -35,7 +36,21 @@ DROP DATABASE db1;
CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT, CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT,
f2 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB; f2 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
INSERT INTO t1 VALUES(1, 2), (25, 3), (2, 4); 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 # 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); INSERT INTO t1(f2) VALUES(5);
SELECT max(f1) FROM t1; SELECT max(f1) FROM t1;
max(f1) max(f1)

View File

@ -42,6 +42,7 @@ DROP DATABASE db1;
--echo # End of 10.6 tests --echo # End of 10.6 tests
--echo # --echo #
SET foreign_key_checks=0, unique_checks=0;
--echo # --echo #
--echo # MDEV-30796 Auto_increment values not updated after bulk --echo # MDEV-30796 Auto_increment values not updated after bulk
--echo # insert operation --echo # insert operation
@ -49,7 +50,9 @@ DROP DATABASE db1;
CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT, CREATE TABLE t1(f1 INT NOT NULL AUTO_INCREMENT,
f2 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB; f2 INT NOT NULL, PRIMARY KEY(f1))ENGINE=InnoDB;
INSERT INTO t1 VALUES(1, 2), (25, 3), (2, 4); INSERT INTO t1 VALUES(1, 2), (25, 3), (2, 4);
SHOW CREATE TABLE t1;
--source include/restart_mysqld.inc --source include/restart_mysqld.inc
SHOW CREATE TABLE t1;
INSERT INTO t1(f2) VALUES(5); INSERT INTO t1(f2) VALUES(5);
SELECT max(f1) FROM t1; SELECT max(f1) FROM t1;
DROP TABLE t1; DROP TABLE t1;

View File

@ -5344,7 +5344,7 @@ func_exit:
if (err != DB_SUCCESS) if (err != DB_SUCCESS)
trx->error_info= index; trx->error_info= index;
else if (index->is_primary() && table->persistent_autoinc) 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); err= btr_bulk.finish(err);
return err; return err;
} }