Skip to content

[Bug]: COPY ALTER leaves an unaffected FULLTEXT2 index empty #28837

Closed as not planned

Description

@Ariznawlll

Description

ALTER TABLE ... ADD COLUMN on a table with an unaffected FULLTEXT2 index replaces the table through COPY ALTER and immediately leaves the inherited FULLTEXT2 definition queryable, but MATCH ... AGAINST returns no rows. The base rows remain correct, both fresh literal SQL and fresh prepared statements see the empty index result, and the result stays empty for at least 60 seconds on both CNs.

Environment

  • Branch: main
  • Commit: bb358ea76aeb44a6eed5079616e7e75ba35e75b9
  • Deployment: local 2 CN / 1 TN / 1 Log service; direct CN connections
  • Date: 2026-09-14

Steps to reproduce

SET experimental_fulltext2_index = 1;

CREATE DATABASE ft2_copy_alter;
USE ft2_copy_alter;
CREATE TABLE t(id BIGINT PRIMARY KEY, body TEXT NOT NULL);
INSERT INTO t VALUES
  (1, 'alpha red'),
  (2, 'beta'),
  (3, 'alpha blue');

CREATE FULLTEXT2 INDEX ft ON t(body);
ALTER TABLE t ALTER REINDEX ft FULLTEXT2 FORCE_SYNC;

SELECT id FROM t
WHERE MATCH(body) AGAINST('+alpha' IN BOOLEAN MODE)
ORDER BY id;
-- 1,3

ALTER TABLE t ADD COLUMN note VARCHAR(20) DEFAULT 'x';

EXPLAIN SELECT id FROM t
WHERE MATCH(body) AGAINST('+alpha' IN BOOLEAN MODE)
ORDER BY id;
-- contains: Table Function on fulltext2_search

SELECT id FROM t
WHERE MATCH(body) AGAINST('+alpha' IN BOOLEAN MODE)
ORDER BY id;
-- empty, including after polling for 60 seconds

SELECT id FROM t WHERE body LIKE '%alpha%' ORDER BY id;
-- 1,3

Actual behavior

After the unrelated ADD COLUMN, the optimizer selects fulltext2_search and returns an empty result. The same result is observed from old and newly prepared statements on the other CN. The base-table oracle still returns 1,3.

The replacement table's live index_ft ISCP job remains in running state and advances its watermark, but the MATCH result remains empty for the full 60-second observation window. A service restart or ALTER TABLE t ALTER REINDEX ft FULLTEXT2 FORCE_SYNC restores 1,3 without changing the base rows.

Expected behavior

An ALTER that does not touch the indexed column must not make a previously valid FULLTEXT2 index return false negatives. COPY ALTER should preserve or rebuild the index and publish it only with queryable content; once the ALTER statement completes, MATCH must remain equivalent to the unchanged base rows, or the index must stay ineligible until initialization is complete.

Stability and controls

  • Reproducer: 3/3 fresh databases on the current main commit; two cross-CN directions plus one literal-only run.
  • Observation: each reproduction polled fresh literal SQL for 60 seconds and remained empty.
  • Base-data control: LIKE '%alpha%' returned 1,3 throughout.
  • Plan control: EXPLAIN continued to select fulltext2_search.
  • Prepared-plan control: old and newly prepared statements both returned empty, excluding stale prepared-plan reuse.
  • Same-COPY-ALTER HNSW control: rebuilt and returned the expected Top-K, excluding a general cluster or polling failure.
  • Recovery: FULLTEXT2 FORCE_SYNC reindex restored 1,3.

Evidence

Evidence artifact: https://gist.github.com/Ariznawlll/7cf5b2083f668fe40d5a2bda899abc54

Code analysis

The unaffected-plugin-index path in pkg/sql/compile/alter.go registers a replacement-table CDC task with startFromNow=false but passes an empty initialization SQL. In cloneUnaffectedIndexes, asynchronous plugins with SkipWholeIndex skip cloning all hidden tables and depend on that rebuild path.

The observed replacement FULLTEXT2 job is therefore registered from 0-0 with an empty InitSQL; its watermark advances while the queryable postings remain unavailable. This differs from the DATA BRANCH-specific initialization fixed by #27950 and appears to leave COPY ALTER without the equivalent FULLTEXT2 restore initialization/cache handoff.

Relevant code on this commit:

  • pkg/sql/compile/alter.go:1537-1562
  • pkg/sql/compile/alter.go:2717-2740

Regression coverage

Add a deterministic two-CN regression that creates and force-builds FULLTEXT2, performs an unrelated COPY ALTER, waits on the replacement index's observable readiness rather than a fixed sleep, and compares MATCH with a base-table oracle. Cover fresh SQL and a statement prepared on the other CN.

Related

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. added
    severity/s0
    and removed on Sep 14, 2026
  5. cpegeric commented on Sep 14, 2026

    @cpegeric
    Contributor

    Fultext2 is an async index. COPY ALTER with unaffected column still rebuild in asynchronous fashion. Fulltext2 search right after COPY ALTER will still get empty result. This is by design.

  6. cpegeric commented on Sep 14, 2026

    @cpegeric
    Contributor

    That's the missing piece — thank you. So the stale-empty read isn't a freshness logic bug; it's the #28005 keep-warm
    optimization: on a CDC flush the warm cache object is deliberately kept (not evicted) so concurrent readers reuse it, and only
    a later TTL sweep replaces it. That's fine for a base-having index (warm base ≈ correct), but for a base-less index cached
    empty at create, keeping the warm empty object means readers get total false-negatives until the sweep. Let me look at that
    keep-warm logic to design the right fix:

  7. 3 remaining items

  8. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    当前 main 复测仍未满足原 issue 的完成时可见性验收,转回 @cpegeric 继续处理。

    验证环境:本地单机 MatrixOne,由远端 main 0370bb4d6b118da29e164c54aa34ee010ed897bc 全新构建;#28879(d5c4e8b832)和后续 #29028(4750501d2f)均已包含。以下 COPY ALTER 场景独立执行 3/3。

    每轮先建立已填充的 FULLTEXT2 索引并 ALTER ... REINDEX ... FORCE_SYNC,ALTER 前 MATCH(... '+alpha' IN BOOLEAN MODE) 正确返回 1,3。随后执行不涉及索引列的 ALTER TABLE ... ADD COLUMN:

    • 基表控制查询 LIKE '%alpha%' 始终返回 1,3;
    • ALTER 完成后的第一条 fresh MATCH 在 3/3 中均返回空集;
    • 该空索引随后在约 8 s、10 s、11 s 才恢复为 1,3。

    这说明当前实现已从“长期/永久空索引”改善为异步恢复,且在 replacement index 的 durable tag=0 base 就绪后查询正确;但在 ALTER 已成功返回、索引查询仍可路由执行的窗口中仍会产生 false negative。原 issue 的期望是 ALTER 完成后保持等价,或在初始化完成前使索引不可参与查询;当前行为两者都不满足。

    现有 fulltext2_copy_alter.sql 在 replacement tag=0 就绪后才断言 MATCH,能验证最终恢复,但会遮蔽上述完成后短暂空结果;且当前多 CN 用例处于 skip。请确认是否应消除该可见窗口,或明确调整 issue 的验收/产品语义。issue 保持 Open。

  9. cpegeric commented on Sep 17, 2026

    @cpegeric
    Contributor

    the index is eventually-consistent. This is async index and never be synchronous. This behavior is normal and WON't FIX.

  10. Ariznawlll commented on Sep 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    处置说明

    已按研发在 #28837 (comment) 的产品决策处理:FULLTEXT2 是异步、最终一致索引,不提供同步索引或 COPY ALTER 成功返回即 MATCH 查询可见的承诺。因此,COPY ALTER 后替换索引尚在重建/刷新期间,MATCH 短暂返回空集或旧结果属于该最终一致性窗口,不作为需要修复的同步语义缺陷。

    已记录的兼容性契约

    该限制已写入并合并到 MySQL 兼容性契约:

    文档明确:调用方不能把 ALTER TABLE 成功返回视为 FULLTEXT2 搜索结果已就绪的信号;依赖索引结果的流程需要等待、重试或采用应用侧的最终一致性处理。

    本次复核证据

    在官方 main 0370bb4 的本地单 CN 复核中,三个独立 COPY ALTER 场景均观察到 ALTER 后首次 MATCH 为空,但替换索引随后收敛并恢复原有命中;底表 LIKE 扫描同时仍可返回目标行。该现象与异步最终一致的产品定位一致,且不构成窗口时长 SLA。

    关闭范围

    本次关闭只覆盖“DDL 返回后立即要求 FULLTEXT2 MATCH 已可见”的诉求。若后续发现索引在合理等待/重试后仍不能收敛、收敛后持续与基表不一致,或存在数据丢失、损坏等独立正确性问题,应另行作为 bug 跟踪。

    Closing as not planned per the documented product decision.

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions