Skip to content

[Bug]: FULLTEXT MATCH is not rewritten beneath a window operator #28974

Closed

Description

@Ariznawlll

Branch and commit

  • Branch: main
  • Commit: d5c4e8b832ad0275766f6d8f8f0be7ec4c0fb544
  • Environment: local two-CN MatrixOne; each case was executed through both CN SQL ports.

Problem

A top-level MATCH() AGAINST() predicate can be served by a FULLTEXT or FULLTEXT2 index. Adding a normal window function to the same select prevents that rewrite. The planner leaves fulltext_match(...) on a base-table scan, and execution returns ERROR 20105 because a full table scan cannot evaluate MATCH.

This is separate from the previously closed IN-subquery case: the MATCH predicate here is directly in the query block's WHERE clause; the only additional relational operator is ROW_NUMBER().

Reproduction

SET experimental_fulltext2_index = 1;
CREATE TABLE docs (
  id BIGINT PRIMARY KEY,
  body TEXT,
  v VECF32(3),
  FULLTEXT2 ft(body) WITH PARSER ngram
);
INSERT INTO docs VALUES
  (1,'alpha','[0,0,0]'),
  (2,'beta','[0.1,0,0]'),
  (3,'alpha','[0.2,0,0]'),
  (4,'alpha','[0.3,0,0]');
ALTER TABLE docs ALTER REINDEX ft FULLTEXT2 FORCE_SYNC;

-- This returns 1,3,4.
SELECT id FROM docs
WHERE MATCH(body) AGAINST('alpha' IN BOOLEAN MODE)
ORDER BY id;

-- This is rejected with ERROR 20105.
SELECT id,
       ROW_NUMBER() OVER (ORDER BY l2_distance(v,'[0,0,0]'), id) AS rn
FROM docs
WHERE MATCH(body) AGAINST('alpha' IN BOOLEAN MODE)
ORDER BY id;

The same result occurs with classic FULLTEXT INDEX ft(body) WITH PARSER ngram, with the corresponding experimental_fulltext_index session setting.

Observed plan

Project
  -> Sort
       -> Window
            -> Table Scan on docs
                 Filter Cond: fulltext_match('alpha', 3, docs.body)

There is no fulltext2_search/fulltext_index_scan table function, so the unreplaced MATCH reaches execution and returns:

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.

Scope and controls

  • FULLTEXT2: three freshly-created databases; after synchronous reindex, direct MATCH returned 1,3,4 on both CNs; the window query returned the same 20105 on both CNs in all three runs.
  • Classic FULLTEXT: three freshly-created databases; direct MATCH returned 1,3,4 on both CNs; the window query returned the same 20105 on both CNs in all three runs.
  • Without MATCH, the same ROW_NUMBER() expression returned 1:1,2:2,3:3,4:4 on both CNs in all six databases.

Expected behavior

The MATCH predicate should still be rewritten to the available fulltext index beneath the window operator, so the query returns (1,1), (3,2), and (4,3).

Activity

  1. added
    kind/bug
    on Sep 16, 2026
  2. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    在固定的 current-main 01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90 上扩展了窗口边界,问题仍存在,并且范围不只限于原复现中的 ROW_NUMBER():

    • ROW_NUMBER() OVER (ORDER BY id)、COUNT(*) OVER()、分区 COUNT(*) OVER(PARTITION BY grp)、LAG() 均使同一查询块内的裸 WHERE MATCH(...) 留在基表扫描并返回 20105;
    • WHERE MATCH(...) > 0 的 wrapped predicate 同样不能穿过 Window 节点完成改写;
    • Window 自己按 MATCH score 排序时也返回 20105;
    • Window 位于 derived table 内部时仍是同一现象;
    • classic FULLTEXT 与 FULLTEXT2、两个 CN 的结果完全一致。

    可用的结构性对照进一步缩小了问题位置:先在内层 CTE/derived query 完成全文检索,再在外层执行 Window,可以正确返回 1,2,4,6;按 score 排序的行号也正确。因此索引内容、score 计算和 Window 算子本身均正常,缺口是同一 query block 内 Window -> Project -> Scan(MATCH) 形态没有把 MATCH 改写放到 Window 之前。

    新增覆盖的代表 SQL:

    SELECT id, COUNT(*) OVER() AS c
    FROM docs
    WHERE MATCH(body) AGAINST('alpha')
    ORDER BY id;
    
    SELECT id, LAG(id) OVER(PARTITION BY grp ORDER BY id) AS prev_id
    FROM docs
    WHERE MATCH(body) AGAINST('alpha') > 0
    ORDER BY id;
    
    WITH hits AS (
      SELECT id,grp,MATCH(body) AGAINST('alpha') AS sc
      FROM docs WHERE MATCH(body) AGAINST('alpha')
    )
    SELECT id,ROW_NUMBER() OVER(ORDER BY sc DESC,id) AS rn
    FROM hits ORDER BY id;
    -- 对照正常:1:2, 2:3, 4:4, 6:1

    这仍是 #28974 的同一 planner traversal 缺口,不另提重复 issue。该问题适合 planner UT + 小数据 SQL 回归,不需要 big-data 或 chaos。

  3. Ariznawlll commented on Sep 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 日期:2026-09-22
    • 分支:main
    • MatrixOne commit:3727c5c5436ca136d7b0312f75bc223a11692a85
    • 部署:本地单机,1 Log / 1 TN / 1 CN

    原问题验证

    在窗口算子上层使用 FULLTEXT MATCH ... AGAINST 过滤已能正确执行,不再因 MATCH 未重写到窗口算子下方而失败。

    Happy Path 覆盖

    匹配返回 id 1,3,4,row_number() 为 1,2,3,MATCH score 计算正确。

    Unhappy Path 覆盖

    覆盖无匹配文本和布尔模式过滤,确认不产生漏行、重复行或窗口序号错乱。

    白盒验证

    同时执行 classic FULLTEXT 与 fulltext2 两条实现路径,验证 MATCH 谓词和 score 穿过窗口算子的计划语义一致。

    回归测试

    新增 suites/14_issue_regression/t/issue_28974_fulltext_window_match.test,已提交至 motr#199。

    测试证据

    定向用例连续执行 3 轮;本次新增 7 个 case 共执行 21 次,结果为 21/21 通过。14_issue_regression 整套执行时该用例也通过。MOTR 当前未为该分支上报远端 checks。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions