Skip to content

[Bug]: DATA BRANCH FULLTEXT2 covered query returns deleted inherited row #28847

Closed

Description

@Ariznawlll

Environment

  • MatrixOne official main: 6987fda6c4a13295b8d525706342fc6033094d2e
  • Topology: 2 CN / 1 TN / 1 Log
  • Client: MySQL Connector/J 8.4.0 (binary protocol)

Problem

After a table with a synchronized FULLTEXT2 index is copied with DATA BRANCH CREATE TABLE, deleting an inherited row from the branch does not fully shadow the copied full-text posting.

A covered full-text query that only projects columns stored by the index returns the deleted primary key. Projecting a non-covered base-table column introduces a join and happens to filter the ghost row, so two equivalent predicates return different row sets.

Reproduction

SET experimental_fulltext2_index = 1;

CREATE DATABASE ft2_branch_delete;
USE ft2_branch_delete;

CREATE TABLE src (
  id BIGINT PRIMARY KEY,
  body TEXT NOT NULL,
  tag INT NOT NULL
);
INSERT INTO src VALUES
  (1, 'alpha inherited row', 10),
  (2, 'beta retained row', 20);

CREATE FULLTEXT2 INDEX ft ON src(body) INCLUDE(tag);
ALTER TABLE src ALTER REINDEX ft FULLTEXT2 FORCE_SYNC;

DATA BRANCH CREATE TABLE leaf FROM src;

DELETE FROM leaf WHERE id = 1;
INSERT INTO leaf VALUES (3, 'alpha branch new', 30);

Wait until the branch FULLTEXT2 storage table has durably consumed the DML (MAX(chunk_id) for index_id='cdc_tail' AND tag=1 advances). Do not execute MATCH while waiting, so the query cache is not pre-warmed.

SELECT id, body FROM leaf ORDER BY id;
-- 2 | beta retained row
-- 3 | alpha branch new

SELECT id
FROM leaf
WHERE MATCH(body) AGAINST('alpha')
ORDER BY id;

SELECT id, body
FROM leaf
WHERE MATCH(body) AGAINST('alpha')
ORDER BY id;

Actual result

The covered query returns the deleted inherited row:

SELECT id ...        => 1, 3
SELECT id, body ...  => 3 | alpha branch new

EXPLAIN shows that the first query uses the FULLTEXT2 covered path without a base-table join, while the second query joins the base table and therefore masks the stale posting.

The branch base table contains only ids 2 and 3. Rebuilding the branch index with ALTER TABLE leaf ALTER REINDEX ft FULLTEXT2 FORCE_SYNC changes the covered result to the correct id 3.

Expected result

Both queries should return only id 3. A DELETE consumed by branch index CDC must create a tombstone newer than the copied base posting, including on the covered-index execution path.

Reproducibility and isolation

  • Reproduced in 3/3 fresh databases.
  • In every run, the hidden FULLTEXT2 tail watermark advanced before the first MATCH query.
  • The source table's equivalent delete/insert sequence returned the correct result.
  • A cold service restart also retained the branch ghost posting, so this is persisted index state rather than a warm-cache visibility delay.
  • This differs from [Bug]: DATA BRANCH leaves FULLTEXT2 and HNSW indexes uninitialized but queryable #27950: that issue covered branch index initialization plus UPDATE/INSERT; the missing operation here is DELETE of a row inherited from the copied FULLTEXT2 base.
  • This differs from [Performance]: keep FULLTEXT2 cache read-only across CDC updates #28005: no MATCH query is issued before durable CDC-tail advancement, and the incorrect result survives a cold restart.

Relevant implementation gap

RestoreTable copies special-index hidden tables and re-registers index CDC from the post-clone timestamp. FULLTEXT2 has plain tombstone/liveness unit coverage, but the copied-base plus branch-delete generation boundary is not covered; the persisted branch tail delete does not shadow the inherited base posting on the covered path.

Activity

  1. added this to the MO-202609 milestone on Sep 14, 2026
  2. added
    kind/bug
    on Sep 14, 2026
  3. added theissue type on Sep 14, 2026
  4. Ariznawlll commented on Sep 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    在当前最新官方 main(ceaf9c6f88ab184d4e1684d413bfe40ae4b56a44,2 CN / 1 TN / 1 Log)上,分支删除后的 FULLTEXT2 covered-path 残留仍可稳定得到,3/3 个全新数据库一致:

    branch base rows       => 2|beta keep;3|alpha branch new
    covered MATCH(id only) => 1;3
    joined MATCH(id, body) => 3|alpha branch new
    

    每轮均先等待 branch 隐藏索引表的 cdc_tail watermark 前进,再执行第一次 MATCH;不是查询预热或尚未消费 CDC。EXPLAIN 仍显示 id-only 查询没有 base-table Join,而投影 body 的查询包含 Join。执行 ALTER TABLE leaf ALTER REINDEX ft FULLTEXT2 FORCE_SYNC 后,covered 查询恢复为仅返回 3。

    同批次还验证了服务冷重启后该残留仍存在,说明错误状态已进入可恢复的索引数据,而不只是当前 CN 的内存缓存。

  5. added
    severity/s0
    ai-easy
    and removed on Sep 24, 2026
  6. gouhongshen commented on Oct 11, 2026

    @gouhongshen
    Contributor

    PR #29863 is trying to fix this issue.

  7. gouhongshen commented on Oct 12, 2026

    @gouhongshen
    Contributor

    PR #29863 has merged and is awaiting manual validation. The issue remains open.

  8. added and removed
    severity/s0
    on Oct 22, 2026
  9. Ariznawlll commented on Oct 22, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 官方 main:75ae9a79d626622e6ccec0bcb28412f5fcf84c7f,产品源码未修改;已确认包含 fix(iscp): deliver trailing delete so a branch delete shadows a copied index #29863 的 merge commit 41ac6242b7620aa069db91492db1d41584319b05。
    • 2026-10-22,macOS arm64 隔离部署,2 CN / 1 TN / 1 LogService,DISK-V2 持久化;MySQL Connector/J 8.4.0,useServerPrepStmts=true、cachePrepStmts=false。
    • 本次仅验收 main,不声称其他发布线通过。

    原问题验证

    10 个全新数据库分别建立原报告的 src(id BIGINT PRIMARY KEY, body TEXT NOT NULL, tag INT NOT NULL),源表为 (1,'alpha inherited row',10),(2,'beta retained row',20)。源 FULLTEXT2 索引 FORCE_SYNC 后创建 leaf;删除继承行 1,插入新行 3。额外插入并删除瞬时行 9。

    每轮在最后一条 DML 完成后读取服务端纳秒时间作为 fence,等 leaf 的全部 live ISCP job 的 watermark 严格大于该 fence 且 ErrorCode=0,才开始第一次 MATCH。没有对 leaf 执行 REINDEX,也没有用 MATCH 预热。

    原始自然语言 MATCH(body) AGAINST('alpha') 与布尔模式均实际执行,分别检查:

    base leaf                     => 2|20;3|30
    covered id-only               => 3
    covered id/tag                => 3|30
    joined id/body                => 3|alpha branch new
    source alpha                  => 1|10
    leaf beta                     => 2|20
    leaf phantom                  => empty
    

    两个 CN 均验证精确结果和 covered plan(Fulltext Index Scan、无 base-table Join)。自然语言和布尔模式版本在冷重启前检查一次,再完成 10 个完整关停/恢复周期:同一持久化目录、每次全新服务进程及 Java 客户端,所有关停 exit=0。10 个数据库 × 2 CN ×(重启前 1 次 + 重启后 10 次)= 220 组检查通过。未复现原报告持久化 ghost row。

    Happy Path 覆盖

    1. 自然语言与布尔查询、仅主键覆盖投影、INCLUDE 列覆盖投影及非覆盖 body 投影结果一致。
    2. 未删除的继承行 2 保留;本分支新行 3 可查;源表不受分支删除影响。
    3. 插入后删除的行 9 在 base 与全文查询中均不可见。
    4. 两 CN 及 10 次冷恢复后逐值一致;不是只检查进程未崩溃。

    Unhappy Path 覆盖

    1. 10 个数据库 × 2 CN:重复主键写入返回 1062;body/tag 的 NOT NULL 违反返回 3819。每次拒绝后 leaf 仍为 (2,20),(3,30),src 仍为 (1,10),(2,20)。
    2. 显式事务删除行 3 后 ROLLBACK:20 组均恢复完整 leaf 行集。
    3. 定向 MOTR 每次创建独立随机数据库;finally 清理并验证数据库消失,连接关闭。CDC 未越过 fence 或出现 job 错误会失败,不将超时当通过。

    白盒验证

    本轮使用真实 SQL、Connector/J 二进制协议和真实进程冷恢复;没有 white-box hook 或替换产品实现。未单独新增 Go mock/UT。

    回归测试

    已检查 main 的 test/distributed/cases/git4data/branch/edge/branch_fulltext2_inherited_delete.sql 以及现有 MOTR。新增独立 MOTR #257,没有加入 #247。

    • script/12_git4data/issue_28847_inherited_delete.py 与独立预期 .out,最新 head 0211c158d97d505bf6f60f66218c7f4b75e92f03。
    • 最终自然语言/id-only/布尔版本在两个 CN 上定向 3/3 与预期精确匹配。MOTR 框架离线测试 428 项通过;第一次沙箱执行因 ps/本机端口权限发生 5 个错误,获得本机执行权限后原样通过。
    • 上述冷重启是独立部署验证,不声称脚本本身会重启共享服务。
    • 完整 MOTR 产品 suite、Linux/TKE 集成测试未运行。 PR 的 GitHub Actions job 因 Actions 预算限制未启动,不能记作 CI 通过。产品验收及定向回归已通过;MOTR unkown error:[42P09]alias 'i0 + 10 * i0 + 100 * i0' is ambiguous #257 的评审和 CI 预算阻塞独立跟踪,不计为产品失败。

    测试证据

    • 回归脚本固定版本
    • PR 首轮 Actions 未启动记录,annotation:The job was not started because an Actions budget is preventing further use.;最新 head 的 run 为 39762721980,亦未运行测试。
    • 本地保存 branch-28847-setup.log、branch-binary-natural-before.log、branch-binary-cycle-{1..10}.log、restart-natural-cycles.log、branch-negative.log 和 motr-28847-natural-{1..3}.log;这些本地文件未冒充公开下载制品。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

ai-easykind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions