Repository navigation
Closed
Closed
Copy link
Labels
kind/bugSomething isn't workingseverity/s0Active / top priority for current sprint. Owner has committed to working on it now.
Milestone
Description
问题
全文索引能够为 WHERE MATCH(...) AGAINST(...) 建立 fulltext_index_scan,但同一个 MATCH 分数一旦直接出现在聚合表达式中,优化器没有把它替换成索引扫描产生的 score 列。以下查询因此在执行期报错 20105:
select max(match(body) against('hello'))
from docs where match(body) against('hello');
select group_concat(match(body) against('hello') order by id separator '|')
from docs where match(body) against('hello');
select group_concat(id order by match(body) against('hello') desc, id separator '|')
from docs where match(body) against('hello');错误为:
ERROR 20105 (HY000): MATCH() AGAINST() function cannot be replaced by FULLTEXT INDEX and full table scan with fulltext search is not supported yet
这不是索引不可用:相同过滤条件下直接投影 score 正常,GROUP_CONCAT(id ...) 正常,EXPLAIN 也显示 fulltext_index_scan 已建立。将 score 先放入 CTE,再由外层聚合,同样可以得到正确结果。
环境
- MatrixOne: official
main065a67528608c475d0219e0be6b7d454a58f7b1a - 拓扑:本地 2 CN / 1 TN / 1 LogService
experimental_fulltext_index=1- 复现次数:上述三种聚合形态分别 3/3
最小复现
set experimental_fulltext_index = 1;
drop database if exists ft_agg_repro;
create database ft_agg_repro;
use ft_agg_repro;
create table docs(id int primary key, body text);
insert into docs values
(1, 'hello world'),
(2, 'foo bar'),
(3, 'hello hello again'),
(4, 'world only'),
(5, 'hello matrix one'),
(6, null);
create fulltext index ft_body on docs(body);
select max(match(body) against('hello'))
from docs where match(body) against('hello');对照
select group_concat(id order by id separator '|')
from docs where match(body) against('hello');
-- 1|3|5
with hits as (
select id, match(body) against('hello') score
from docs where match(body) against('hello')
)
select max(score), group_concat(id order by score desc, id separator '|')
from hits;
-- 0.09843373 3|1|5MySQL 8.3 对三种直接聚合写法均可执行;按 score 排序的结果同为 3|1|5。
代码定位
applyIndicesForAggUsingFullTextIndex 调用 applyJoinFullTextIndices 后只把聚合节点的 child 改为新 join,未使用返回的 served 映射遍历和改写 aggNode.AggList。因此计划中仍然保留:
Aggregate Functions: max(fulltext_match('hello', 0, docs.body))
现有 TestFullTextGroupedAggregateWithOrderByUsesIndex 只验证 WHERE MATCH 上方的普通 COUNT(*),没有覆盖 MATCH 本身作为聚合参数或聚合内部排序键。
Metadata
Metadata
Assignees
Labels
kind/bugSomething isn't workingseverity/s0Active / top priority for current sprint. Owner has committed to working on it now.
Activity
Ariznawlll commentedon Sep 11, 2026
在更新后的 official
mainee0c2bf563bf27ff2c80891bb57a1de5886bf90b(本地 2 CN / 1 TN / 1 LogService)复核:MAX(MATCH(...)):3/3 返回 20105;GROUP_CONCAT(MATCH(...) ORDER BY id):3/3 返回 20105;GROUP_CONCAT(id ORDER BY MATCH(...) DESC):3/3 返回 20105;0.09843373和3|1|5;EXPLAIN仍把fulltext_match(...)留在Aggregate Functions内,而索引扫描已经出现在聚合子树中,说明问题仍是聚合表达式列表未使用 score 映射,不是索引未就绪。fix(fulltext): rewrite MATCH inside aggregate expressions to the inde…
cpegeric commentedon Sep 14, 2026
please verify
Ariznawlll commentedon Sep 15, 2026
测试版本
main:0c3a04f390adaf6281fd592a49778ea5b1155e67原问题验证
验证
MATCH位于聚合参数和ORDER BY时均被正确改写为 score,不再残留未改写表达式。Happy Path 覆盖
覆盖 FULLTEXT 表、聚合内 MATCH、分组与按 score 排序。
Unhappy Path 覆盖
覆盖聚合表达式嵌套与多文档结果,确认不会报 planner/执行错误。
白盒验证
TestFullTextAggMatchRewrittenToScore在pkg/sql/plan连续 3 次通过。回归测试
已加入 MOTR:
issue_28681_fulltext_aggregate_match,见 motr#176。测试证据
定向 plan UT 3/3 通过;新增 MOTR 用例连续 3 轮通过。
测试结论
测试通过。
fix(fulltext): rewrite MATCH inside aggregate expressions to the inde…
fix(fulltext): rewrite MATCH inside aggregate expressions to the inde…
fix(fulltext): rewrite MATCH inside aggregate expressions to the inde…
fix(plan): rewrite MATCH beneath a window operator and OUTER JOIN to …
fix(plan): drive fulltext index from an aggregate MATCH proven presen…