Repository navigation
expression, planner: evaluate MATCH ... AGAINST IN BOOLEAN MODE in TiDB - #73086
terry1purcell wants to merge 9 commits into
Conversation
|
Skipping CI for Draft Pull Request. |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
cda4e3b to
fcaaa66
Compare
…ysis Add the parsing and analysis a FULLTEXT search needs, with no SQL behaviour change yet: - pkg/expression/matchagainst parses IN BOOLEAN MODE search strings for the STANDARD and NGRAM parsers, following MySQL's operator grammar. - pkg/expression/fulltext tokenizes documents the way InnoDB's built-in and ngram parsers do (token size bounds, the default stopword list, ngram positions), and compiles a boolean search into a query that can match a document. - innodb_ft_min_token_size, innodb_ft_max_token_size and ngram_token_size become real global variables, bounded as in MySQL, so the analyzer reads them; they were read-only placeholders. - model.FullTextParserTypeNgramV1 names the NGRAM parser. This is the first part of splitting pingcap#71531 (FULLTEXT index in TiKV) into staged PRs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oken-size bounds - NGRAM positions: a word too short to yield a gram left no gap when an earlier word had more grams than words, so the distance between the grams around it depended on the preceding text. A phrase such as "gh x ij" then missed a document containing it, and "gh ij" matched it. Positions now come from a running counter: one per gram start, and one per word too short for a gram. - STANDARD parser: a quote left open now runs to the end of the search string, and a newline no longer ends it, as in the NGRAM parser. It was an error, so a stray quote failed the statement under one parser and not the other. - innodb_ft_min_token_size and innodb_ft_max_token_size are validated against each other. Their ranges overlap, and a minimum above the maximum made the STANDARD analyzer drop every token, so every search silently matched nothing. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… operators
- A required term that is a stopword or outside the token-size bounds
made the whole search match nothing, while the same term without '+'
was ignored. It is now dropped, as MySQL transforms '+word +stopword'
into '+word'; a search left with no positive term still matches
nothing.
- '~', '<' and '>' were errors. In MySQL they only change a word's
contribution to the relevance, and MATCH is evaluated here as a filter
without a score, so the word after them is optional. '(' ')' and '@'
stay unsupported.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
8b94b63 to
1df94b4
Compare
…equired term UsesPrefixPostings reported a prefix anywhere in the query, including an optional one in a group with a required child, whose postings are never read. It now follows the lists PostingReads names. Also document the two exported NGRAM parsing errors separately. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1df94b4 to
3696b05
Compare
…GRAM delimiter A word of Hindi, Thai or vocalized Arabic holds a combining mark, a vowel sign or a virama, between most of its letters. The tokenizer took only letters, numbers and '_' as word characters, so it split such a word at every mark, into single letters that the STANDARD analyzer then dropped as too short. Marks are now word characters, in the analyzer and in the NGRAM search-string scanner, which must agree with it. The NGRAM scanner follows MySQL's fts_get_word, which an index WITH PARSER ngram is searched through: a prefix operator counts only after a space, the last of several wins, and a stray one is skipped. '@' is no operator there, only a delimiter, so it no longer fails the statement and an address can be searched for. Also remove code no search string can reach: - the NGRAM parser's parenthesized groups, which its scanner rejects first, and with them ErrUnmatchedLeftParen and ErrUnmatchedRightParen; - BooleanGroup as a clause expression, BooleanTerm.Ignored and BooleanPhrase.Distance, which no parser sets; - the STANDARD scanner's NUM token, which only followed the '@' the parser rejects, and the commented-out parseGroupClause. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2ad01b8 to
4724c7c
Compare
…ted token sizes - In an NGRAM boolean search, '>', '<' and '~' after a space are consumed as operators, as MySQL's scanner does, so '+>apple' stays required and '->apple' excluded instead of both becoming optional. - The analyzer refuses innodb_ft_min_token_size above innodb_ft_max_token_size when it reads them. Each SET checks the other variable, but concurrent updates, or updates between the two reads, can still give such a pair, and the STANDARD analyzer would then drop every token and match nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4724c7c to
257634f
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add tidb_enable_local_match_against (default OFF). When it is on, a MATCH ... AGAINST ... IN BOOLEAN MODE in a filter position (WHERE, ON, HAVING, under NOT or parentheses) is evaluated in TiDB with the analyzer and boolean query from pkg/expression/fulltext, instead of erroring without a columnar index or being approximated by the ILIKE fallback. - The analyzer settings are resolved from the session at plan time and frozen into the builtin, so every row is tokenized the same way; plans that use them skip the plan cache. The switch is part of the plan cache key, so a plan built with it off is not reused with it on. - A constant search string is compiled at plan time, so syntax errors surface even when no row reaches the filter, and a query that matches nothing is known to the estimator. Any other search string is compiled per value at execution. - The search modifier and the place of evaluation are part of the builtin's hash codes and equality, so a BOOLEAN MODE search and a natural-language one over the same column and string stay two predicates. - Natural-language mode, query expansion and scoring positions (SELECT list, ORDER BY, comparisons) keep the existing behaviour: a 0/1 result is never substituted for a relevance score. - The estimator uses one analyzed term as its ILIKE proxy, and the cost model charges a locally evaluated MATCH by document size. - Column substitution keeps the planner state on the builtin by cloning it, and a local MATCH is never pushed to TiFlash. This is part 2 of splitting pingcap#71531 (FULLTEXT index in TiKV) into staged PRs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Building a subquery set the plan builder's current clause for its own clauses and left it there, so the rest of the enclosing expression, and the next select-list item, ran as if in the subquery's last clause. A local MATCH after such a subquery was then misclassified: in the select list it was evaluated as a 0/1 filter instead of refused as a score, and in WHERE it was refused although it is a filter. buildSubquery now restores the clause, as it already restores the window specs and the subquery context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6cf5d1c to
7f6e4b7
Compare
What problem does this PR solve?
Issue Number: ref #70491
Problem Summary:
Depends on #73085 (part 1). Until it merges, this PR also shows its commit; review only the top commit,
expression, planner: evaluate MATCH ... AGAINST IN BOOLEAN MODE in TiDB.This is part 2 of 6 of splitting #71531 (FULLTEXT index in TiKV) into staged PRs:
MATCH ... AGAINSTevaluation without an index (this PR)ADMIN CHECK, with creation behind a switch (ddl, table, executor: build a FULLTEXT index in TiKV behind a switch #73088)On the classic kernel,
MATCH ... AGAINSTwithout a columnar index either errors or, with alternative logical plans, is approximated by ILIKE, which cannot honour word boundaries, stopwords, token-size limits, prefixes or phrases.What changed and how does it work?
New variable
tidb_enable_local_match_against(defaultOFF). When it is on, aMATCH ... AGAINST ... IN BOOLEAN MODEin a filter position (WHERE, ON, HAVING, under NOT or parentheses) is evaluated in TiDB with the analyzer and boolean query from part 1.?marker is compiled per search string at execution.Check List
Tests
Side effects
Documentation
Release note
🤖 Generated with Claude Code