commit e082eadab813a4fb63975b4a5c5c96a401e73af2 Author: zhongbei.yk Date: Wed Jun 28 15:50:18 2023 +0800 BUG#110976 full-text index with parser rebuilt incorrect When the ngram parser is added to a full-text index without a parser using the inplace DDL algorithm in a separate DDL statement, the full-text index does not change. When the copy DDL algorithm is used or the rebuilt DDL statement is divided into two DDL statement, the problem can be solved. Reason: In a inplace DDL, has_index_def_changed function is responsible for judging whether the index is changed. When the index is changed, the index will be rebuilt. However, when the full-text index’s parser is changed, has_index_def_changed has no logic to sense that change. How to fix: When the full-text index’s parser is changed, the ful-text index should be to be rebuilt. Add this judgment logic to the has_index_def_changed function. diff --git a/mysql-test/r/bug110976.result b/mysql-test/r/bug110976.result new file mode 100644 index 00000000000..0ad9b6c880e --- /dev/null +++ b/mysql-test/r/bug110976.result @@ -0,0 +1,56 @@ +INSTALL PLUGIN simple_parser SONAME 'mypluglib.so'; +##################################################################### +# 1. Prepare a table with a full-text index with default parser. +##################################################################### +CREATE TABLE t (name varchar(256), FULLTEXT KEY ft_index (name)) ENGINE = InnoDB; +# full-text index should have no ngram parser. +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `name` varchar(256) DEFAULT NULL, + FULLTEXT KEY `ft_index` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci +################################################################################################# +# 2. Modify full-text index from default parser to ngram parser in a DDL statement by inplace DDL +################################################################################################# +ALTER TABLE t +DROP INDEX ft_index , +ADD FULLTEXT INDEX ft_index (name) WITH PARSER ngram , algorithm = inplace; +# full-text index should have ngram parser. +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `name` varchar(256) DEFAULT NULL, + FULLTEXT KEY `ft_index` (`name`) /*!50100 WITH PARSER `ngram` */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci +################################################################################################ +# 3. Modify full-text index from ngram parser to simple_parser in a DDL statement by inplace DDL +################################################################################################ +ALTER TABLE t +DROP INDEX ft_index , +ADD FULLTEXT INDEX ft_index (name) WITH PARSER simple_parser , algorithm = inplace; +# full-text index should have simple_parser. +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `name` varchar(256) DEFAULT NULL, + FULLTEXT KEY `ft_index` (`name`) /*!50100 WITH PARSER `simple_parser` */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci +################################################################################################## +# 4. Modify full-text index from simple_parser to default parser in a DDL statement by inplace DDL +################################################################################################## +ALTER TABLE t +DROP INDEX ft_index , +ADD FULLTEXT INDEX ft_index (name), algorithm = inplace; +# full-text index should have no ngram parser. +SHOW CREATE TABLE t; +Table Create Table +t CREATE TABLE `t` ( + `name` varchar(256) DEFAULT NULL, + FULLTEXT KEY `ft_index` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci +############# +# 4. Cleanup +############# +DROP TABLE t; +UNINSTALL PLUGIN simple_parser; \ No newline at end of file diff --git a/mysql-test/t/bug110976.test b/mysql-test/t/bug110976.test new file mode 100644 index 00000000000..0404efe36b5 --- /dev/null +++ b/mysql-test/t/bug110976.test @@ -0,0 +1,45 @@ +INSTALL PLUGIN simple_parser SONAME 'mypluglib.so'; + +--echo ##################################################################### +--echo # 1. Prepare a table with a full-text index with default parser. +--echo ##################################################################### +CREATE TABLE t (name varchar(256), FULLTEXT KEY ft_index (name)) ENGINE = InnoDB; + +--echo # full-text index should have no ngram parser. +SHOW CREATE TABLE t; + +--echo ################################################################################################# +--echo # 2. Modify full-text index from default parser to ngram parser in a DDL statement by inplace DDL +--echo ################################################################################################# +ALTER TABLE t +DROP INDEX ft_index , +ADD FULLTEXT INDEX ft_index (name) WITH PARSER ngram , algorithm = inplace; + +--echo # full-text index should have ngram parser. +SHOW CREATE TABLE t; + +--echo ################################################################################################ +--echo # 3. Modify full-text index from ngram parser to simple_parser in a DDL statement by inplace DDL +--echo ################################################################################################ +ALTER TABLE t +DROP INDEX ft_index , +ADD FULLTEXT INDEX ft_index (name) WITH PARSER simple_parser , algorithm = inplace; + +--echo # full-text index should have simple_parser. +SHOW CREATE TABLE t; + +--echo ################################################################################################## +--echo # 4. Modify full-text index from simple_parser to default parser in a DDL statement by inplace DDL +--echo ################################################################################################## +ALTER TABLE t +DROP INDEX ft_index , +ADD FULLTEXT INDEX ft_index (name), algorithm = inplace; + +--echo # full-text index should have no ngram parser. +SHOW CREATE TABLE t; + +--echo ############# +--echo # 4. Cleanup +--echo ############# +DROP TABLE t; +UNINSTALL PLUGIN simple_parser; \ No newline at end of file diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 8dea91e74cb..f51b2700c46 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -11843,6 +11843,18 @@ static bool has_index_def_changed(Alter_inplace_info *ha_alter_info, } } + /* + Check whether the fulltext parsers has been chagned. + 1. Key with parser converted to key with built-in parser. + 2. key with built-in parser converted to key with parser. + 3. Key with parser converted to key with another parser. + */ + if ((table_key->parser != nullptr && new_key->parser_name.str == nullptr) || + (table_key->parser == nullptr && new_key->parser_name.str != nullptr) || + (table_key->parser != nullptr && new_key->parser_name.str != nullptr && + strcmp(plugin_name(table_key->parser)->str, new_key->parser_name.str))) + return true; + return false; }