diff --git a/mysql-test/suite/innodb/r/insert_into_empty_notembedded.result b/mysql-test/suite/innodb/r/insert_into_empty_notembedded.result index 5305b2e7a85..789c17dfb20 100644 --- a/mysql-test/suite/innodb/r/insert_into_empty_notembedded.result +++ b/mysql-test/suite/innodb/r/insert_into_empty_notembedded.result @@ -28,3 +28,17 @@ DROP DATABASE db1; # # End of 10.6 tests # +# +# MDEV-30796 Auto_increment values not updated after bulk +# insert operation +# +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); +# restart +INSERT INTO t1(f2) VALUES(5); +SELECT max(f1) FROM t1; +max(f1) +26 +DROP TABLE t1; +# End of 10.9 tests diff --git a/mysql-test/suite/innodb/t/insert_into_empty_notembedded.test b/mysql-test/suite/innodb/t/insert_into_empty_notembedded.test index 267501133ea..0caeea59aae 100644 --- a/mysql-test/suite/innodb/t/insert_into_empty_notembedded.test +++ b/mysql-test/suite/innodb/t/insert_into_empty_notembedded.test @@ -41,3 +41,17 @@ DROP DATABASE db1; --echo # --echo # End of 10.6 tests --echo # + +--echo # +--echo # MDEV-30796 Auto_increment values not updated after bulk +--echo # insert operation +--echo # +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); +--source include/restart_mysqld.inc +INSERT INTO t1(f2) VALUES(5); +SELECT max(f1) FROM t1; +DROP TABLE t1; + +--echo # End of 10.9 tests diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 84befbaf311..32e61e65ba1 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -5336,6 +5336,8 @@ dberr_t row_merge_bulk_t::write_to_index(ulint index_no, trx_t *trx) func_exit: if (err != DB_SUCCESS) trx->error_info= index; + else if (index->is_primary() && table->persistent_autoinc) + btr_write_autoinc(index, table->autoinc); err= btr_bulk.finish(err); return err; }