From 57434359540c7eb6f8719ee74ebe70f6d43bb1b7 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 3 Sep 2025 18:56:13 +0200 Subject: [PATCH] MDEV-37397 Assertion `bitmap_is_set(&read_partitions, next->id)' failed in int partition_info::vers_set_hist_part(THD *) after 633417308f16 (MDEV-37312) lookup_handler is locked with F_WRLCK, because it may be used for deleting rows. And lookup_handler is locked with F_WRLCK after prune_partitions(), but the main handler is locked before, and might expects all partitions to be in the read least, non-pruned. Let's prepare the lookup handler before prune_partitions(). --- mysql-test/suite/period/r/long_unique.result | 6 ++++++ mysql-test/suite/period/t/long_unique.test | 7 +++++++ sql/sql_delete.cc | 5 +++-- sql/sql_update.cc | 2 +- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mysql-test/suite/period/r/long_unique.result b/mysql-test/suite/period/r/long_unique.result index fa7817fb562..6018edf9b4f 100644 --- a/mysql-test/suite/period/r/long_unique.result +++ b/mysql-test/suite/period/r/long_unique.result @@ -31,4 +31,10 @@ set transaction isolation level read committed; update t1 for portion of p from '1980-01-01' to '1980-01-02' set a = 1; ERROR 23000: Duplicate entry 'foo' for key 'f' drop table t1; +# +# MDEV-37397 Assertion `bitmap_is_set(&read_partitions, next->id)' failed in int partition_info::vers_set_hist_part(THD *) +# +create table t (f int,s date,e date,period for p (s,e),unique (f,p without overlaps)) with system versioning partition by system_time limit+1 (partition p history,partition pn current); +delete from t; +drop table t; # End of 10.6 tests diff --git a/mysql-test/suite/period/t/long_unique.test b/mysql-test/suite/period/t/long_unique.test index bca2f15ebae..299e22a8c62 100644 --- a/mysql-test/suite/period/t/long_unique.test +++ b/mysql-test/suite/period/t/long_unique.test @@ -41,4 +41,11 @@ set transaction isolation level read committed; update t1 for portion of p from '1980-01-01' to '1980-01-02' set a = 1; drop table t1; +--echo # +--echo # MDEV-37397 Assertion `bitmap_is_set(&read_partitions, next->id)' failed in int partition_info::vers_set_hist_part(THD *) +--echo # +create table t (f int,s date,e date,period for p (s,e),unique (f,p without overlaps)) with system versioning partition by system_time limit+1 (partition p history,partition pn current); +delete from t; +drop table t; + --echo # End of 10.6 tests diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index dc7b3fc00c4..2d6ce671b2f 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -511,6 +511,9 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, } } + if (table->versioned(VERS_TIMESTAMP) || (table_list->has_period())) + table->file->prepare_for_insert(1); + #ifdef WITH_PARTITION_STORAGE_ENGINE if (prune_partitions(thd, table, conds)) { @@ -813,8 +816,6 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, && !table->versioned() && table->file->has_transactions(); - if (table->versioned(VERS_TIMESTAMP) || (table_list->has_period())) - table->file->prepare_for_insert(1); DBUG_ASSERT(table->file->inited != handler::NONE); THD_STAGE_INFO(thd, stage_updating); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 6a2a5a09a66..2cbd2c692c8 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -559,6 +559,7 @@ int mysql_update(THD *thd, // Don't count on usage of 'only index' when calculating which key to use table->covering_keys.clear_all(); + table->file->prepare_for_insert(1); #ifdef WITH_PARTITION_STORAGE_ENGINE if (prune_partitions(thd, table, conds)) @@ -1021,7 +1022,6 @@ update_begin: can_compare_record= records_are_comparable(table); explain->tracker.on_scan_init(); - table->file->prepare_for_insert(1); DBUG_ASSERT(table->file->inited != handler::NONE); THD_STAGE_INFO(thd, stage_updating);