Repository navigation
MDEV-41757 Phrase search misses rows of a FULLTEXT index built over rows with an empty string in an earlier indexed column - #5979
Open
futureweb wants to merge 1 commit into
Conversation
…ows with an empty string in an earlier indexed column When a FULLTEXT index is built over existing rows, row_merge_fts_doc_tokenize() moves the start position of the next field by the length of the field plus one byte, also for a field that holds an empty string. fts_init_recover_doc(), which adds the rows that were not synced to the cache again after a crash, does the same. Rows added to an existing index (fts_fetch_doc_from_rec(), fts_fetch_doc_from_tuple()) and phrase search (fts_query_fetch_document()) skip an empty field, as they skip a NULL. So the words after an empty field were stored one byte too far, and phrase search, which starts to match at the stored position, did not find the row. An empty field no longer moves the position. Indexes built before this fix keep the wrong positions until they are rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
futureweb
marked this pull request as ready for review
October 24, 2026 18:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a FULLTEXT index is built over existing rows, row_merge_fts_doc_tokenize() moves the start position of the next field by the length of the field plus one byte, also for a field that holds an empty string. fts_init_recover_doc(), which adds the rows that were not synced to the cache again after a crash, does the same. Rows added to an existing index (fts_fetch_doc_from_rec(), fts_fetch_doc_from_tuple()) and phrase search (fts_query_fetch_document()) skip an empty field, as they skip a NULL. So the words after an empty field were stored one byte too far, and phrase search, which starts to match at the stored position, did not find the row.
Before:
After: 1, 2, 3, 4.
Fix: an empty field no longer moves the position, in both functions.
Notes for reviewers:
Found with a random test for the ngram parser proposed in MDEV-10267.
Release Notes
Phrase searches in an InnoDB FULLTEXT index on several columns no longer miss rows in which an earlier indexed column holds an empty string, when the index was built over existing rows or the rows were added to the index again after a crash. Indexes built before the fix must be rebuilt, for example with ALTER TABLE ... FORCE.
How can this PR be tested?
New cases in
innodb_fts.phrase(an index built over rows with NULL, '' and ' ' in the first or second column, with the positions from INNODB_FT_INDEX_TABLE) andinnodb_fts.crash_recovery(rows that are only in the FTS cache when the server is killed). Without the fix, the phrase search ininnodb_fts.phrasemisses rows 3 and 4 (empty title), and the one ininnodb_fts.crash_recoverymisses row 1 after the restart.The
innodb_ftssuite and themainfulltext tests pass on 11.4 (debug build). On main with all our fixes and the ngram parser of MDEV-10267, theinnodb_fts,mariaandpluginssuites and themainfulltext, plugin and alter tests pass.Basing the PR against the correct MariaDB version
PR quality check
🤖 Generated with Claude Code