From b57c536e674571cabd01fb43ce3658fb619d8831 Mon Sep 17 00:00:00 2001 From: Ming Lin Date: Thu, 16 Aug 2018 09:04:32 -0700 Subject: [PATCH] Update AUTO_INCREMENT in the UPDATE statement (#868) Upstream commit ID : fb-mysql-5.6.35/f8ea6852be5484ed15ffbac844b3719673f0f057 PS-5217 : Merge fb-prod201803 Summary: Currently RocksDB engine doesn't update AUTO_INCREMENT in the UPDATE statement. For example, CREATE TABLE t1 (pk INT AUTO_INCREMENT, a INT, PRIMARY KEY(pk)) ENGINE=RocksDB; INSERT INTO t1 (a) VALUES (1); UPDATE t1 SET pk = 3; ==> AUTO_INCREMENT should be updated to 4. Without this fix, it hits the Assertion `dd_val >= last_val' failed in myrocks::ha_rocksdb::load_auto_incr_value_from_index. Please see detail at: https://jira.mariadb.org/browse/MDEV-16703 Pull Request resolved: https://github.com/facebook/mysql-5.6/pull/868 Differential Revision: D9360242 Pulled By: lth fbshipit-source-id: 70ee31cb90f --- mysql-test/suite/rocksdb/r/autoinc_vars.result | 8 ++++++++ mysql-test/suite/rocksdb/t/autoinc_vars.test | 10 ++++++++++ storage/rocksdb/ha_rocksdb.cc | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/rocksdb/r/autoinc_vars.result b/mysql-test/suite/rocksdb/r/autoinc_vars.result index a1b27cd5f702..b0b2bb56a09c 100644 --- a/mysql-test/suite/rocksdb/r/autoinc_vars.result +++ b/mysql-test/suite/rocksdb/r/autoinc_vars.result @@ -155,3 +155,11 @@ CREATE TABLE t0(c0 BLOB) ENGINE=ROCKSDB; INSERT INTO t0 VALUES(0); ALTER TABLE t0 AUTO_INCREMENT=0; DROP TABLE t0; +#---------------------------------- +# Issue #869 Crash in autoincrement +#---------------------------------- +CREATE TABLE t1 (pk INT AUTO_INCREMENT, a INT, PRIMARY KEY(pk)) ENGINE=RocksDB; +INSERT INTO t1 (a) VALUES (1); +UPDATE t1 SET pk = 3; +ALTER TABLE t1 AUTO_INCREMENT 2; +DROP TABLE t1; diff --git a/mysql-test/suite/rocksdb/t/autoinc_vars.test b/mysql-test/suite/rocksdb/t/autoinc_vars.test index 8a030ff1dbea..1b48501c542a 100644 --- a/mysql-test/suite/rocksdb/t/autoinc_vars.test +++ b/mysql-test/suite/rocksdb/t/autoinc_vars.test @@ -119,3 +119,13 @@ CREATE TABLE t0(c0 BLOB) ENGINE=ROCKSDB; INSERT INTO t0 VALUES(0); ALTER TABLE t0 AUTO_INCREMENT=0; DROP TABLE t0; + +--echo #---------------------------------- +--echo # Issue #869 Crash in autoincrement +--echo #---------------------------------- + +CREATE TABLE t1 (pk INT AUTO_INCREMENT, a INT, PRIMARY KEY(pk)) ENGINE=RocksDB; +INSERT INTO t1 (a) VALUES (1); +UPDATE t1 SET pk = 3; +ALTER TABLE t1 AUTO_INCREMENT 2; +DROP TABLE t1; diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 2289ffa8973e..1e8f1be8c0d0 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -8929,7 +8929,7 @@ int ha_rocksdb::update_pk(const Rdb_key_def &kd, } } - if (table->next_number_field) { + if (table->found_next_number_field) { update_auto_incr_val_from_field(); }