Skip to content

Commit 5484c73

Browse files
Andrzej Jarzabekzmur
authored andcommitted
Bug#37039354 Backport Bug#36559642 FTS cleanup on DROP INDEX issue when adding a FULLTEXT index in same transaction
Cause: When all FULLTEXT indexes are dropped from a table, but another one is added in the same transaction using INPLACE algorithm, the logic for dropping the last FULLTEXT index performs cleanup on the assumption that the in-memeory and on-disk FTS infrastructure is not needed any more. Because of the way the INPLACE algorithm works, creation of said infrastructure for the index being added and related checks will have already been done at this point - the index is already added but not yet published (the in-memory fts_t structure is not updated) and thus not detected. This leaves the infrastructure in an inconsistent state, leading to incorrect behavior. Fix: When dropping a FULLTEXT index, do not perform the cleanup if another FULLTEXT index is to be added in the same transaction. Change-Id: Iceed9f4c755d2cd44d2cf7b301fc0f3a18a521cc
1 parent f034c38 commit 5484c73

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

storage/innobase/fts/fts0fts.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,17 +812,21 @@ fts_drop_index(
812812
/*===========*/
813813
dict_table_t* table, /*!< in: Table where indexes are dropped */
814814
dict_index_t* index, /*!< in: Index to be dropped */
815-
trx_t* trx) /*!< in: Transaction for the drop */
815+
trx_t* trx, /*!< in: Transaction for the drop */
816+
bool adding_another) /*! in: Another FTS index is to be
817+
added as part of the same
818+
transaction */
816819
{
817820
ib_vector_t* indexes = table->fts->indexes;
818821
dberr_t err = DB_SUCCESS;
819822

820823
ut_a(indexes);
821824

822-
if ((ib_vector_size(indexes) == 1
825+
const bool last_index = (ib_vector_size(indexes) == 1
823826
&& (index == static_cast<dict_index_t*>(
824827
ib_vector_getp(table->fts->indexes, 0))))
825-
|| ib_vector_is_empty(indexes)) {
828+
|| ib_vector_is_empty(indexes);
829+
if (last_index && !adding_another) {
826830
doc_id_t current_doc_id;
827831
doc_id_t first_doc_id;
828832

storage/innobase/handler/handler0alter.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2005, 2023, Oracle and/or its affiliates.
3+
Copyright (c) 2005, 2024, Oracle and/or its affiliates.
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License, version 2.0,
@@ -8019,12 +8019,17 @@ commit_cache_norebuild(
80198019
}
80208020
}
80218021

8022+
bool adding_fts_index = false;
8023+
80228024
for (ulint i = 0; i < ctx->num_to_add_index; i++) {
80238025
dict_index_t* index = ctx->add_index[i];
80248026
assert(dict_index_get_online_status(index)
80258027
== ONLINE_INDEX_COMPLETE);
80268028
assert(!index->is_committed());
80278029
index->set_committed(true);
8030+
if (index->type & DICT_FTS) {
8031+
adding_fts_index = true;
8032+
}
80288033
}
80298034

80308035
if (ctx->num_to_drop_index) {
@@ -8071,7 +8076,7 @@ commit_cache_norebuild(
80718076
|| (index->type
80728077
& DICT_CORRUPT));
80738078
assert(index->table->fts);
8074-
fts_drop_index(index->table, index, trx);
8079+
fts_drop_index(index->table, index, trx, adding_fts_index);
80758080
}
80768081

80778082
dict_index_remove_from_cache(index->table, index);
@@ -8858,9 +8863,6 @@ ha_innobase::commit_inplace_alter_table(
88588863

88598864
if (index->type & DICT_FTS) {
88608865
assert(index->type == DICT_FTS);
8861-
/* We reset DICT_TF2_FTS here because the bit
8862-
is left unset when a drop proceeds the add. */
8863-
DICT_TF2_FLAG_SET(ctx->new_table, DICT_TF2_FTS);
88648866
fts_add_index(index, ctx->new_table);
88658867
}
88668868
}

storage/innobase/include/fts0fts.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2011, 2023, Oracle and/or its affiliates.
3+
Copyright (c) 2011, 2024, Oracle and/or its affiliates.
44
55
This program is free software; you can redistribute it and/or modify
66
it under the terms of the GNU General Public License, version 2.0,
@@ -1047,7 +1047,10 @@ fts_drop_index(
10471047
/*===========*/
10481048
dict_table_t* table, /*!< in: Table where indexes are dropped */
10491049
dict_index_t* index, /*!< in: Index to be dropped */
1050-
trx_t* trx); /*!< in: Transaction for the drop */
1050+
trx_t* trx, /*!< in: Transaction for the drop */
1051+
bool adding_another = false); /*!< in: Another FTS index is
1052+
to be added as part of
1053+
the same transaction */
10511054

10521055
/****************************************************************//**
10531056
Rename auxiliary tables for all fts index for a table

0 commit comments

Comments
 (0)