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
ParsePattern/PatternToSql/SimpleTokenizeron that tree. No cluster was running. Not the same bug as [Bug]: classic fulltext BOOLEAN phrase on the ngram parser looks up the raw CJK string and misses the indexed trigrams #29271 (quoted boolean phrase emitsword = '<raw CJK>'; this is the unquoted trailing-*form and emitsprefix_eq). Closed [Bug]: fulltext index search 'string*' in boolean mode is not correct. #20958 is a different repro (每日图片/2009年8月*contains/); it was closed because the punctuation-strippedLIKEwas also empty. Closed [Bug] Chinese ngram fulltext natural-language multi-term query returns 0 rows (appears fixed on main) #24820 is space-separated natural-language mode on 3.0.11, fixed on main.
Actual Behavior
On a classic FULLTEXT index, boolean mode with a trailing * on a CJK stem of 4 or more runes returns no rows for a document that contains that stem. The statement succeeds.
CreatePattern (pkg/fulltext/fulltext.go 637–642) turns a token whose last rune is * into STAR and keeps the whole token, including the *, as Text. SqlBoolean only dispatches to GenSql (pkg/fulltext/sql.go 379). The non-TEXT branch (sql.go 327–332, and the JOIN form at 359–366) strips one trailing * and emits prefix_eq of whatever remains. It does not call GenTextSql / ParsePatternInNLMode. The same strip-and-prefix_eq is in GenJoinPlusSql (216–223) and SqlPhrase (477–489, 517–522).
Probed with NewSearchAccum + PatternToSql for parsers "", "ngram", "default", and "gojieba":
苹果香蕉* -> prefix_eq(word,'苹果香蕉')
+苹果香蕉* -> prefix_eq(word,'苹果香蕉')
苹果香蕉西瓜* -> prefix_eq(word,'苹果香蕉西瓜')
SimpleTokenizer.outputCJK (pkg/monlp/tokenizer/simple.go 179–206) stores a sliding 3-rune window plus the shorter tail. "苹果香蕉" is stored as 苹果香, 果香蕉, 香蕉, 蕉. None of those words has the prefix 苹果香蕉, so the scan is empty. "苹果香蕉西瓜" is stored as 苹果香, 果香蕉, 香蕉西, 蕉西瓜, 西瓜, 瓜, which also does not match prefix_eq(word,'苹果香蕉西瓜').
The same operand without * already hits. +苹果香蕉 goes through GenTextSql (sql.go 168–188) and, for the ngram parser, becomes the positional pair word = '苹果香' at anchor 0 with word = '果香蕉' at anchor+3. For gojieba it becomes word = '苹果' with word = '香蕉'. Adding * drops that expansion and looks up a string longer than any stored token.
A stem of at most 3 runes can still hit, because the prefix is itself a stored token or a prefix of one: 苹果* is prefix_eq(word,'苹果') and 苹果香* is prefix_eq(word,'苹果香'). TestSqlBoolean (pkg/fulltext/sql_test.go 132–154) already locks the English whole-token form (Origin* → prefix_eq(word,'origin')) and the unstarred 4-rune CJK form (+读写汉字 → the two trigrams). It does not cover a 4-rune CJK star.
This SQL is what the planner precompiles (pkg/sql/plan/fulltext.go getFullTextIndexScanSql 153–161) and what fulltext_index_scan runs (pkg/sql/colexec/table_function/fulltext.go runWordStats 475–476).
Expected Behavior
A trailing * should not make a stem that already matches disappear. 苹果香蕉* / +苹果香蕉* should return the row whose body is 苹果香蕉 or 苹果香蕉西瓜, the same rows +苹果香蕉 returns, and should also return a longer body that continues past that stem. The ngram/default path should expand the stem the way GenTextSql does, and only the part that is actually a prefix of a stored token should be prefix_eq. gojieba should segment first and then apply * to the last segment, instead of prefix_eq of the raw 4-rune string.
Steps to Reproduce
CREATE TABLE ft(id INT PRIMARY KEY, body VARCHAR(200));
INSERT INTO ft VALUES (1, '苹果香蕉'), (2, '苹果香蕉西瓜'), (3, '苹果香瓜');
CREATE FULLTEXT INDEX fi ON ft(body) WITH PARSER ngram;
SELECT id FROM ft WHERE MATCH(body) AGAINST('苹果香蕉*' IN BOOLEAN MODE);
-- success, 0 rows. Rows 1 and 2 contain the stem.
SELECT id FROM ft WHERE MATCH(body) AGAINST('+苹果香蕉*' IN BOOLEAN MODE);
-- success, 0 rows.
SELECT id FROM ft WHERE MATCH(body) AGAINST('+苹果香蕉' IN BOOLEAN MODE);
-- id 1 and 2.
SELECT id FROM ft WHERE MATCH(body) AGAINST('苹果*' IN BOOLEAN MODE);
-- id 1, 2, and 3. A 2-rune prefix still hits the stored trigram 苹果香.The same prefix_eq(word,'苹果香蕉') SQL is produced for parser "", "default", and "gojieba". On gojieba, +苹果香蕉 without * is word = '苹果' AND word = '香蕉'; with * it is still prefix_eq(word,'苹果香蕉').
Additional information
MySQL's ngram parser documents that boolean * is not a word-prefix operator. This is not a request to copy that. MatrixOne already implements * as prefix_eq against stored tokens (+提效 in TestSqlBoolean, English Origin*). For a stem longer than the stored token, that predicate cannot hit the document that contains the stem, while the same operand without * can. #29271 is the quoted form (word = '苹果香蕉'); fixing the phrase branch does not fix STAR.
Activity
Ariznawlll commentedon Sep 23, 2026
Same
STARpath also drops a Latin word longer than 23 bytes.SimpleTokenizer.outputLatin(pkg/monlp/tokenizer/simple.go144–177) stores one token, the first 23 bytes, lowercased. A 26-byte run ofbis indexed asbbbbbbbbbbbbbbbbbbbbbbb(23).gojiebatruncates to the sameMAX_TOKEN_SIZE(pkg/monlp/tokenizer/jieba.go174).NewSearchAccum+PatternToSqlon the four classic parsers ("",ngram,default,gojieba):prefix_eqisbytes.HasPrefix(pkg/sql/plan/function/func_prefix.go). A stored 23-byte token cannot have a 24- or 26-byte prefix, so the scan succeeds and returns no rows for a document that contains the word. A stem of exactly 23 bytes still hits:++ 23b+*isprefix_eq(word,'bbbbbbbbbbbbbbbbbbbbbbb').TestSqlBooleanlocksOrigin*(shorter than 23). It does not lock this cut.A fix that only ngram-expands a 4+ rune CJK stem still leaves this Latin case on the raw-stem
prefix_eq. The expected behavior already says only the part that is actually a prefix of a stored token should beprefix_eq. That has to include the 23-byte Latin cut, on all four parsers, not only the CJK trigram split.test(fulltext): cover star-phrase SQL-gen sites to clear the diff-cov…
fix(fulltext): keep star expansion/prefix-cap parser-aware for json_v…
fix(fulltext): star prefix must reproduce outputLatin's exact truncat…
fix(fulltext): expand BOOLEAN trailing-star CJK stem to a positional …
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3dmo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE原问题验证
按 issue 原始语义在上述 commit 重新执行并重复 3 次。classic BOOLEAN 的 4+ rune CJK stem 加
*返回 ids 6,7,使用索引后的 trigram/prefix 语义正确。Happy Path 覆盖
覆盖 CJK 长 stem、前缀匹配和 direct control。
Unhappy Path 覆盖
覆盖不存在前缀、超长 Latin token、空
*;不匹配全表。白盒验证
关联修复 #29366 已进入当前
main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。回归测试
suites/14_issue_regression/t/issue_recent_fulltext_contracts.test714/714条语句通过。测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3d*返回 ids 6,7,使用索引后的 trigram/prefix 语义正确。14_issue_regression中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。测试结论
测试通过。