matrixorigin / matrixorigin/matrixone

[Bug]: Fulltext2 JSON probes are never selected after the ISCP job completes

Open
#28,050 2 comments 0 reactions 1 assignee Claimed by @Ariznawlll View on GitHub
kind/bug severity/s0
Dominant language
Go
Stars
1.9k
Forks
311
Avg merge
1d 3h
Merged PRs (30d)
768

Description

## 问题

Fulltext2 JSON index 的 JSON 提取谓词 probe 被作为强过滤条件。规划器要求该索引的 ISCP watermark 不早于查询读快照;但 FULLTEXT2 ISCP job 完成后 watermark 固定,后续语句的读快照必然更新,因此该条件无法满足,JSON probe 不会被加入计划。

## 验证环境

main @ 95d04586eb80864499d0fde27aeb912b463ae4cd

## 复现

set experimental_fulltext2_index = 1;
create table async_docs (id int primary key, doc json);
create fulltext2 index ft_async on async_docs(doc) with parser json;
insert into async_docs values (1, '{"foo":"bar"}'), (2, '{"foo":"baz"}');

等待隐藏索引表中 index_id = 'cdc_tail' and tag = 1 的持久 chunk 出现后,mo_catalog.mo_iscp_log 中该 job 为:

job_name = index_ft_async, job_state = 3, drop_at is null, watermark 非空。

随后执行:

explain select id from async_docs where json_extract_string(doc, '$.foo') = 'bar';

计划为 Table Scan,保留原始 JSON filter,没有 fulltext2_search。

同一表上的普通 MATCH 对照:

explain select id from async_docs where match(doc) against('bar');

计划包含 Table Function on fulltext2_search,说明索引、会话开关和隐藏索引表均正常。

再验证“先写数据、后建索引”的静态建表路径,JSON 提取谓词同样是 Table Scan,而 MATCH 同样走 fulltext2_search。两种路径均稳定复现。

## 根因定位

pkg/sql/plan/apply_indices_fulltext_json.go 的 addJSONFulltextProbes 先调用 indexCoversSnapshot。对于 AlwaysAsync 的 fulltext2,它委托 pkg/fulltext2/plugin/coverage/coverage.go,只有 live job 的 watermark >= 当前事务 Snapshot 才返回 true。

该 watermark 在 job_state = completed 后不再推进;新查询的 Snapshot 晚于完成时 watermark,因此 coverage 永远 fail-closed。JSON probe 从未被追加。现有 test/distributed/cases/fulltext2/fulltext2_json_probe.sql 的注释说明优化器应把 json_extract_string/json_extract_float64 比较转为 probe,但该用例只比较查询结果,没有断言计划是否实际使用 probe。

## 期望

在隐藏索引已完整覆盖源表、且后续没有未被索引的源表变更时,JSON 提取比较可以安全地使用 Fulltext2 JSON probe;至少需要让 completed job 的 coverage 对无后续变更的读快照可证明为已覆盖,或以其他保守但可达的条件替代当前 watermark >= fresh query snapshot 的门槛。

## 影响

这是执行计划/性能问题,不影响已验证的查询结果正确性:JSON 谓词回退 Table Scan 后结果与无索引表一致。该能力仍受 experimental_fulltext2_index 会话开关控制。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.