Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Actual Behavior
A natural-language / default MATCH ... AGAINST whose pattern is shorter than 3 runes does not lowercase the pattern. The query returns empty even though the indexed documents contain that word.
Indexed Latin tokens are stored lowercased. SimpleTokenizer.outputLatin (pkg/monlp/tokenizer/simple.go) calls strings.ToLower before the token is written. Boolean mode lowercases the whole pattern in ParsePattern before it parses. A natural-language pattern of 3 or more runes also goes through SimpleTokenizer, so AGAINST('HIGH') matches high.
The short-pattern branch does not. ParsePattern (pkg/fulltext/fulltext.go) calls ParsePatternInNLMode with the original string. When len([]rune(pattern)) < 3, that function returns a STAR of the raw pattern and never tokenizes it:
if len(runeSlice) < ngram_size {
return []*Pattern{{Text: pattern + "*", Operator: STAR}}, nil
}PatternToSql then emits prefix_eq(word, '<raw>') (pkg/fulltext/sql.go). prefix_eq is case-sensitive, so Hi* does not match the stored token high or hi.
Reproduced on a local v1.3.0 build (309dbd8df6ff2c2fd675b13da891ec5f3bca222e). ParsePattern / ParsePatternInNLMode on that commit are the same as origin/main 66da3877e9e77f01083c4aac0cb9f94ab6e11fe6.
CREATE DATABASE ft_case;
CREATE TABLE ft_case.c (id INT PRIMARY KEY, body VARCHAR(64));
CREATE FULLTEXT INDEX fc ON ft_case.c (body);
INSERT INTO ft_case.c VALUES
(1, 'high'), (2, 'HI'), (3, 'pineapple'), (4, 'apple'), (5, 'Abyss');| AGAINST | rows |
|---|---|
'hi' |
1 high, 2 HI |
'Hi' |
empty |
'HI' |
empty |
'ab' |
5 Abyss |
'Ab' |
empty |
'AB' |
empty |
'HIGH' |
1 high |
'+HI' IN BOOLEAN MODE |
1 high, 2 HI |
'+Hi*' IN BOOLEAN MODE |
1 high, 2 HI |
Hi / HI / Ab / AB are successful empty results. The documents are indexed; only the capitalised short pattern misses them.
Expected Behavior
AGAINST('Hi') and AGAINST('HI') return the same rows as AGAINST('hi'). AGAINST('Ab') and AGAINST('AB') return the same row as AGAINST('ab').
The short-pattern prefix rule itself is unchanged: hi matching high is the existing < 3 rune prefix search. A 3-rune pattern such as hig stays an exact token and does not match high. Boolean mode already folds case, so +HI and +Hi* are not part of this bug.
Steps to Reproduce
CREATE DATABASE ft_case;
CREATE TABLE ft_case.c (id INT PRIMARY KEY, body VARCHAR(64));
CREATE FULLTEXT INDEX fc ON ft_case.c (body);
INSERT INTO ft_case.c VALUES (1, 'high'), (2, 'HI'), (5, 'Abyss');
SELECT id, body FROM ft_case.c WHERE MATCH(body) AGAINST('hi');
SELECT id, body FROM ft_case.c WHERE MATCH(body) AGAINST('Hi');
SELECT id, body FROM ft_case.c WHERE MATCH(body) AGAINST('HI');
SELECT id, body FROM ft_case.c WHERE MATCH(body) AGAINST('ab');
SELECT id, body FROM ft_case.c WHERE MATCH(body) AGAINST('Ab');The lowercase queries return the rows above. Hi, HI, and Ab return empty.
Additional information
ParsePattern lowercases only the boolean arm:
case int64(tree.FULLTEXT_NL), int64(tree.FULLTEXT_DEFAULT):
ps, err := ParsePatternInNLMode(pattern, parser)
case int64(tree.FULLTEXT_BOOLEAN):
lowerp := strings.ToLower(pattern)
ps, err := ParsePatternInBooleanMode(lowerp, parser)The same short-circuit is what makes AGAINST('-5') look up the raw prefix -5 instead of the indexed token 5. That case is the breaker-plus-short-prefix rule, not this bug. This report is only the missing ToLower on a < 3 rune natural-language pattern.
Activity
fix(fulltext): match short-query case folding to the index parser (ma…
fix(fulltext): lowercase a <3-rune NL pattern before the prefix search (
Ariznawlll commentedon Oct 2, 2026
测试版本
maind50a2d475a406829f67127fef7b2ad4abc1c1d3dmo-service,独立数据目录;MySQL 文本协议与 server-side PREPARE原问题验证
按 issue 原始语义在上述 commit 重新执行并重复 3 次。classic fulltext 大小写折叠后返回 ids 1,2,AB 查询命中 id 3。
Happy Path 覆盖
覆盖 BOOLEAN/NATURAL 查询、大小写和短 token。
Unhappy Path 覆盖
覆盖不存在 token、空查询和 NULL;无多余文档命中。
白盒验证
关联修复 #29354 已进入当前
main。同时将本 issue 的可公开观察契约固化为独立回归,避免只依赖实现细节或共享测试间接判断。回归测试
suites/14_issue_regression/t/issue_recent_fulltext_contracts.test714/714条语句通过。测试证据
d50a2d475a406829f67127fef7b2ad4abc1c1d3d14_issue_regression中观察到的旧 GOROOT/历史 golden/并发锁冲突属于既有无关失败,以上新增用例单独重跑均稳定通过。测试结论
测试通过。
[4.2-dev] fix(fulltext): lowercase a <3-rune NL pattern before the pr…