Skip to content

[Bug]: FULLTEXT2 index never indexes rows inserted/updated after index creation (incremental DML lost) #30401

Closed

Description

@Ariznawlll

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

b24d1b3 (2026-10-16)

Other Environment Information

  • Hardware: macOS arm64 (Apple Silicon), single-node standalone (./mo-service -launch etc/launch/launch.toml, LOG+TN+CN single process, DISK-V2 backend)
  • OS: macOS
  • Others: experimental_fulltext2_index = 1 required to use CREATE FULLTEXT2 INDEX

Actual Behavior

A FULLTEXT2 index never receives rows inserted or updated after the index is created.

  • New terms introduced by an INSERT after CREATE FULLTEXT2 INDEX are never returned by MATCH ... AGAINST — not immediately, not after waiting 60+ seconds.
  • An UPDATE that changes the indexed text leaves the old terms searchable and never adds the new terms.
  • Only DELETE propagates to the index — and only DROP INDEX + CREATE FULLTEXT2 INDEX rebuild fixes the content.
set experimental_fulltext2_index = 1;
drop database if exists dml;
create database dml;
use dml;
create table t (id int auto_increment primary key, body text);
insert into t (body) values ('apple banana');
create fulltext2 index i on t(body);

-- A: baseline — works, pre-existing data is indexed
select id from t where match(body) against ('apple');   -- -> 1  (correct)

-- B: insert AFTER the index exists
insert into t (body) values ('cherry date');
select id from t where match(body) against ('cherry');  -- -> EMPTY  (should be 2)

-- C: wait 60 s — still empty (verified with three successive sleeps)
-- (after ~60 s) select id from t where match(body) against ('cherry'); -- -> still EMPTY

-- D: update the existing row
update t set body = 'elderberry fig' where id = 1;
select id from t where match(body) against ('elderberry'); -- -> EMPTY (should be 1)
select id from t where match(body) against ('apple');      -- -> 1     (should be EMPTY — stale term)
select id from t where match(body) against ('banana');     -- -> 1     (should be EMPTY — stale term)

-- E: delete works
select id from t where match(body) against ('cherry');     -- -> EMPTY (correct, row 2 deleted)

Expected Behavior

FULLTEXT2 incremental maintenance must behave like the classic FULLTEXT engine on the same server:

Operation classic FULLTEXT (same server, same shape) FULLTEXT2
INSERT after index built New term searchable immediately Never indexed
UPDATE removes/improves text Old term gone / new term in Old term stays, new term never indexed
DELETE Removed Same (works)
DROP INDEX + rebuild — Rebuilt index is correct

Direct side-by-side control on the same instance:

create table classic_t (id int auto_increment primary key, body text);
insert into classic_t (body) values ('apple banana');
create fulltext index icl on classic_t(body);
insert into classic_t (body) values ('cherry date');
select id from classic_t where match(body) against ('cherry');  -- -> 2 (correct)

create table ft2_t (id int auto_increment primary key, body text);
insert into ft2_t (body) values ('apple banana');
create fulltext2 index i2 on ft2_t(body);
insert into ft2_t (body) values ('cherry date');
select id from ft2_t where match(body) against ('cherry');  -- -> EMPTY (wrong)
-- even after waiting 15 s: still EMPTY

Additional information

  • Verified 5 independent runs across separate standalone instances; behaviour is 100% deterministic.
  • SELECT git_version(); -> b24d1b3
  • The ISCP executor is alive and iterating — log shows ISCP-Task flush watermark every 5 s with jobCount=7.
  • mo_catalog.mo_iscp_log row for the index job shows job_state=3, watermark (LSN) advances periodically, yet the delta is never materialized into the index.
  • Checked for duplicates: not #27964 (INCLUDE-column rename), not #27788 (cross-CN cache), not #26973 (performance bound), not #28986 (multi-column NULL), not #30335 (COPY ALTER covered search), not #28847 (data branch).
  • Related: #29887 (NL multi-word bug) is a separate issue in the same area but different semantics.

Activity

  1. added
    kind/bug
    severity/s2
    on Oct 16, 2026
  2. Ariznawlll commented on Oct 18, 2026

    @Ariznawlll
    CollaboratorAuthor

    Root-cause narrowing (official main b24d1b3, single-node standalone)

    I instrumented the ISCP pipeline during the non-converging incremental insert, and found a sharper symptom that should narrow the search:

    The ISCP watermark advances every sync tick (15s), yet the FULLTEXT2 index content never updates.

    Observed over 90s after INSERT of a row whose term should be searchable:

    t MATCH("cherry") mo_iscp_log.watermark
    15s 0 rows 1792313889028559000-1
    30s 0 rows 1792313918924171000-1
    ... 0 rows (advancing ~10s each tick)
    90s 0 rows 1792313978921938000-1

    mo_iscp_log.job_status for the index job shows LSN: 8, Stage: 1, ErrorCode: 0, ErrorMsg: "" — i.e. the consumer reports healthy progress (no error) while the delta is silently dropped.

    So the failure is not "ISCP never consumes" (my initial guess) — the executor clearly advances its watermark over the new logtail. The delta is being acknowledged but not materialized into the FULLTEXT2 posting/segment store. Likely candidates: the fulltext2 build path skipping the tail-build for post-create inserts, or the search side reading a generation that is never swapped to include the delta.

    This also explains why DROP INDEX + rebuild fixes it (fresh full build) and why pre-create rows are searchable (initial build), while post-create inserts/updates are lost (incremental path).

    Environment: macOS arm64, ./mo-service -launch single process (LOG+TN+CN), git_version b24d1b3, sink/source topology not involved here.

  3. Ariznawlll commented on Oct 18, 2026

    @Ariznawlll
    CollaboratorAuthor

    Control: classic FULLTEXT incremental is correct on the same build

    Side-by-side on the same instance (same b24d1b3, same process), the classic FULLTEXT engine handles every incremental case correctly, confirming this is FULLTEXT2-specific:

    op classic FULLTEXT FULLTEXT2
    INSERT after build cherry searchable immediately (1 row) never searchable (0 rows)
    UPDATE (old term) old term gone (0 rows) old term still hits (stale)
    UPDATE (new term) new term searchable (1 row) never searchable
    DELETE term removed (0 rows) removed (works)

    This isolates the defect to the FULLTEXT2 tail/incremental build path (the RunFulltext2 ISCP consumer → TailBuilder → CdcTail frames), which the code itself notes is "CDC/txn-coupled: not exercised by package unit tests" — only its primitives are unit-tested. Classic FULLTEXT uses a different incremental path that is proven correct.

  4. Ariznawlll commented on Oct 18, 2026

    @Ariznawlll
    CollaboratorAuthor

    Control: classic FULLTEXT incremental is correct on the same build

    Side-by-side on the same instance (same b24d1b3, same process), the classic FULLTEXT engine handles every incremental case correctly, confirming this is FULLTEXT2-specific:

    • INSERT after build: classic searchable immediately (1 row) vs FULLTEXT2 never (0 rows)
    • UPDATE old term: classic gone (0 rows) vs FULLTEXT2 stale (still hits)
    • UPDATE new term: classic searchable (1 row) vs FULLTEXT2 never
    • DELETE: classic removed (0 rows) vs FULLTEXT2 removed (works)

    This isolates the defect to the FULLTEXT2 tail/incremental build path (RunFulltext2 ISCP consumer -> TailBuilder -> CdcTail frames), which the code itself notes is "CDC/txn-coupled: not exercised by package unit tests" — only its primitives are unit-tested. Classic FULLTEXT uses a different, proven-correct incremental path.

  5. Ariznawlll commented on Oct 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main;隔离源码完整 commit 21966565287edf9f7d7f519af60d269711608945,服务端 git_version()=2196656528。
    • 修复:PR fix(fulltext2): evict idle search cache after CDC flush so incremental DML is visible (#30401) #30606,merge commit fed3bf59700158212a9135d0b619c3849034bb65,已进入该 main。
    • 部署方式:macOS arm64,隔离 mo-service,etc/launch/launch.toml 单进程 1 CN / 1 TN / 1 LogService、DISK-V2,MySQL 协议 127.0.0.1:6001;experimental_fulltext2_index=1,其余 FULLTEXT2 刷新设置采用默认值。
    • 测试日期:2026-10-20。

    原问题验证

    按 issue 的实际 SQL 路径,在每轮独立创建并清理的数据库中执行:先插入 apple banana、再创建 FULLTEXT2 索引并查询预存词(命中 id=1、预热查询缓存);随后才 INSERT ('cherry date'),等待 25 秒后查 cherry;再将 id=1 UPDATE 为 elderberry fig,等待 25 秒后查新旧词;最后 DELETE id=2,等待 25 秒后查 cherry。

    三轮实际结果完全一致:cherry 在插入后均返回 id=2;更新后 elderberry 均返回 id=1、apple 和 banana 均返回空;删除后 cherry 均返回空,基表仅余 (1,'elderberry fig')。原报告中“增量 INSERT/UPDATE 60 秒仍不可见、旧词仍命中”没有再出现。这里验证的是25 秒检查点,没有声称立即可见或测得精确刷新延迟。

    Happy Path 覆盖

    1. 建索引前已有行 apple 三轮均命中 id=1;增量插入/更新后的新词按上述结果三轮均可见。
    2. 额外三轮 NULL 对照:含 SQL NULL 文本行的 FULLTEXT2 索引可正常建立,apple 只命中非 NULL 行,未出现虚假 cherry 命中。
    3. 同轮传统 FULLTEXT 对照表在索引建立后插入 cherry date,三轮均立即命中 id=2。所有测试库已删除。

    Unhappy Path 覆盖

    1. 更新后旧词 apple/banana 三轮均不再错误命中;删除后 cherry 三轮均不再错误命中。
    2. NULL 行三轮均不影响其它词检索;不存在的 cherry 在插入前返回空。

    白盒验证

    在同一最新 main 上运行 pkg/fulltext2.TestEvictIdleCache 及 pkg/iscp.TestRunFulltext2RefreshesIdleCacheAfterNonEmptyCDCFlush,两个包的定向 Go 测试 -count=3 均 PASS。后者覆盖非空 CDC flush 后驱逐空闲热缓存、下一读者重载已提交数据的修复路径;本轮未运行 -race。

    回归测试

    • 修复 PR fix(fulltext2): evict idle search cache after CDC flush so incremental DML is visible (#30401) #30606 已有上述直达修复路径的确定性 Go 回归;仓库现有 fulltext2_async/warm_refresh BVT 覆盖缓存刷新相关路径。本轮独立真实 SQL 三轮补足了原报告的端到端 INSERT/UPDATE/DELETE 可见性。
    • 按当前约定,已有针对修复路径的 Go 测试且原单 CN 产品路径 3/3 通过,本轮未追加重复的定时 MOTR 用例;持续轮询 MATCH 会使 idle-only 驱逐条件时序不稳定,不能把偶发时序输出做成功 golden。未运行 MOTR 全套。
    • PR #30606 的主 CI 中 CI Required、Ubuntu/x86 UT、multi-CN BVT job 成功;另一 TKE run 的镜像构建 job 失败,后续 TKE 用例跳过,不能计为该环境的产品验收。

    测试证据

    • 本轮隔离服务端 git_version()=2196656528;原路径每轮输出均为 insert ((2,),) update ((1,),) () () delete (),三轮末行 result 3/3 PASS, all test databases dropped;独立 NULL/传统 FULLTEXT 对照亦为 3/3 PASS。
    • 修复 PR #30606 和 CDC 缓存回归源码。
    • 本结论限于 issue 报告的单 CN 默认刷新场景;不同 CN 上的跨节点缓存可见延迟未单独验收,不将其表述为已通过。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions