Repository navigation
Description
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,3Actual 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%'returned1,3throughout. - 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_SYNCreindex restored1,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-1562pkg/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
- [Bug]: DATA BRANCH leaves FULLTEXT2 and HNSW indexes uninitialized but queryable #27950 covered DATA BRANCH leaving FULLTEXT2/HNSW indexes uninitialized; this reproducer uses ordinary COPY ALTER and remains empty after the former branch fix.
- [Bug]: Prepared FULLTEXT and vector statements keep stale hidden-index plans after index DDL #25625 covered stale prepared plans after special-index DDL; here fresh SQL and fresh prepared statements are also empty.
- [Bug]: ASYNC special indexes can return empty results before initial build completes #26029 documents the short initial async-build window; this COPY ALTER case remains empty after 60 seconds and requires reindex or restart to restore results.
Activity
cpegeric commentedon Sep 14, 2026
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.
cpegeric commentedon Sep 14, 2026
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:
test(fulltext2): cover AlterCopyInitSQL dispatch + plugin seeds (matr…
test(fulltext2): deterministically prove the matrixorigin#28837 not-c…
3 remaining items
fix(cagra/ivfpq): seed the copy-alter CDC with a REINDEX so the repla…
fix(vectorindex): don't retain an empty index generation, and keep a…
Ariznawlll commentedon Sep 17, 2026
当前 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;MATCH在 3/3 中均返回空集;1,3。这说明当前实现已从“长期/永久空索引”改善为异步恢复,且在 replacement index 的 durable
tag=0base 就绪后查询正确;但在 ALTER 已成功返回、索引查询仍可路由执行的窗口中仍会产生 false negative。原 issue 的期望是 ALTER 完成后保持等价,或在初始化完成前使索引不可参与查询;当前行为两者都不满足。现有
fulltext2_copy_alter.sql在 replacementtag=0就绪后才断言 MATCH,能验证最终恢复,但会遮蔽上述完成后短暂空结果;且当前多 CN 用例处于 skip。请确认是否应消除该可见窗口,或明确调整 issue 的验收/产品语义。issue 保持 Open。cpegeric commentedon Sep 17, 2026
the index is eventually-consistent. This is async index and never be synchronous. This behavior is normal and WON't FIX.
Ariznawlll commentedon Sep 17, 2026
处置说明
已按研发在 #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.
fix(fulltext2): rebuild + refresh cache so COPY ALTER leaves the inde…
fix(vectorindex): don't retain an empty index generation, and keep a…
fix(fulltext2): rebuild + refresh cache so COPY ALTER leaves the inde…
fix(vectorindex): don't retain an empty index generation, and keep a…