Skip to content

Commit 0dd6566

Browse files
MDEV-37123 dict_table_open_on_id() fails to release dict_sys.latch
While updating the persistent defragmentation statistics for the table, InnoDB opens the table only if it is in cache. If dict_table_open_on_id() fails to find the table in cache then it fails to unfreeze dict_sys.latch. This lead to crash
1 parent 2d5dfc4 commit 0dd6566

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,11 @@ ALTER TABLE t2 STATS_PERSISTENT=1;
131131
DROP TABLE t2;
132132
SELECT * FROM mysql.innodb_index_stats;
133133
database_name table_name index_name last_update stat_name stat_value sample_size stat_description
134+
#
135+
# MDEV-37123 dict_table_open_on_id() fails to release dict_sys.latch
136+
#
137+
SET GLOBAL innodb_defragment_stats_accuracy=1;
138+
CREATE TABLE t (f INT,f2 CHAR(1),KEY k1 (f2),FULLTEXT KEY(f2),
139+
FOREIGN KEY(f2) REFERENCES t (f3)) ENGINE=InnoDB;
140+
ERROR HY000: Can't create table `test`.`t` (errno: 150 "Foreign key constraint is incorrectly formed")
141+
SET GLOBAL innodb_defragment_stats_accuracy=default;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ ALTER TABLE t2 STATS_PERSISTENT=1;
8686
DROP TABLE t2;
8787

8888
SELECT * FROM mysql.innodb_index_stats;
89+
90+
--echo #
91+
--echo # MDEV-37123 dict_table_open_on_id() fails to release dict_sys.latch
92+
--echo #
93+
SET GLOBAL innodb_defragment_stats_accuracy=1;
94+
--error ER_CANT_CREATE_TABLE
95+
CREATE TABLE t (f INT,f2 CHAR(1),KEY k1 (f2),FULLTEXT KEY(f2),
96+
FOREIGN KEY(f2) REFERENCES t (f3)) ENGINE=InnoDB;
97+
SET GLOBAL innodb_defragment_stats_accuracy=default;

storage/innobase/dict/dict0dict.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,8 @@ dict_table_t *dict_table_open_on_id(table_id_t table_id, bool dict_locked,
927927
else if (table)
928928
table->acquire();
929929
}
930+
else if (!dict_locked)
931+
dict_sys.unfreeze();
930932

931933
return table;
932934
}

0 commit comments

Comments
 (0)