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
Index.SearchQuery/Index.SearchBagOfWordson 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 (classicword =SQL), not [Bug]: classic fulltext BOOLEAN trailing * on a 4+ rune CJK stem does prefix_eq of the whole stem and misses the indexed trigrams #29273 (classicprefix_eqof a CJK stem), and not [Bug]: fulltext2 BOOLEAN trailing * keeps only the first CJK trigram and matches documents that do not contain the stem #29274 (fulltext2*keeps the first trigram and returns extra rows). This search succeeds and returns no rows for a document that contains the word. No open issue covers a fulltext2 query that skips the 23-byte token cap.
Actual Behavior
On a FULLTEXT2 index with parser "", "default", or "ngram", a Latin word longer than 23 bytes is stored truncated and the natural-language, quoted-boolean, and IN BM25 MODE lookups use the untruncated string. The statement succeeds and returns no rows.
SimpleTokenizer.outputLatin (pkg/monlp/tokenizer/simple.go 144–164) keeps at most MAX_TOKEN_SIZE (23) bytes. An ASCII run longer than that is cut at byte 23. A 2-byte rune (isLatin: rune < 0x7FF, lines 77–79) backs up to the previous leading byte, so 12 Cyrillic я (24 bytes) are stored as 11 letters (22 bytes). tokenWord (pkg/fulltext2/build.go 29–34) documents that the tokenizer already truncates. A 26-byte run of b is indexed as 23 bs.
ngramPhraseSlots (pkg/fulltext2/query.go 502–508) does not apply that cap. A Latin run becomes strings.ToLower of the entire run. phraseSlots (443–459) uses ngramPhraseSlots for "" / "default" / "ngram".
Three production lookups call phraseSlots:
- Natural language.
Index.SearchQuerywithboolean=false(387–393). The TVF setsBooleanonly forFULLTEXT_BOOLEAN(pkg/sql/colexec/table_function/fulltext2_search.go747) andFulltext2Search.runTopKcallsSearchQuery(pkg/fulltext2/search_cache.go342). IN BM25 MODE.SearchBagOfWords→buildBagOfWordsQuery(402–418) builds one SHOULD term perphraseSlotsterm. The TVF setsBagOfWordsforFULLTEXT_BM25(748) andrunTopKcallsSearchBagOfWords(339–340).- Quoted boolean.
rawToClauseParser(666–676) sendsrc.quotedthroughphraseSlots. Unquoted boolean does not: it callstokenizeToTerms(654–680), which usesSimpleTokenizerand therefore hits.
Probed with buildSeg (SimpleTokenizer) and NewIndex. Documents: 1 = 26 bs, 2 = 23 as, 3 = hello + 26 bs, 4 = short. Indexed tokens of the 26-b word: ["bbbbbbbbbbbbbbbbbbbbbbb"] (23). Parsers default, ngram, and "" all printed the same rows:
| mode | query | slots | doc ids |
|---|---|---|---|
| NL | 26 bs |
the full 26-byte word | (empty). Docs 1 and 3 contain it |
| NL | 23 as |
the 23-byte word | 2 |
| boolean, bare | 26 bs |
lookup is the truncated token, not the printed slot | 1, 3 |
boolean, + |
26 bs |
same | 1, 3 |
| boolean, quoted | "…" around 26 bs |
the full 26-byte word | (empty) |
| NL | hello + 26 bs |
hello @0, full 26-byte word @6 |
(empty). Doc 3 contains it |
| boolean | +hello + 26 bs |
each operand tokenized | 3 |
| BM25 | 26 bs |
SearchBagOfWords |
(empty) |
Same root for a 2-byte rune. 12 я (24 bytes) are indexed as 11 я. phraseSlots keeps all 12. NL SearchQuery returns nothing. Unquoted boolean returns doc 9.
parser = "gojieba" is not this path. phraseSlots (452–457) tokenizes, and JiebaTokenizer truncates with truncateUTF8(..., MAX_TOKEN_SIZE) (pkg/monlp/tokenizer/jieba.go 174).
Expected Behavior
Natural-language MATCH, quoted boolean, and IN BM25 MODE should look up the same token SimpleTokenizer.outputLatin stored. A document whose body is 26 bs should be returned for that word in all three modes, the way unquoted boolean already returns it. The 23-byte query that already hits doc 2 should stay a hit. A 12-letter Cyrillic word should be looked up as the 11-letter token the index stored.
Steps to Reproduce
SET experimental_fulltext2_index = 1;
CREATE TABLE ft(id INT PRIMARY KEY, body VARCHAR(200));
INSERT INTO ft VALUES
(1, 'bbbbbbbbbbbbbbbbbbbbbbbbbb'),
(2, 'aaaaaaaaaaaaaaaaaaaaaaa'),
(3, 'hello bbbbbbbbbbbbbbbbbbbbbbbbbb');
CREATE FULLTEXT2 INDEX fi ON ft(body) WITH PARSER ngram;
-- 26 b's are indexed as the first 23. These succeed and return 0 rows.
SELECT id FROM ft WHERE MATCH(body) AGAINST('bbbbbbbbbbbbbbbbbbbbbbbbbb');
SELECT id FROM ft WHERE MATCH(body) AGAINST('bbbbbbbbbbbbbbbbbbbbbbbbbb' IN BM25 MODE);
SELECT id FROM ft WHERE MATCH(body) AGAINST('"bbbbbbbbbbbbbbbbbbbbbbbbbb"' IN BOOLEAN MODE);
SELECT id FROM ft WHERE MATCH(body) AGAINST('hello bbbbbbbbbbbbbbbbbbbbbbbbbb');
-- these hit:
SELECT id FROM ft WHERE MATCH(body) AGAINST('bbbbbbbbbbbbbbbbbbbbbbbbbb' IN BOOLEAN MODE);
SELECT id FROM ft WHERE MATCH(body) AGAINST('+bbbbbbbbbbbbbbbbbbbbbbbbbb' IN BOOLEAN MODE);
SELECT id FROM ft WHERE MATCH(body) AGAINST('aaaaaaaaaaaaaaaaaaaaaaa');The executed evidence is SearchQuery / SearchBagOfWords on one segment built with SimpleTokenizer, which is what runTopK calls after the index exists. An empty result from querying before the async build finishes is not this bug. "" and "default" take the same ngramPhraseSlots path as "ngram".
Additional information
Unquoted boolean is the control, not a second bug: tokenizeToTerms already truncates. A query that is exactly the stored 23-byte token already hits; the longer query should use that same token. #29274 is the opposite wrong result (a trailing * returns extra rows). Fixing the star path does not truncate this term.
Activity
fix(fulltext2): match query truncation to outputLatin's exact stored-…
fix(fulltext2): truncate the ngram query token to the stored-token cap (
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
按 issue 原始 SQL 在最新 main 上独立执行 3 次,结果 3/3 符合修复预期;确认修复提交
10d3a3d5f5f34e6727b14827a15879407227111a已包含在当前 main。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
核对修复提交
10d3a3d5f5f34e6727b14827a15879407227111a、对应 BVT/UT 以及当前 main 的祖先关系;本次同时完成公开 SQL 协议验收。回归测试
已加入 MOTR PR #204 的
issue_29079_29276_fulltext_query_contracts.test,MOTR 提交c7aeb11c;本地基线比对连续 3 次通过。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e测试结论
测试通过。
fix(fulltext): star prefix must reproduce outputLatin's exact truncat…