Skip to content

[Bug]: DISTINCT with ORDER BY prevents MATCH from using fulltext index #25890

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

c838d312d7bd2f69c22a9c189d36dfde7a3dc307

Other Environment Information

Actual Behavior

DISTINCT with MATCH works, and ORDER BY with MATCH works, but combining DISTINCT + ORDER BY + MATCH fails:

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.

This indicates that the optimizer does not rewrite fulltext_match to fulltext_index_scan for this plan shape.

Expected Behavior

The query should use the fulltext index and return author IDs 1 and 2 in order.

Steps to Reproduce

set experimental_fulltext_index = 1;
drop database if exists ft_distinct_order;
create database ft_distinct_order;
use ft_distinct_order;
create table articles (
  id int primary key,
  title varchar(255),
  content text,
  author_id int,
  fulltext index ft_articles(title, content) with parser gojieba
);
insert into articles values
  (1, 'Database Guide', 'database search engine', 1),
  (2, 'Vector Guide', 'vector search engine', 2),
  (3, 'Transaction Guide', 'database transaction engine', 1),
  (4, 'Mixed Guide', 'database vector integration', 2);

-- Works
select distinct author_id from articles
where match(title, content) against('+database' in boolean mode);

-- Fails with ERROR 20105
select distinct author_id from articles
where match(title, content) against('+database' in boolean mode)
order by author_id;

Additional information

The fulltext rewrite currently recognizes a limited set of plan shapes. The DISTINCT + ORDER BY plan leaves the scalar MATCH() expression unreplaced.

Add a deterministic regression under test/distributed/cases/fulltext/ when fixed.

Activity

  1. added theissue type on Jul 20, 2026
  2. added this to the MO-202607 milestone on Jul 20, 2026
  3. added
    ai-light
    on Sep 1, 2026
  4. Ariznawlll commented on Sep 1, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • MatrixOne main@33af6ae3c0c23e4f277137460577ea64678f7ecf
    • 1 Log / 1 TN / 2 CN / Proxy,2026-09-01

    原问题验证

    同步 gojieba FULLTEXT index 下执行原始 DISTINCT + ORDER BY + MATCH 组合,稳定返回 author_id=1,2,未再因 ORDER BY 丢失 fulltext index 绑定。

    Happy Path 覆盖

    • GROUP BY 等价控制返回同一作者集合 1,2。
    • DESC + LIMIT 返回 2,覆盖排序方向和截断。

    Unhappy Path 覆盖

    • 无匹配词返回空集。
    • 多篇文档属于同一作者时仍正确去重,不产生重复或漏行。

    白盒验证

    不适用。optimizer rewrite 的最终语义可由公开 SQL 结果直接验收。

    回归测试

    • 已加入 motr#136:issue_25890_fulltext_distinct_order.test/.result。
    • Big-data / Stability / Chaos 均不需要:回归由 query shape 触发,不依赖语料规模、异步构建或外部故障。

    测试证据

    • 作者结果集合使用 MySQL 8.3 兼容 FULLTEXT 场景独立对照。
    • MOTR 重复 3/3 轮通过,完整套件中本用例通过。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-lightarea/optimizerkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions