From 1a95c2a4b2028d3808febdbd15c2ab48f0242414 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 21 May 2025 11:10:09 +0300 Subject: [PATCH] MDEV-36817 Server crashes in do_mark_index_columns instead of ER_DUP_ENTRY on partitioned table Now as c1492f3d077 (MDEV-36115) restores m_last_part table->file points to partition p0 while the error happens in p1, so error index does not match ib_table in innobase_get_mysql_key_number_for_index(). This case is handled by separate code block in innobase_get_mysql_key_number_for_index() which was wrong on using secondary index for dict_index_is_auto_gen_clust() and it was not covered by the tests. --- mysql-test/suite/versioning/r/partition.result | 9 +++++++++ mysql-test/suite/versioning/t/partition.test | 10 ++++++++++ storage/innobase/handler/ha_innodb.cc | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index bda04f6f0f6..580ced253a8 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -1805,6 +1805,15 @@ insert into t values (1),(2); DELETE from t; drop table t; # +# MDEV-36817 Server crashes in do_mark_index_columns instead of +# ER_DUP_ENTRY on partitioned table +# +create table t (f int, unique(f)) engine=innodb partition by key (f) partitions 2; +insert into t (f) values (1), (3); +update t set f = 0; +ERROR 23000: Duplicate entry '0' for key 'f' +drop table t; +# # End of 10.5 tests # set global innodb_stats_persistent= @save_persistent; diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index d3af1d25dd3..b3eceb7184a 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -1583,6 +1583,16 @@ insert into t values (1),(2); DELETE from t; drop table t; +--echo # +--echo # MDEV-36817 Server crashes in do_mark_index_columns instead of +--echo # ER_DUP_ENTRY on partitioned table +--echo # +create table t (f int, unique(f)) engine=innodb partition by key (f) partitions 2; +insert into t (f) values (1), (3); +--error ER_DUP_ENTRY +update t set f = 0; +drop table t; + --echo # --echo # End of 10.5 tests --echo # diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 562362db16e..7e8eef467cf 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -14554,13 +14554,14 @@ innobase_get_mysql_key_number_for_index( if (index->table != ib_table) { i = 0; ind = dict_table_get_first_index(index->table); + const bool auto_gen_clust = dict_index_is_auto_gen_clust(ind); while (index != ind) { ind = dict_table_get_next_index(ind); i++; } - if (dict_index_is_auto_gen_clust(index)) { + if (auto_gen_clust) { ut_a(i > 0); i--; }