Repository navigation
Description
Description
For a table with a valid Fulltext2 index, a top-level MATCH() AGAINST() query succeeds, as do IN subquery and derived-table forms. The identical indexed predicate inside a scalar subquery fails with error 20105 instead of returning the scalar result.
Environment
- Branch:
main - Commit:
33af6ae3c0c23e4f277137460577ea64678f7ecf - Deployment: isolated local single-CN MatrixOne service
- Date: 2026-09-01
Steps to reproduce
CREATE DATABASE ft2_scalar_subquery;
USE ft2_scalar_subquery;
SET experimental_fulltext2_index = 1;
CREATE TABLE docs(id BIGINT PRIMARY KEY, body TEXT);
INSERT INTO docs VALUES (1, 'ready token');
CREATE FULLTEXT2 INDEX ft ON docs(body);
-- controls: each returns 1
SELECT id FROM docs WHERE MATCH(body) AGAINST('ready');
SELECT id FROM docs
WHERE id IN (SELECT id FROM docs WHERE MATCH(body) AGAINST('ready'));
SELECT id FROM (SELECT id FROM docs WHERE MATCH(body) AGAINST('ready')) q;
-- fails
SELECT (
SELECT COUNT(*) FROM docs WHERE MATCH(body) AGAINST('ready')
) AS scalar_count;Actual behavior
The scalar-subquery statement is rejected:
ERROR 20105 (HY000): not supported: MATCH() AGAINST() function cannot be replaced by FULLTEXT INDEX and full table scan with fulltext search is not supported yet.
Expected behavior
Because docs.body has a usable Fulltext2 index and the same predicate is accepted in the control query shapes, the scalar subquery should return 1 rather than reaching the unsupported full-scan implementation.
Stability and controls
- Reproducer: 3/3 independent indexed databases failed identically.
- Top-level control: 3/3 returned row
1. INsubquery control: 3/3 returned row1.- Derived-table control: 3/3 returned row
1. - Failure atomicity: after the rejected scalar statement, the source table still had one row,
mo_indexeshad two Fulltext2 metadata rows, andmo_index_updatehad onefulltext2_reindexrow. No data or metadata was modified. - An additional immediate-read probe ran 10/10 successfully for top-level
MATCH; this is not an index-build readiness issue.
Code analysis
The error originates from the fallback implementations in pkg/sql/plan/function/func_fulltext.go, which intentionally return 20105 when the planner does not replace MATCH with an index-backed operator. The observed controls show that Fulltext2 rewrite works for top-level, IN subquery, and derived-table shapes. The scalar-subquery plan appears to leave the MATCH expression unreplaced; this is an inference from the behavior and the fallback location.
Regression coverage
After a fix, add a Fulltext2 distributed regression covering the scalar COUNT(*) subquery plus the direct, IN, and derived controls, with an EXPLAIN assertion that the indexed form uses fulltext2_search.
Related
- Related but not duplicate: [Bug]: MATCH in an IN subquery is not rewritten to fulltext_index_scan #25891 fixed classic Fulltext
MATCHin anINsubquery. This issue concerns Fulltext2 and only the scalar-subquery shape; itsINcontrol already works.
Activity
fix(plan/fulltext): rewrite MATCH in scalar subqueries to the fulltex…
fix(plan/fulltext): pick join-child by null-extension contract, not a…
fix(plan/fulltext): rewrite MATCH in scalar subqueries to the fulltex…
Ariznawlll commentedon Sep 3, 2026
测试版本
main17c161a31b47a22e71ca222839143f66717ac365原问题验证
原问题是在存在可用 Fulltext2 索引时,
MATCH ... AGAINST位于 scalar subquery 内未被改写,错误返回 20105。当前 main 上使用docs(id, body)和FULLTEXT2(body)按原步骤执行,scalarCOUNT(*)返回1,不再报 20105。Happy Path 覆盖
同一张表、同一个 Fulltext2 索引覆盖以下四种形态,结果均正确:
id = 1。IN (subquery):返回id = 1。id = 1。SELECT COUNT(*) ... MATCH ...:返回scalar_count = 1。Unhappy Path 覆盖
ERROR 20105(没有可用索引时不支持 full scan)。count(*) = 1,连接继续可用(select 1返回1)。scalar_count = 1,确认连接和查询可恢复。白盒验证
本次验证对应修复提交
0db2d5ea9a(Fulltext2 scalar-subquery index rewrite,合入为 #28011)。修复在 scalar subquery 展平后的 AGG 入口补充 Fulltext2 索引改写;四种查询形态和无索引 20105 对照结果符合预期。回归测试
已加入 MOTR:
motr#141,测试文件suites/14_issue_regression/t/issue_27962_fulltext2_scalar_subquery.test。20/20statements passed。3/3通过(每轮20/20)。测试证据
MOTR 三轮总计:
6个 case 执行成功,129/129statements 通过。每轮均执行四种 Happy 查询、删除索引后的 20105 Unhappy 校验、源数据/连接存活检查、重建索引后的恢复查询和清理。最新 main 已修复 #27962 描述的问题,Happy/Unhappy 场景均通过;黑盒回归已加入 MOTR,不需要 big-data、stability 或 chaos 专项。
测试结论
测试通过。
fix(plan/fulltext): rewrite MATCH in scalar subqueries to the fulltex…
fix(plan/fulltext): rewrite MATCH in scalar subqueries to the fulltex…
fix(plan/fulltext): rewrite MATCH in scalar subqueries to the fulltex…