From db655e1310adc7be8dd7670c22c059599ff37b89 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 4 Apr 2022 19:34:59 +0530 Subject: [PATCH] MDEV-28237 Assertion `0' failed in row_upd_sec_index_entry on DELETE - InnoDB bulk insert operation fails to rollback when it detect DB_DUPLICATE_KEY error. It leads to orphaned records in primary indexes. Consecutive update/delete operation assumes that record should exist in secondary index and it leads to failure. --- mysql-test/suite/innodb/r/insert_into_empty.result | 8 ++++++++ mysql-test/suite/innodb/t/insert_into_empty.test | 9 +++++++++ storage/innobase/handler/ha_innodb.cc | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/mysql-test/suite/innodb/r/insert_into_empty.result b/mysql-test/suite/innodb/r/insert_into_empty.result index 8fd53204e48..b0568d48ed2 100644 --- a/mysql-test/suite/innodb/r/insert_into_empty.result +++ b/mysql-test/suite/innodb/r/insert_into_empty.result @@ -260,3 +260,11 @@ SPATIAL INDEX(f2))ENGINE=InnoDB; INSERT INTO t1(f1) VALUES(0), (1), (2); ERROR 23000: Duplicate entry '1' for key 'f1' DROP TABLE t1; +# +# MDEV-28237 Assertion `0' failed in row_upd_sec_index_entry on DELETE +# +CREATE TABLE t1 (c0 YEAR UNIQUE) ENGINE=InnoDB; +INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(0),(0); +ERROR HY000: Got error 1 "Operation not permitted" during COMMIT +DELETE FROM t1; +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/insert_into_empty.test b/mysql-test/suite/innodb/t/insert_into_empty.test index a1220cb718c..23b0f654eb5 100644 --- a/mysql-test/suite/innodb/t/insert_into_empty.test +++ b/mysql-test/suite/innodb/t/insert_into_empty.test @@ -272,3 +272,12 @@ SPATIAL INDEX(f2))ENGINE=InnoDB; --error ER_DUP_ENTRY INSERT INTO t1(f1) VALUES(0), (1), (2); DROP TABLE t1; + +--echo # +--echo # MDEV-28237 Assertion `0' failed in row_upd_sec_index_entry on DELETE +--echo # +CREATE TABLE t1 (c0 YEAR UNIQUE) ENGINE=InnoDB; +--error ER_ERROR_DURING_COMMIT +INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(0),(0); +DELETE FROM t1; +DROP TABLE t1; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 60e44b4e7e3..df9159db7a2 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -17000,6 +17000,10 @@ innobase_xa_prepare( SQL statement */ trx_mark_sql_stat_end(trx); + if (UNIV_UNLIKELY(trx->error_state != DB_SUCCESS)) { + trx_rollback_for_mysql(trx); + return 1; + } } if (thd_sql_command(thd) != SQLCOM_XA_PREPARE