Repository navigation
Conversation
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
The change fulfills the formal preliminary review criteria, hence I'm approving it.
Stay tuned for the final review. One clarification question below.
| --source include/have_sequence.inc | ||
| --source include/not_embedded.inc | ||
|
|
||
| # MDEV-37370 fts_phrase_or_proximity_search() is quadratic instead of linear |
There was a problem hiding this comment.
AFAIU, it seems that you have two fixes:
- the performance improvement
- the fix for out of order IDs indexing and update of the memory cache around these.
Correct me if I'm wrong, but I do not think the two are related and can be tested in isolation.
Your tests here seem to be testing the latter.
I guess proper testing for the former claim would also be needed. In your description you mention some performance results it seems. Please share (preferably in the jira itself) how can one go about testing the performance: setup, driver etc. Preferably with the old parser so that we don't compare apples to oranges. This will be needed by our testing team.
There was a problem hiding this comment.
They're related in one direction. For each candidate document from the first match list, the old scan went through the other lists from their start, and with a list that isn't sorted by document ID it could already miss documents – that's the out-of-order part of the test, which fails on 11.4 without the patch. The cursors never go back, so with unsorted lists they would miss more; sorting first is what makes them safe. So the sort fixes wrong results on its own, and the cursors depend on it. If you prefer, I'll split it into two commits – the sort first, then the cursors – or file the wrong results as a separate MDEV.
And yes, the test checks results only – I've reworded its header to say so. The out-of-order part needs the sort, and the patterns before it (gaps between document IDs, repeated words, lists that end early, data in the cache and on disk) check that the cursors don't skip matches. For the performance, I've put a benchmark with the built-in parser into MDEV-37370: the setup, the queries and the times on 11.4 with and without the patch.
b50e9c9 to
e3cb4b5
Compare
|
FYI: According to our development cycle we work on bugs In the following periods 15 Mar-30 Apr, 15 Jun-30 Jul, 15 Sep-30 Oct and 15 Dec-31 Jan. So, please, expect to get a review somewhere between these two dates and the goal is to have your PR merged before the second date |
Thirunarayanan
left a comment
There was a problem hiding this comment.
OK to push after addressing the comment
| GROUP BY pattern ORDER BY pattern; | ||
|
|
||
| SELECT pattern, COUNT(*) AS matches FROM t1 | ||
| WHERE MATCH(body) AGAINST ('"alpha absent"' IN BOOLEAN MODE) |
There was a problem hiding this comment.
I don't think it hits the changed code at all.
There was a problem hiding this comment.
Right: when a word of the phrase has no match, fts_query_phrase_search() returns before it calls fts_phrase_or_proximity_search(). I removed that query. To check the others, I ran the test with a debug print in fts_phrase_or_proximity_search(): every remaining query of this test case reaches it, and the two out-of-order cases also sort (the first match list in the first case, the second one in the second).
| @@ -0,0 +1,147 @@ | |||
| --source include/have_innodb.inc | |||
There was a problem hiding this comment.
Can we add the test case in existing test ? (innodb_fts_proximity.test in innodb_fts suite)
There was a problem hiding this comment.
Done: the test case is now at the end of innodb_fts_proximity.test, and phrase_proximity_order is removed. Since innodb_fts_proximity also runs with system versioning, which doesn't support TRUNCATE, the second out-of-order case now drops and recreates the table. I also rebased onto the current 11.4.
gkodinov
left a comment
There was a problem hiding this comment.
requesting changes to follow up on the last request
…inear Retain a cursor for each word instead of restarting its match-list scan for every document. Matching ordered lists is linear in their lengths for a fixed number of query tokens. Cache nodes and overlapping disk posting lists can produce unsorted match lists, where the old scan could miss documents. Check each list and sort it by document ID only when needed before using the cursors. Keep ib_vector_t, phrase filtering and proximity verification. Cover gaps, repeated words, list exhaustion, disk/cache data and out-of-order commits with unsorted first and second match lists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
e3cb4b5 to
bb3f3c2
Compare
Description
fts_phrase_or_proximity_search() scanned the match list of every other query word from the start again for each document of the first word (see the removed FIXME). As in the fix for MySQL Bug #37682648 (MySQL 8.0.43), without its boilerplate, each word keeps a cursor into its match list, so matching sorted lists is linear in their lengths for a fixed number of query words. As suggested in the Jira issue, ib_vector_t is kept and there is no Vector_wrapper. The template parameter for the query mode is not part of this change.
The match lists are not always sorted by document ID: cache nodes and overlapping posting lists on disk can produce unsorted lists. With such lists the old scan could already miss documents. For example, after two transactions committed out of document ID order, alpha has the list 10 and bravo the list 30, 10; the scan for bravo stops at 30, and
'"alpha bravo"'misses document 10. So each list is checked once and sorted by document ID with std::sort() if it is not sorted, before the cursors are used.Benchmark (release build of main with all our fixes, the ngram parser proposed in MDEV-10267 with n=2, 20,000 Latin documents, boolean mode queries in which each query word becomes a phrase of n-grams): 37.2 s without this commit, 10.1 s with it, with the same number of hits (1,076,673). MySQL 8.4.13 takes 9.5 s on the same data. A CJK corpus, which has short match lists, is unchanged.
Note for reviewers: the Jira issue has Fix Version 11.8 and is assigned to Thirunarayanan. This PR is based on 11.4 because the sort also fixes wrong results there. If you prefer 11.8, I will rebase it.
Release Notes
InnoDB fulltext phrase and proximity searches are faster for words that occur in many rows. They also no longer miss rows in some cases after transactions were committed out of document ID order.
How can this PR be tested?
New test case in
innodb_fts.innodb_fts_proximity: phrase and proximity searches with gaps between document IDs, repeated words, lists that end early, data in the cache and on disk, and two out-of-order commits that give an unsorted first and an unsorted second match list. Without the fix, the phrase and proximity queries miss document 10 after the out-of-order commit.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