You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: fulltext index: MATCH() AGAINST() function cannot be replaced by FULLTEXT INDEX and full table scan with fulltext search is not supported yet. #20687
场景一:
drop table if exists articles;
drop table if exists authors;
create table articles (
id int auto_increment primary key,
title varchar(255),
content text,
author_id int,
fulltext(content)
);
create table authors (
id int auto_increment primary key,
name varchar(100)
);
insert into authors (name) values ('John Doe'), ('Jane Smith'), ('Alice Johnson');
insert into articles (title, content, author_id) values
('MO全文索引入门', 'MO全文索引是一种强大的工具,可以帮助你快速检索数据库中的文本数据。', 1),
('深入理解全文索引', '全文索引不仅可以提高搜索效率,还可以通过JOIN操作与其他表结合使用。', 2),
('MO性能优化', '本文将探讨如何优化MO数据库的性能,包括索引优化和查询优化。', 3),
('全文索引与JOIN操作', '全文索引可以与JOIN操作结合使用,以实现跨表的全文搜索。', 1);
select * from articles;
select * from authors;
select a.title, a.content, au.name
from articles a
join authors au on a.author_id = au.id
where match(a.content) against ('MO' IN NATURAL LANGUAGE MODE);
场景2:
drop table if exists posts;
drop table if exists comments;
create table posts (
post_id int auto_increment primary key,
title varchar(255),
content text
);
create table comments (
comment_id int auto_increment primary key,
post_id int,
comment_text text,
foreign key (post_id) references posts(post_id)
);
alter table posts add fulltext(content);
insert into posts (title, content) values
('MO全文索引入门', 'MO全文索引是一种强大的工具,可以帮助你快速检索数据库中的文本数据。'),
('深入理解全文索引', '全文索引不仅可以提高搜索效率,还可以通过JOIN操作与其他表结合使用。');
insert into comments (post_id, comment_text) values
(1, '这篇文章很有用,谢谢分享!'),
(1, '我也在学习全文索引,很有帮助。'),
(2, '全文索引真的很强大,学习了。');
select count(posts.title), count(comments.comment_id) as comment_count
from posts
left join comments on posts.post_id = comments.post_id
where match(posts.content) against ('全文索引' IN NATURAL LANGUAGE MODE)
group by posts.post_id;
在固定 main commit 01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90 上补充多 MATCH 布尔组合范围。
同一张表分别在 title、body 建立两个全文索引后:
-- 可执行,返回两个命中集合的交集WHERE MATCH(title) AGAINST('+alpha'INBOOLEAN MODE)
AND MATCH(body) AGAINST('+beta'INBOOLEAN MODE)
-- 20105WHERE MATCH(title) AGAINST('+alpha'INBOOLEAN MODE)
OR MATCH(body) AGAINST('+beta'INBOOLEAN MODE)
-- 20105WHERE MATCH(title) AGAINST('+alpha'INBOOLEAN MODE)
AND NOT MATCH(body) AGAINST('+beta'INBOOLEAN MODE)
NOT (MATCH(...) OR MATCH(...)) 以及 ((MATCH(...) AND id<... ) OR (MATCH(...) AND id>...)) 也返回相同 20105。classic FULLTEXT 与 FULLTEXT2、两个 CN 的行为一致;而 AND 形态会生成两个全文检索流并返回正确交集。
Verdict: the 20105 rejection is correct and intentional (WAI), not an unfixed bug
The behavior is a documented, deliberate design decision, not a path someone forgot to close. Two spots in
pkg/sql/plan/apply_indices_fulltext.go state it explicitly:
collectDrivingFullTextMatches (line 2217) only descends through and and membership-implying comparisons (>c, >=c). It returns
unchanged for or/not, so a MATCH nested in OR/NOT is never harvested → the raw fulltext_match survives to execution → the
fulltext.go:1189 guard fires 20105. The code comments give the reason:
line 2290: "AND-reachable only. Under an OR or a NOT the predicate does not have to hold for a returned row, so the engine
must not drop anything on its account."
line 2484: "The stream a driver builds is INNER JOINed to the base scan, which ANDs 'this document is in the index result'
onto the query; harvesting a MATCH out of an OR or a NOT would impose a restriction the query never asked for."
Why it's architecturally correct, not a gap
MO has no full-table-scan fulltext fallback — by design. The 20105 message itself says so. Every MATCH must be driven by the
index.
The driver is an INNER JOIN of the index-result stream onto the base scan → inherently conjunctive. That's exactly why MATCH
AND MATCH works (two inner joins), and why the tester confirms AND is fine.
OR would need a UNION-of-streams rewrite; NOT / AND-NOT would need anti-join semantics against the entire base (the index
enumerates matches, not non-matches). Neither exists. Forcing a MATCH from inside OR/NOT into the join model would silently
change semantics (return wrong rows). Returning 20105 is the safe choice over returning wrong results.
Recommendation
Reject the OR/NOT complaint as WAI — the original issue (single MATCH over JOIN, scenario 1/2) was genuinely fixed by #29069;
what remains is the intentional refusal. Distinguish two sub-cases when replying to the tester:
NOT / NOT(OR) / top-level negation: architecturally un-driveable (index yields matches, not non-matches, and there's no scan
fallback). This is a permanent limitation, not a bug.
OR-of-MATCHes (and MATCH OR predicate): semantically well-defined and MySQL-supports it, but it needs a new union-based
driver rewrite MO doesn't have, plus resolves undefined score semantics on the non-match branch. That's a feature request, not
a defect in the current path — track it separately rather than reopening this bug.
Net: the tester's "测试不通过" observation is factually right that OR/NOT return 20105, but that 20105 is the designed, safe
behavior. I'd close the bug as WAI and, if OR support is wanted, file it as a scoped feature (union-driver) rather than keep it
as an S0 bug on the existing rewrite.
commit:529ee099e32ed8c38d2806043bf1516ab0345e45(复测后确认仍是远端 main HEAD)
部署方式:本地单 CN,以及 1 Log / 1 TN / 2 CN 拓扑
测试日期:2026-10-03
原问题验证
按 issue 中的建表和数据,分别复测两个原始场景,各连续执行 3 轮:
articles 与 authors 的 INNER JOIN,在 WHERE 中用 MATCH(a.content) AGAINST('MO' IN NATURAL LANGUAGE MODE) 过滤:3/3 返回两条预期文章(MO全文索引入门 / John Doe、MO性能优化 / Alice Johnson),EXPLAIN 包含 fulltext_index_scan。
posts 与 comments 的 LEFT JOIN,以 MATCH(posts.content) AGAINST('全文索引' IN NATURAL LANGUAGE MODE) 过滤并按 post 分组:3/3 返回 (post_id, comment_count)=(1,2),(2,1);另加一条匹配全文条件、但没有评论的 post,得到 (post_id, comment_count)=(新增ID,0),确认保留侧和 NULL 扩展语义。计划同样包含 fulltext_index_scan。
Activity
1 remaining item
fix(plan): serve fulltext MATCH on the preserved side of an outer join (
Ariznawlll commentedon Sep 18, 2026
在固定
maincommit01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90上补充多MATCH布尔组合范围。同一张表分别在
title、body建立两个全文索引后:NOT (MATCH(...) OR MATCH(...))以及((MATCH(...) AND id<... ) OR (MATCH(...) AND id>...))也返回相同 20105。classic FULLTEXT 与 FULLTEXT2、两个 CN 的行为一致;而AND形态会生成两个全文检索流并返回正确交集。在同表同时存在 IVFFLAT、查询按向量距离分页时,
AND形态可同时生成两个fulltext2_search和一个Vector Index Scan,结果与精确路径一致。OR/NOT 的 20105 在移除向量排序后仍存在,因此根因是全文谓词布尔改写不覆盖析取/否定,不是向量候选合并。fix(plan): rewrite MATCH beneath a window operator and OUTER JOIN to …
Ariznawlll commentedon Sep 22, 2026
@cpegeric 当前验证仍存在未修复路径,转回研发继续处理。
测试版本
main3727c5c5436ca136d7b0312f75bc223a11692a85原问题验证
关联修复 #29069 合入后,OUTER JOIN 与窗口算子上的 MATCH 路径已经改善;但原 issue 下补充的多 MATCH 布尔组合仍未闭环。两个全文索引分别建在
title、body后,MATCH(title) AND MATCH(body)可执行,而 OR/NOT 组合仍稳定返回ERROR 20105。Happy Path 覆盖
MATCH ... AGAINST可正确使用全文索引并返回命中行。Unhappy Path 覆盖
MATCH(title) ... OR MATCH(body) ...返回ERROR 20105。MATCH(title) ... AND NOT MATCH(body) ...返回ERROR 20105。NOT (MATCH(...) OR MATCH(...))返回ERROR 20105。ERROR 20105。白盒验证
本轮未增加内部注入。失败由公开 SQL 稳定触发,范围集中在全文谓词对析取和否定表达式的 planner 改写,使用黑盒计划与结果即可直接判定。
回归测试
当前产品行为仍失败,未把错误结果固化为 MOTR baseline。修复后回归需要覆盖 OR、AND NOT、外层 NOT,以及 classic FULLTEXT/FULLTEXT2 两条路径。
测试证据
main复测结果:OR/NOT 路径仍返回ERROR 20105。测试结论
测试不通过。
cpegeric commentedon Sep 24, 2026
Verdict: the 20105 rejection is correct and intentional (WAI), not an unfixed bug
The behavior is a documented, deliberate design decision, not a path someone forgot to close. Two spots in
pkg/sql/plan/apply_indices_fulltext.go state it explicitly:
collectDrivingFullTextMatches (line 2217) only descends through and and membership-implying comparisons (>c, >=c). It returns
unchanged for or/not, so a MATCH nested in OR/NOT is never harvested → the raw fulltext_match survives to execution → the
fulltext.go:1189 guard fires 20105. The code comments give the reason:
must not drop anything on its account."
onto the query; harvesting a MATCH out of an OR or a NOT would impose a restriction the query never asked for."
Why it's architecturally correct, not a gap
index.
AND MATCH works (two inner joins), and why the tester confirms AND is fine.
enumerates matches, not non-matches). Neither exists. Forcing a MATCH from inside OR/NOT into the join model would silently
change semantics (return wrong rows). Returning 20105 is the safe choice over returning wrong results.
Recommendation
Reject the OR/NOT complaint as WAI — the original issue (single MATCH over JOIN, scenario 1/2) was genuinely fixed by #29069;
what remains is the intentional refusal. Distinguish two sub-cases when replying to the tester:
fallback). This is a permanent limitation, not a bug.
driver rewrite MO doesn't have, plus resolves undefined score semantics on the non-match branch. That's a feature request, not
a defect in the current path — track it separately rather than reopening this bug.
Net: the tester's "测试不通过" observation is factually right that OR/NOT return 20105, but that 20105 is the designed, safe
behavior. I'd close the bug as WAI and, if OR support is wanted, file it as a scoped feature (union-driver) rather than keep it
as an S0 bug on the existing rewrite.
fix(plan): drive fulltext MATCH under ANTI/MARK joins on the preserve…
Ariznawlll commentedon Oct 3, 2026
测试版本
main529ee099e32ed8c38d2806043bf1516ab0345e45(复测后确认仍是远端mainHEAD)原问题验证
按 issue 中的建表和数据,分别复测两个原始场景,各连续执行 3 轮:
articles与authors的INNER JOIN,在WHERE中用MATCH(a.content) AGAINST('MO' IN NATURAL LANGUAGE MODE)过滤:3/3 返回两条预期文章(MO全文索引入门/ John Doe、MO性能优化/ Alice Johnson),EXPLAIN包含fulltext_index_scan。posts与comments的LEFT JOIN,以MATCH(posts.content) AGAINST('全文索引' IN NATURAL LANGUAGE MODE)过滤并按 post 分组:3/3 返回(post_id, comment_count)=(1,2),(2,1);另加一条匹配全文条件、但没有评论的 post,得到(post_id, comment_count)=(新增ID,0),确认保留侧和 NULL 扩展语义。计划同样包含fulltext_index_scan。上述结果在单 CN 和双 CN 环境一致。原始的单
MATCH/ JOIN 故障已由 #29069 修复,本轮未再复现。已支持路径覆盖
MATCH ... AGAINST过滤与 JOIN/聚合组合返回预期行集;LEFT JOIN 的无匹配评论行未丢失。设计限制路径覆盖
WHERE MATCH(content) AGAINST('MO' IN NATURAL LANGUAGE MODE) OR author_id=2返回ERROR 20105。WHERE NOT MATCH(content) AGAINST('MO' IN NATURAL LANGUAGE MODE)返回ERROR 20105。INNER JOIN驱动,不能安全地把OR/NOT中的MATCH强制作为合取过滤;目前没有 OR 的并集驱动、NOT 的反连接或全文全表扫描回退。20105 是有意保留的安全拒绝,不是原 JOIN 缺陷未修复。此前对 classic FULLTEXT / FULLTEXT2 的多MATCHOR/NOT 在双 CN 上也记录了相同结果。白盒验证
本轮未新增内部注入或
-race测试;原始问题和当前限制均可由公开 SQL、实际行集及执行计划直接判断。研发已在上述评论中指出限制对应的 planner 收集与执行 guard 代码路径。回归测试
原 JOIN 路径的产品修复见 #29069。
OR/NOT是现有设计限制,不将ERROR 20105写成新的 MOTR 正确性预期;如需支持 OR,应另立 Feature 定义并集驱动和非命中分支分数语义。测试证据
MATCH布尔组合验证记录。MATCH不支持位于OR/NOT谓词分支(提交d7f40e3)。测试结论
测试通过。