diff --git a/storage/innobase/fts/fts0que.cc b/storage/innobase/fts/fts0que.cc index ff360ea7857..607768f554a 100644 --- a/storage/innobase/fts/fts0que.cc +++ b/storage/innobase/fts/fts0que.cc @@ -3000,6 +3000,20 @@ static dberr_t fts_query_filter_doc_ids( match = static_cast(ib_vector_push(query->matched, nullptr)); + /* find the correct slot of new match */ + ut_ad(ib_vector_size(query->matched) >= 1); + ulint slot = ib_vector_size(query->matched) - 1; + while (slot >= 1) { + fts_match_t *temp_match = + static_cast(ib_vector_get(query->matched, slot - 1)); + if (doc_id >= temp_match->doc_id) { + break; + } + ib_vector_set(query->matched, slot, temp_match); + slot--; + } + match = static_cast(ib_vector_get(query->matched, slot)); + match->start = 0; match->doc_id = doc_id; heap_alloc = ib_vector_allocator(query->matched);