Skip to content

Commit 990cde8

Browse files
Thirunarayanandr-m
authored andcommitted
MDEV-28912 NON-UNIQUE FTS_DOC_ID index mistaken as FTS_DOC_ID_INDEX
- InnoDB mistakenly identifies the non-unique FTS_DOC_ID index as FTS_DOC_ID_INDEX while loading the table. dict_load_indexes() should check whether the index is unique before assigning fts_doc_id_index
1 parent 7c35ad1 commit 990cde8

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

mysql-test/suite/innodb_fts/r/fulltext2.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,10 @@ fts_doc_id first_name last_name score
271271
6 Ned Flanders 0
272272
7 Nelson Muntz 0
273273
DROP TABLE t1;
274+
CREATE TABLE t1(a INT, b TEXT, FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
275+
KEY FTS_DOC_ID_INDEX(FTS_DOC_ID))ENGINE=InnoDB;
276+
ALTER TABLE t1 ADD COLUMN c INT as (a) VIRTUAL;
277+
ALTER TABLE t1 ADD d INT NULL;
278+
ALTER TABLE t1 ADD FULLTEXT(b);
279+
ERROR HY000: Index 'FTS_DOC_ID_INDEX' is of wrong type for an InnoDB FULLTEXT index
280+
DROP TABLE t1;

mysql-test/suite/innodb_fts/t/fulltext2.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,14 @@ INSERT INTO t1 (id, first_name, last_name) VALUES
257257
analyze table t1;
258258
SELECT fts_doc_id, first_name, last_name, MATCH(first_name) AGAINST('Homer' IN BOOLEAN MODE) AS score FROM t1;
259259
DROP TABLE t1;
260+
261+
#
262+
# MDEV-28912 NON-UNIQUE FTS_DOC_ID mistaken as FTS_DOC_ID_INDEX
263+
#
264+
CREATE TABLE t1(a INT, b TEXT, FTS_DOC_ID BIGINT UNSIGNED NOT NULL,
265+
KEY FTS_DOC_ID_INDEX(FTS_DOC_ID))ENGINE=InnoDB;
266+
ALTER TABLE t1 ADD COLUMN c INT as (a) VIRTUAL;
267+
ALTER TABLE t1 ADD d INT NULL;
268+
--error ER_INNODB_FT_WRONG_DOCID_INDEX
269+
ALTER TABLE t1 ADD FULLTEXT(b);
270+
DROP TABLE t1;

storage/innobase/dict/dict0load.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2590,8 +2590,11 @@ dict_load_indexes(
25902590
ut_ad(table->fts_doc_id_index == NULL);
25912591

25922592
if (table->fts != NULL) {
2593-
table->fts_doc_id_index = dict_table_get_index_on_name(
2593+
dict_index_t *idx = dict_table_get_index_on_name(
25942594
table, FTS_DOC_ID_INDEX_NAME);
2595+
if (idx && dict_index_is_unique(idx)) {
2596+
table->fts_doc_id_index = idx;
2597+
}
25952598
}
25962599

25972600
/* If the table contains FTS indexes, populate table->fts->indexes */

0 commit comments

Comments
 (0)