From b771ab242baf238463837b9d19eb59d544bff475 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 29 Mar 2021 18:51:36 +0530 Subject: MDEV-25200 Index count mismatch due to aborted FULLTEXT INDEX - Aborting of fulltext index creation fails to remove the index from sys indexes table. When we try to reload the table definition, InnoDB fails with index count mismatch error. InnoDB should remove the index from sys indexes while rollbacking the secondary index creation. --- mysql-test/suite/innodb_fts/r/misc_debug.result | 26 +++++++++++++++++++++ mysql-test/suite/innodb_fts/t/misc_debug.test | 31 +++++++++++++++++++++++++ storage/innobase/row/row0merge.cc | 2 ++ 3 files changed, 59 insertions(+) diff --git a/mysql-test/suite/innodb_fts/r/misc_debug.result b/mysql-test/suite/innodb_fts/r/misc_debug.result index 8ef2ac425fc..b162b2f7415 100644 --- a/mysql-test/suite/innodb_fts/r/misc_debug.result +++ b/mysql-test/suite/innodb_fts/r/misc_debug.result @@ -26,3 +26,29 @@ SET DEBUG_DBUG="+d,fts_instrument_sync"; INSERT INTO t1 VALUES(1, "mariadb"); ALTER TABLE t1 FORCE; DROP TABLE t2, t1; +# +# MDEV-25200 Index count mismatch due to aborted FULLTEXT INDEX +# +CREATE TABLE t1(a INT, b TEXT, c TEXT, FULLTEXT INDEX(b)) ENGINE=InnoDB; +connect con1,localhost,root,,test; +SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL s1 WAIT_FOR g1'; +SET DEBUG_SYNC='innodb_commit_inplace_alter_table_enter SIGNAL s2 WAIT_FOR g2'; +ALTER TABLE t1 ADD FULLTEXT(c); +connection default; +SET DEBUG_SYNC='now WAIT_FOR s1'; +KILL QUERY @id; +SET DEBUG_SYNC='now SIGNAL g1 WAIT_FOR s2'; +START TRANSACTION; +SELECT * FROM t1; +a b c +SET DEBUG_SYNC='now SIGNAL s2'; +connection con1; +ERROR 70100: Query execution was interrupted +disconnect con1; +connection default; +SET DEBUG_SYNC=RESET; +ALTER TABLE t1 ADD bl INT AS (LENGTH(b)) VIRTUAL; +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +DROP TABLE t1; diff --git a/mysql-test/suite/innodb_fts/t/misc_debug.test b/mysql-test/suite/innodb_fts/t/misc_debug.test index aaf628abe6d..461e3f1d9d4 100644 --- a/mysql-test/suite/innodb_fts/t/misc_debug.test +++ b/mysql-test/suite/innodb_fts/t/misc_debug.test @@ -5,6 +5,8 @@ --source include/have_innodb.inc --source include/have_debug.inc +--source include/have_debug_sync.inc +--source include/count_sessions.inc # Following test is for Bug 14668777 - ASSERT ON IB_VECTOR_SIZE( # TABLE->FTS->INDEXES, ALTER TABLE @@ -52,3 +54,32 @@ INSERT INTO t1 VALUES(1, "mariadb"); ALTER TABLE t1 FORCE; # Cleanup DROP TABLE t2, t1; + +--echo # +--echo # MDEV-25200 Index count mismatch due to aborted FULLTEXT INDEX +--echo # +CREATE TABLE t1(a INT, b TEXT, c TEXT, FULLTEXT INDEX(b)) ENGINE=InnoDB; +connect(con1,localhost,root,,test); +let $ID= `SELECT @id := CONNECTION_ID()`; +SET DEBUG_SYNC='innodb_inplace_alter_table_enter SIGNAL s1 WAIT_FOR g1'; +SET DEBUG_SYNC='innodb_commit_inplace_alter_table_enter SIGNAL s2 WAIT_FOR g2'; +send ALTER TABLE t1 ADD FULLTEXT(c); +connection default; +SET DEBUG_SYNC='now WAIT_FOR s1'; +let $ignore= `SELECT @id := $ID`; +KILL QUERY @id; +SET DEBUG_SYNC='now SIGNAL g1 WAIT_FOR s2'; +START TRANSACTION; +SELECT * FROM t1; +SET DEBUG_SYNC='now SIGNAL s2'; +connection con1; +--error ER_QUERY_INTERRUPTED +reap; +disconnect con1; +connection default; +SET DEBUG_SYNC=RESET; +# Exploit MDEV-17468 to force the table definition to be reloaded +ALTER TABLE t1 ADD bl INT AS (LENGTH(b)) VIRTUAL; +CHECK TABLE t1; +DROP TABLE t1; +--source include/wait_until_count_sessions.inc diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 3de85f024a3..835d74043fd 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -3768,6 +3768,8 @@ row_merge_drop_indexes( ut_ad(prev); ut_a(table->fts); fts_drop_index(table, index, trx); + row_merge_drop_index_dict( + trx, index->id); /* We can remove a DICT_FTS index from the cache, because we do not allow ADD FULLTEXT INDEX -- cgit v1.2.1