Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters:
- OS type:
- Others: code inspection of origin/main plus
buildBooleanQuery/Index.SearchQueryon aSimpleTokenizersegment. No cluster was running. Not [Bug]: classic fulltext BOOLEAN phrase on the ngram parser looks up the raw CJK string and misses the indexed trigrams #29271 and not the classicprefix_eq(word,'苹果香蕉')false negative: this index returns extra rows. No open issue covers a fulltext2 boolean*that keeps only the first trigram.
Actual Behavior
On a FULLTEXT2 index with parser "", "default", or "ngram", boolean mode 苹果香蕉* returns a document that does not contain 苹果香蕉. The statement succeeds.
Index.SearchQuery (pkg/fulltext2/query.go 379–384) and Index.StreamQuery (pkg/fulltext2/stream.go 245–249) both call buildBooleanQuery when boolean is true. The search TVF sets that flag from FULLTEXT_BOOLEAN (pkg/sql/colexec/table_function/fulltext2_search.go 747) and Fulltext2Search.runTopK calls SearchQuery (pkg/fulltext2/search_cache.go 342).
rawToClauseParser (pkg/fulltext2/query.go 637–678) sends a bare, non-quoted, non-star CJK operand through phraseSlots, so +苹果香蕉 is the positional pair 苹果香@0 + 果香蕉@3. The comment there says the old OR-of-ngrams path made +中文學習 match 中文學校. A trailing * is excluded by !rc.star and falls through to tokenizeToTerms + clausePrefix of terms[:1] only (677–678). tokenizeToTerms on 苹果香蕉 yields 苹果香, 果香蕉, 香蕉, 蕉. Only 苹果香 is kept.
clausePrefix (pkg/fulltext2/boolean.go 464–488) ORs every term from prefixTerms (pkg/fulltext2/termdict.go 114–133). The trigram 苹果香 is a prefix of itself, so every document that contains that trigram matches, including 苹果香瓜.
Probed with BuildSegmentFromDocs (SimpleTokenizer) and SearchQuery(..., boolean=true, BM25):
| query | clause | doc ids returned |
|---|---|---|
苹果香蕉* |
prefix 苹果香 |
1 苹果香蕉, 2 苹果香瓜, 3 苹果香蕉西瓜 |
+苹果香蕉* |
must prefix 苹果香 |
1, 2, 3 |
+苹果香蕉 |
phrase 苹果香@0, 果香蕉@3 |
1, 3 |
苹果* |
prefix 苹果 |
1, 2, 3, 4 红苹果甜 |
苹果香* |
prefix 苹果香 |
1, 2, 3 |
苹果* and 苹果香* match stored tokens whose prefix is the whole user stem. 苹果香蕉* shortens a 4-rune stem to its first 3-rune token, so doc 2 matches even though rune 4 is 瓜, not 蕉. The same three parsers all produce terms:["苹果香"]. Natural-language 苹果香蕉 (boolean=false) returns only docs 1 and 3.
SearchQuery's comment (368–371) says a word* prefix behaves as its operator. The operator is not the problem. Keeping only the first trigram drops the rest of the user's prefix.
Expected Behavior
苹果香蕉* / +苹果香蕉* should return docs 1 and 3 and should not return doc 2. The ngrams fully contained in the user prefix (苹果香 at byte 0 and 果香蕉 at byte 3) should still be required, the same slots phraseSlots already builds for the unstarred operand. Only a tail shorter than one stored token should be a prefix. A document that shares the first trigram and then diverges (苹果香瓜) should not match.
Steps to Reproduce
CREATE TABLE ft(id INT PRIMARY KEY, body VARCHAR(200));
INSERT INTO ft VALUES (1, '苹果香蕉'), (2, '苹果香瓜'), (3, '苹果香蕉西瓜'), (4, '红苹果甜');
CREATE FULLTEXT2 INDEX fi ON ft(body) WITH PARSER ngram;
SELECT id FROM ft WHERE MATCH(body) AGAINST('苹果香蕉*' IN BOOLEAN MODE);
-- returns 1, 2, and 3. Doc 2 does not contain 苹果香蕉.
SELECT id FROM ft WHERE MATCH(body) AGAINST('+苹果香蕉' IN BOOLEAN MODE);
-- returns 1 and 3.The unit probe above is Index.SearchQuery on one segment built with SimpleTokenizer, which is the tokenizer normalizeParser selects for "" / "default" / "ngram". parser = "gojieba" was not part of this probe.
Additional information
Classic fulltext has the opposite failure for the same pattern: prefix_eq(word,'苹果香蕉') matches nothing, because no stored token is 4 runes long. That is a separate issue. Fixing one side does not fix the other. SearchBooleanText / ParseBoolean is not this path; production boolean search uses buildBooleanQuery.
Activity
fix(fulltext2): keep the whole CJK stem for a BOOLEAN trailing * (mat…
fix(fulltext2): prefix-match the final Latin token of a mixed CJK/Lat…
fix(fulltext2): gojieba final-word prefix + keep single-trigram star …
fix(fulltext2): keep the whole CJK stem for a BOOLEAN trailing * (#29274
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3dmo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE原问题验证
按 issue 原始语义在上述 commit 重新执行并重复 3 次。FULLTEXT2 CJK trailing-star 查询返回 ids 1,3,并排除仅部分相似的文档。
Happy Path 覆盖
覆盖 CJK prefix、多个 parser 文档及排序。
Unhappy Path 覆盖
覆盖不存在前缀、空 term 和 NULL;无过宽命中。
白盒验证
关联修复 #29346 已进入当前
main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。回归测试
suites/14_issue_regression/t/issue_recent_fulltext_contracts.test714/714条语句通过。测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3d14_issue_regression中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。测试结论
测试通过。