Skip to content

[Bug]: Fulltext2 MATCH in scalar subquery is not rewritten and returns 20105 #27962

Closed

Description

@Ariznawlll

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.
  • IN subquery control: 3/3 returned row 1.
  • Derived-table control: 3/3 returned row 1.
  • Failure atomicity: after the rejected scalar statement, the source table still had one row, mo_indexes had two Fulltext2 metadata rows, and mo_index_update had one fulltext2_reindex row. 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

Activity

  1. added this to the MO-202609 milestone on Sep 1, 2026
  2. added
    kind/bug
    on Sep 1, 2026
  3. added
    severity/s0
    and removed on Sep 1, 2026
  4. Ariznawlll commented on Sep 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • Commit:17c161a31b47a22e71ca222839143f66717ac365
    • 环境:本地最新 main,单 CN / 单 TN(isolated local single-CN/single-TN)
    • 日期:2026-09-03

    原问题验证

    原问题是在存在可用 Fulltext2 索引时,MATCH ... AGAINST 位于 scalar subquery 内未被改写,错误返回 20105。当前 main 上使用 docs(id, body) 和 FULLTEXT2(body) 按原步骤执行,scalar COUNT(*) 返回 1,不再报 20105。

    Happy Path 覆盖

    同一张表、同一个 Fulltext2 索引覆盖以下四种形态,结果均正确:

    • 顶层 MATCH:返回 id = 1。
    • IN (subquery):返回 id = 1。
    • derived table:返回 id = 1。
    • scalar subquery SELECT COUNT(*) ... MATCH ...:返回 scalar_count = 1。

    Unhappy Path 覆盖

    • 删除 Fulltext2 索引后执行 scalar 查询,按预期返回 ERROR 20105(没有可用索引时不支持 full scan)。
    • 错误后源表仍为 count(*) = 1,连接继续可用(select 1 返回 1)。
    • 重建索引并等待异步维护 10 秒后再次执行 scalar 查询,仍返回 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。

    • MOTR 单次:20/20 statements passed。
    • MOTR 重复 3 轮:3/3 通过(每轮 20/20)。

    测试证据

    MOTR 三轮总计:6 个 case 执行成功,129/129 statements 通过。每轮均执行四种 Happy 查询、删除索引后的 20105 Unhappy 校验、源数据/连接存活检查、重建索引后的恢复查询和清理。

    最新 main 已修复 #27962 描述的问题,Happy/Unhappy 场景均通过;黑盒回归已加入 MOTR,不需要 big-data、stability 或 chaos 专项。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions