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. No open issue covers this. Closed [Bug] Chinese ngram fulltext natural-language multi-term query returns 0 rows (appears fixed on main) #24820 is the opposite symptom (space-separated natural-language query returned 0 rows on 3.0.11, fixed on main). Closed [Feature Request]: Use NLP word breaker in fulltext query. #21774 is a feature request for an optional NLP breaker and says the 3-gram breaker is used at query time, which is true for natural-language mode and for unquoted boolean terms, not for a quoted boolean phrase.
Actual Behavior
On a classic FULLTEXT index whose parser is "", "default", or "ngram", MATCH(col) AGAINST('"..."' IN BOOLEAN MODE) returns no rows for a CJK phrase the column contains. The statement succeeds.
The index stores SimpleTokenizer tokens (pkg/sql/colexec/table_function/fulltext_tokenize.go 138–195, pkg/monlp/tokenizer/simple.go outputCJK 179–206): sliding 3-rune windows plus the shorter tail of the run. "红苹果甜" is stored as 红苹果@0, 苹果甜@3, 果甜@6, 甜@9. "苹果香蕉" is stored as 苹果香@0, 果香蕉@3, 香蕉@6, 蕉@9. The whole phrase is never one word.
A quoted boolean pattern does not use that tokenizer. ParsePatternInBooleanMode (pkg/fulltext/fulltext.go 734–741) calls ParsePhrase. For every parser other than gojieba, ParsePhrase (662–689) only splits on spaces, so "苹果香蕉" becomes one TEXT child 苹果香蕉 and "苹果" becomes one TEXT child 苹果. patternToSql ( pkg/fulltext/sql.go 579–581) then sends a PHRASE node straight to SqlPhrase, which emits:
SELECT doc_id, CAST(0 as int) FROM <index> WHERE word = '苹果香蕉' GROUP BY doc_id
SELECT doc_id, CAST(0 as int) FROM <index> WHERE word = '苹果' GROUP BY doc_idNeither literal is an indexed word, so the scan is empty. This SQL is what the planner precompiles (pkg/sql/plan/apply_indices_fulltext.go 698–707 → getFullTextIndexScanSql, pkg/sql/plan/fulltext.go 153–161) and what fulltext_index_scan runs again (pkg/sql/colexec/table_function/fulltext.go runWordStats 475–476).
The unquoted boolean term and natural-language mode already expand CJK through GenTextSql (sql.go 168–188) → ParsePatternInNLMode. On the same inputs that produces prefix_eq(word,'苹果') and the positional pair word = '苹果香' at anchor 0 with word = '果香蕉' at anchor+3. Those hit the rows above. parser = "gojieba" is also unaffected: parsePhraseJieba segments the quote. CREATE FULLTEXT2 INDEX does not use this SQL; ngramPhraseSlots (pkg/fulltext2/query.go 473–528) builds the shifted trigrams.
Expected Behavior
A quoted boolean phrase on the default/ngram parser should be decomposed the same way GenTextSql decomposes an unquoted boolean term, then matched with the positions SqlPhrase already applies. "苹果香蕉" should return the row whose body is 苹果香蕉. "苹果" should return the row whose body is 红苹果甜.
Steps to Reproduce
CREATE TABLE ft(id INT PRIMARY KEY, body VARCHAR(200));
INSERT INTO ft VALUES (1, '苹果香蕉'), (2, '红苹果甜');
CREATE FULLTEXT INDEX fi ON ft(body) WITH PARSER ngram;
SELECT id FROM ft WHERE MATCH(body) AGAINST('"苹果香蕉"' IN BOOLEAN MODE);
-- success, 0 rows. Row 1 contains the phrase.
SELECT id FROM ft WHERE MATCH(body) AGAINST('"苹果"' IN BOOLEAN MODE);
-- success, 0 rows. Row 2 contains 苹果. Indexed words are 红苹果 / 苹果甜 / 果甜 / 甜.
-- same parser, these already hit:
SELECT id FROM ft WHERE MATCH(body) AGAINST('苹果香蕉' IN NATURAL LANGUAGE MODE); -- id 1
SELECT id FROM ft WHERE MATCH(body) AGAINST('+苹果香蕉' IN BOOLEAN MODE); -- id 1
SELECT id FROM ft WHERE MATCH(body) AGAINST('+苹果' IN BOOLEAN MODE); -- id 2The same word = '<whole phrase>' SQL is produced for parser "" and "default". A phrase of 1, 2, or more than 3 CJK characters without spaces is the broken shape. A phrase of exactly 3 CJK characters happens to equal one stored trigram, so that single lookup can hit.
Additional information
TestPatternToSqlGojiebaPhrase (pkg/fulltext/jieba_test.go 136–156) already treats word = '我来到北京' as the bug for gojieba and only pins the whitespace split for an English phrase (TestParsePhraseWhitespaceParserUnchanged). GenTextSql's comment says a Chinese boolean term must be tokenized into ngrams; the quoted-phrase branch never calls it.
Activity
Ariznawlll commentedon Sep 23, 2026
Same path also skips
SimpleTokenizerfor a Latin word longer than 23 bytes. A CJK-only ngram split of the quoted text would still miss this.outputLatin(pkg/monlp/tokenizer/simple.go144–164) stores at mostMAX_TOKEN_SIZE(23) bytes. A 26-byte run ofbis indexed as 23bs.ParsePhrase(662–689) only splits on spaces for every parser other thangojieba, andpatternToSql(579–581) sends thatPHRASEtoSqlPhraseas rawword =.ParsePattern+PatternToSqlon this tree:bs, parserngram:WHERE word = 'bbbbbbbbbbbbbbbbbbbbbbb'(23). Matches the index.bs, parserngram, and+the same word, parserdefault: the same 23-byteword =."bbbbbbbbbbbbbbbbbbbbbbbbbb", parserngram:WHERE word = 'bbbbbbbbbbbbbbbbbbbbbbbbbb' GROUP BY doc_id(26). Empty scan."hello bbbbbbbbbbbbbbbbbbbbbbbbbb", parser"": second anchor isword = 'bbbbbbbbbbbbbbbbbbbbbbbbbb'atpos - 6. Empty.hello+ the 26-byte word, parserngram: second word is the 23-byte token atpos - 6. Matches.parsePhraseJiebaalready tokenizes the quote, and jieba truncates to 23 bytes, sogojiebais not this case. The quoted text on""/default/ngramneedsSimpleTokenizer: CJK trigram split and the 23-byte Latin cut.This is still classic
SqlPhrase, not the fulltext2ngramPhraseSlotsmiss (filed separately).Ariznawlll commentedon Sep 23, 2026
Same
ParsePhrasepath also misses hyphen and apostrophe, whichSimpleTokenizersplits at index time.ParsePhrase(pkg/fulltext/fulltext.go662–689) splits a whole-string quoted pattern only on spaces for every parser other thangojieba.SqlPhrasethen looks the pieces up with rawword =. Index build runsSimpleTokenizer, andisBreakerRunetreats both-and'as breakers:full-text searchis stored asfull@0,text@5,search@10.AGAINST('"full-text search"' IN BOOLEAN MODE)looks upword = 'full-text'andword = 'search'. No row matches.Ma'trix Originis stored asma@0,trix@3,origin@8.AGAINST('"Ma'\''trix Origin"' IN BOOLEAN MODE)looks upword = 'ma'\''trix'. No row matches.Unquoted natural-language
Ma'trix Origindoes go throughSimpleTokenizerand is not this miss. This is the same raw-lookup hole as the CJK trigram case and the >23-byte Latin case above, so it stays on this issue.A quote that does not wrap the entire boolean string never becomes a PHRASE node at all. That false positive is #29289, not this one.
fix(fulltext): tokenize a quoted BOOLEAN phrase like the index (matri…
fix(fulltext): keep json_value phrases whole; sync fulltext2 phrase t…
fix(fulltext): tokenize short phrases before exact-vs-prefix classifi…
fix(fulltext): tokenize original phrase bytes before case folding (ma…
fix(fulltext): matrixorigin#29271 P2 keep original token type/span di…
fix(tokenizer): matrixorigin#29271 P2 cap folded Latin token so case …
fix(fulltext2): matrixorigin#29271 P2 sync query reader with the fold…
perf(tokenizer): matrixorigin#29271 P2 avoid a per-token heap allocat…
perf(tokenizer): matrixorigin#29271 P2 add an all-ASCII fast path to …
fix(fulltext): tokenize a quoted BOOLEAN phrase like the index (#29271)…
Ariznawlll commentedon Oct 8, 2026
测试版本
MatrixOne 最新 main
1a0088790c8823bd3fe824ad9ff2ef1ce130eb31;本地独立数据目录、单 CN/TN 服务;MOTR PR #218 已推送,Python 3.10/3.12/3.13 与 Go 离线检查均通过。原问题验证
classic FULLTEXT ngram 的引号 BOOLEAN 短语现在命中实际索引词,不再将中文整串当作未入索引的原始词查找。
正常场景覆盖
"苹果香蕉"命中 id=1;短词"苹果"命中 1/2/6;自然语言与未引号 BOOLEAN 对照保持正确。边界与异常场景覆盖
连字符
full-text、撇号Ma'trix与超过 23 字节的 Latin 词均命中各自目标,不误命中旁支文档。白盒验证
现有 MatrixOne BVT
test/distributed/cases/fulltext/fulltext_boolean_phrase_ngram.sql覆盖更完整的混合文字、大小写折叠、容量边界;此前按 golden 3/3 通过。回归测试
新增 MOTR
14_issue_regression.issue_29271_fulltext_boolean_phrase_ngram,3/3 通过(16 条语句/轮)。测试证据
MOTR PR #218 的 SQL/golden,6 行文档及命中 id 可复核。
测试结论
测试通过。