Skip to content

Commit 2c00526

Browse files
committed
MDEV-26753 Assertion state == TRX_STATE_PREPARED ||... failed
dict_stats_save(): Do not attempt to commit an already committed transaction.
1 parent 2ca1123 commit 2c00526

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

mysql-test/suite/innodb/r/stat_tables.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,17 @@ a
1313
drop table t1;
1414
rename table mysql.table_stats_save to mysql.table_stats;
1515
flush tables;
16+
#
17+
# MDEV-26753 Assertion state == TRX_STATE_PREPARED ||... failed
18+
#
19+
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
20+
XA START 'test';
21+
SELECT COUNT(*)>0 FROM mysql.innodb_index_stats LOCK IN SHARE MODE;
22+
COUNT(*)>0
23+
1
24+
INSERT INTO t1 VALUES (1),(2);
25+
UPDATE mysql.innodb_table_stats SET last_update=NULL WHERE table_name='t1';
26+
XA END 'test';
27+
XA ROLLBACK 'test';
28+
DROP TABLE t1;
29+
# End of 10.6 tests

mysql-test/suite/innodb/t/stat_tables.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ select * from t1;
1515
drop table t1;
1616
rename table mysql.table_stats_save to mysql.table_stats;
1717
flush tables;
18+
19+
--echo #
20+
--echo # MDEV-26753 Assertion state == TRX_STATE_PREPARED ||... failed
21+
--echo #
22+
CREATE TABLE t1(a INT PRIMARY KEY) ENGINE=InnoDB;
23+
XA START 'test';
24+
SELECT COUNT(*)>0 FROM mysql.innodb_index_stats LOCK IN SHARE MODE;
25+
INSERT INTO t1 VALUES (1),(2);
26+
UPDATE mysql.innodb_table_stats SET last_update=NULL WHERE table_name='t1';
27+
XA END 'test';
28+
XA ROLLBACK 'test';
29+
DROP TABLE t1;
30+
31+
--echo # End of 10.6 tests

storage/innobase/dict/dict0stats.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2009, 2019, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2015, 2021, MariaDB Corporation.
4+
Copyright (c) 2015, 2022, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -3115,7 +3115,9 @@ dict_stats_save(
31153115
ret = lock_table_for_trx(index_stats, trx, LOCK_X);
31163116
}
31173117
if (ret != DB_SUCCESS) {
3118-
trx->commit();
3118+
if (trx->state != TRX_STATE_NOT_STARTED) {
3119+
trx->commit();
3120+
}
31193121
goto unlocked_free_and_exit;
31203122
}
31213123

0 commit comments

Comments
 (0)