diff --git a/mysql-test/suite/innodb/r/stat_tables.result b/mysql-test/suite/innodb/r/stat_tables.result index bb449570479..c1ce6fc8fce 100644 --- a/mysql-test/suite/innodb/r/stat_tables.result +++ b/mysql-test/suite/innodb/r/stat_tables.result @@ -13,3 +13,17 @@ a drop table t1; rename table mysql.table_stats_save to mysql.table_stats; flush tables; +# +# MDEV-26753 Assertion state == TRX_STATE_PREPARED ||... failed +# +CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB; +XA START 'test'; +SELECT COUNT(*)>0 FROM mysql.innodb_index_stats LOCK IN SHARE MODE; +COUNT(*)>0 +1 +INSERT INTO t1 VALUES (1),(2); +UPDATE mysql.innodb_table_stats SET last_update=NULL WHERE table_name='t1'; +XA END 'test'; +XA ROLLBACK 'test'; +DROP TABLE t1; +# End of 10.6 tests diff --git a/mysql-test/suite/innodb/t/stat_tables.test b/mysql-test/suite/innodb/t/stat_tables.test index 68344b3f425..dd18c265e99 100644 --- a/mysql-test/suite/innodb/t/stat_tables.test +++ b/mysql-test/suite/innodb/t/stat_tables.test @@ -15,3 +15,17 @@ select * from t1; drop table t1; rename table mysql.table_stats_save to mysql.table_stats; flush tables; + +--echo # +--echo # MDEV-26753 Assertion state == TRX_STATE_PREPARED ||... failed +--echo # +CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB; +XA START 'test'; +SELECT COUNT(*)>0 FROM mysql.innodb_index_stats LOCK IN SHARE MODE; +INSERT INTO t1 VALUES (1),(2); +UPDATE mysql.innodb_table_stats SET last_update=NULL WHERE table_name='t1'; +XA END 'test'; +XA ROLLBACK 'test'; +DROP TABLE t1; + +--echo # End of 10.6 tests diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index 570903d4327..00a83ded00c 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2009, 2019, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2021, MariaDB Corporation. +Copyright (c) 2015, 2022, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -3115,7 +3115,9 @@ release_and_exit: ret = lock_table_for_trx(index_stats, trx, LOCK_X); } if (ret != DB_SUCCESS) { - trx->commit(); + if (trx->state != TRX_STATE_NOT_STARTED) { + trx->commit(); + } goto unlocked_free_and_exit; }