Repository navigation
Description
Problem
After ALTER TABLE ... ADD COLUMN rebuilds a table that has an IVFFLAT index,
an explicit mode=pre vector query returns an empty result even though matching
rows remain in the base table and in the vector index.
The wrong result is not tied to an old prepared plan. It also occurs with a
newly parsed static query and with a PreparedStatement created after the ALTER.
It affects both vector_l2_ops/l2_distance and
vector_l2sq_ops/l2_distance_sq, with and without IVFFLAT INCLUDE columns.
Environment
- MatrixOne commit:
01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90 - Version:
8.0.30-MatrixOne-v1.3.0 - Topology: 2 CN / 1 TN / 1 LogService
- SQL endpoints: both CNs were checked independently
Minimal reproduction
SET experimental_ivf_index = 1;
SET probe_limit = 1;
CREATE DATABASE ivf_copy_alter_pre;
USE ivf_copy_alter_pre;
CREATE TABLE t (
id INT PRIMARY KEY,
grp INT,
v VECF32(2)
);
INSERT INTO t VALUES
(1, 1, '[0,0]'),
(2, 1, '[1,0]'),
(3, 2, '[0,1]'),
(4, 2, '[2,0]');
CREATE INDEX ix USING IVFFLAT ON t(v)
LISTS = 1 OP_TYPE 'vector_l2_ops' INCLUDE(grp);
SELECT id FROM t
WHERE grp = 1
ORDER BY l2_distance(v, '[0,0]')
LIMIT 2 BY RANK WITH OPTION 'mode=pre';
-- 1, 2
ALTER TABLE t ADD COLUMN note INT DEFAULT 7;
SELECT id FROM t
WHERE grp = 1
ORDER BY l2_distance(v, '[0,0]')
LIMIT 2 BY RANK WITH OPTION 'mode=pre';
-- empty resultActual result
After the ALTER, mode=pre returns zero rows.
The post-ALTER plan still chooses the membership-filter topology:
Table Scan on t (grp = 1)
-> Vector Index Scan on ix
Runtime Filter Probe
-> SEMI JOIN
Runtime Filter Build
Table Scan on t (grp = 1)
The base-table producer has matching primary keys, but none survive the runtime
membership filter at the IVFFLAT scan.
Expected result
mode=pre should continue to return IDs 1, 2 after an unrelated column is
added.
At the same post-ALTER state, the following controls all return IDs 1, 2:
mode=forcemode=postmode=includewhengrpis an INCLUDE columnmode=autoin the four-row reproduction
Reproducibility and scope
- 3 independent database recreations
- 2 CN endpoints per recreation
- 6/6 minimal observations returned the same empty
mode=preresult - A broader matrix reproduced the same behavior for L2 and L2SQ, static SQL,
pre-ALTER PreparedStatements, and post-ALTER PreparedStatements - The same queries return the expected rows before the ALTER
This is a correctness issue in the explicit pre-filter path after COPY ALTER,
not approximate-nearest-neighbor recall variance: LISTS=1 and
probe_limit=1 scan the only IVF list, and the control paths return both rows.
Activity
Ariznawlll commentedon Sep 17, 2026
Expanded the post-DDL scope on the same commit and 2-CN topology.
The empty
mode=preresult occurs after these unrelated schema changes:Each statement leaves the base rows queryable and the IVFFLAT index usable by
mode=post; when the filter column is covered,mode=includealso remainscorrect. Only the membership-based
mode=prepath returns no rows. The samebehavior is visible immediately from both CN endpoints.
These controls do not produce the empty result in the same fixture:
A synchronous IVFFLAT rebuild restores pre-filter results:
After that statement, the minimal query again returns IDs
1, 2inmode=preon both CNs. This narrows the problem to the IVFFLAT state producedor retained by the affected COPY ALTER operations rather than to the added,
dropped, or defaulted column itself.
Ariznawlll commentedon Sep 17, 2026
进一步缩小了影响路径:异常有精确的
100/101候选主键数边界。在 500 行表上创建
IVFFLAT lists=5,随后执行会触发 COPY ALTER 的ADD COLUMN,使用非主键谓词形成不同大小的成员集合,并在两个 CN 上分别比较mode=pre与mode=force:mode=premode=force一致ALTER 前,以上全部规模都返回正确结果;ALTER 后,两套 CN 的结果完全一致。
mode=auto在这组简单查询中也保持正确。这个边界与
pkg/vectorindex/ivfflat/search.go中的exactPkFilterThreshold = 100完全吻合:小成员集合进入exactRelationMembershipScan,101 个及以上成员走另一条 membership-filter 路径。结合前一组EXPLAIN ANALYZE,异常表的隐藏 entries 扫描能够读到索引行,但 exact storage membership filter 将其从4行过滤为0行;正常对照表则能输出匹配行。因此问题可以进一步限定为:COPY ALTER 生成的 IVFFLAT 隐藏 entries 对象在“小成员集合 exact storage membership”优化路径上无法匹配;通用的大成员集合过滤路径不受影响。
ALTER REINDEX ... IVFFLAT FORCE_SYNC会重写物理索引状态并恢复该路径。Ariznawlll commentedon Sep 17, 2026
主键编码矩阵进一步限定了 #29042 的影响范围。相同的 4 行表、相同谓词和 COPY ALTER,在两套 CN 上得到以下结果:
INTBIGINTBIGINT UNSIGNEDVARCHARBINARYUUIDDECIMAL(20,0)(INT,VARCHAR)因此 COPY ALTER 后 exact storage membership 的异常目前只落在整数族主键编码上,并不是所有主键类型或所有 PRE membership 都损坏。
CHAR主键暴露了另一个与 ALTER 无关的 PRE runtime-key 类型校验问题,已单独记录为 #29045,避免混入本 issue。[-][Bug]: IVFFLAT mode=pre returns an empty result after COPY ALTER[/-][+][Bug]: IVFFLAT mode=pre returns empty after COPY ALTER, clone, snapshot clone, or data branch[/+]Ariznawlll commentedon Sep 17, 2026
进一步确认问题不局限于 COPY ALTER,而是所有会复制 IVFFLAT 隐藏物理表的生命周期路径。
从一个最终 schema 已经确定、且 PRE 查询完全正确的 500 行源表分别创建:
CREATE TABLE ... CLONE ...;DATA BRANCH CREATE TABLE ... FROM ...。源表和三个派生表都保留同一 IVFFLAT 定义。两个 CN 上比较
mode=pre与mode=force后得到完全相同的边界:三个派生表的执行计划都选择
Vector Index Scan,并非索引未被使用。分别执行ALTER TABLE ... ALTER REINDEX ... IVFFLAT FORCE_SYNC后,小成员集合 PRE 结果恢复。这与 COPY ALTER 的整数主键、100/101 阈值和 REINDEX 恢复特征完全一致,说明缺陷位于克隆 IVFFLAT entries 物理对象后的小整数主键 exact-storage-membership 匹配,不是 COPY ALTER 上层语法独有的问题。
[-][Bug]: IVFFLAT mode=pre returns empty after COPY ALTER, clone, snapshot clone, or data branch[/-][+][Bug]: IVFFLAT PRE and AUTO retry return empty after COPY ALTER, clone, snapshot clone, or data branch[/+]Ariznawlll commentedon Sep 17, 2026
影响并不限于显式 L2 PRE:
vector_l2_ops、vector_l2sq_ops、vector_l1_ops、vector_ip_ops、vector_cosine_ops全部复现小整数主键 PRE 空结果;VECF32与VECF64都受影响。各源表 PRE 与 FORCE 一致,派生表 FORCE 正确、PRE 为空。mode=auto在发生 AUTO -> PRE correctness retry 时也会返回空结果。AUTO 重试复现使用 1,000 行,只有距离较远的 ID
901..950满足谓词,查询请求 10 行:两个 CN 的结果均为:
源表的 AUTO 能在 POST underfill 后通过 PRE 重试补满;clone 表的重试进入损坏的 exact-membership 路径,因此默认 AUTO 也产生静默 false negative。该问题会影响依赖 AUTO correctness retry 的正常查询,并非只有主动选择
mode=pre的用户可见。Ariznawlll commentedon Sep 17, 2026
增量写入进一步证明这是克隆 entries 物理对象的问题,并且实际表现不一定始终“全空”,还可能是新旧数据混合的部分 false negative。
在含 10 条匹配行的源表上建立 IVFFLAT 后执行普通 clone,随后在 clone 表依次执行写入;两个 CN 的 PRE 结果完全一致:
clone 后新写入的 entries 行可以被 exact membership 正常匹配;从源索引物理复制过来的旧 entries 行不能匹配。只有会重写向量索引项的 DML 才让对应旧行重新可见,修改无关列没有效果。
因此线上表在 clone/data branch/COPY ALTER 后继续写入时,PRE/AUTO-retry 可能返回“部分新行 + 少量被重写旧行”,而不是稳定的空结果,这类结果更难通过简单的非空检查发现。
Ariznawlll commentedon Sep 17, 2026
持久化边界进一步排除了“只有从源表复制来的旧 object 损坏”的解释。
复现步骤:
mo_ctl('dn','flush',...)。两个 CN 的结果:
新写入索引项在内存态能够通过 exact membership;一旦成为 clone 隐藏 entries 表的持久化 object,也无法通过该过滤。源/clone 隐藏 entries 的 catalog 列号和
attr_seqnum均一致,因此问题更接近 clone 后 relation/object 身份或持久化 reader 对 membership hint 的映射,而不是用户列定义、索引行内容或单纯旧 object 复用。普通 flush 不是恢复手段;在有 clone 后写入的场景中,它会让暂时可见的新索引行也消失。当前验证中只有 IVFFLAT REINDEX 能稳定恢复持久化 PRE/AUTO-retry 结果。
Ariznawlll commentedon Sep 17, 2026
FULLTEXT2 + IVFFLAT 混合检索同样会触发本问题,并且已排除全文索引未就绪。
构造 1,000 行表,其中全文词
rareterm只命中 ID901..950;源表同时建立 FULLTEXT2 与 IVFFLAT,普通 clone 后对 clone 的 FULLTEXT2 单独执行FORCE_SYNC REINDEX,不重建 IVFFLAT。两个 CN 上:
901..950;fulltext2_search与Vector Index Scan;901..910,POST=空,PRE=901..910,AUTO=901..910;901..910,POST=空,PRE=空,AUTO=空。查询形状:
全文召回的 50 个整数主键正好进入 IVFFLAT 的 small exact-membership 路径。源表 AUTO 能从空的 POST 结果重试 PRE;clone 表的 PRE membership 无法匹配持久化 entries,最终默认 AUTO 静默返回空。该影响覆盖常见的“全文召回 + 向量重排”组合,而不只是普通列谓词。
Ariznawlll commentedon Sep 17, 2026
主键编码矩阵补充:clone 后的持久化 exact-membership 问题覆盖全部常见整数宽度,而非只有
INT/BIGINT。TINYINT、SMALLINT、MEDIUMINT、INT、BIGINT,以及以上全部 UNSIGNED 变体;BOOL:源表 PRE 正确,clone 后报invalid state vector Top-K row 0 is not present in the filtered row set,而 FORCE 正确;这与
docfilter对整数 key 使用 exact integer set、其他类型使用另一种 membership 表示的代码分支相吻合;BOOL 的错误表现不同,但仍只发生在 clone 后持久化 entries + exact membership 组合中。7 remaining items
cpegeric commentedon Sep 17, 2026
@iamlinjunhong please take a look.
LeftHandCold commentedon Sep 18, 2026
补充一条来自 Main Nightly 的复现证据。结论是:这不是普通的 ANN recall 波动,也不像环境/OOM 导致的测试误报;它是一个高可信的产品正确性异常,并且当前证据更支持“#29042 的同一持久化边界/关联路径”,暂时不另建重复 Issue。
Run / Job:
ee372584f28b49a32b5539ce72e2f515e464af376690f1af97977ad5671235e9204296cd2d504ad5mo-main-family-35243665787-1nightly-regression-dis-tp-cn-rdzmr本次运行实际观察到的顺序(UTC,2026-09-17)
21:36:38.012:IVF entries 写入完成,AffectedRows=5。21:36:39.204:TN 对该 entries 表执行flusher.force。21:36:39.594:该表FLUSH-START。21:36:39.663:FLUSH-END,记录aobj-merge-rows=5、tombstone-rows=0。21:36:42.462–42.533:IVF centroids 和同一 entries 表均完成查询侧加载/订阅。21:36:42.599:mixed-fulltext-vector返回空集;期望结果为1,2,4。该用例是 5 行固定数据、
mode=pre、lists=2、probe_limit=5,距离没有并列;失败发生在后续 DML/concurrency 步骤之前。因此这不是排序差异,也不是写入尚未完成导致的普通测试时序问题。与 #29042 的对应关系
#29042 的后续验证已经表明:即使没有 Clone/COPY ALTER,普通源表的 IVFFLAT entries 在持久化后,非主键谓词生成的小成员集合也可能使 PRE 查询返回空集,而 FORCE 仍然正确:
本次运行同时具备:整数主键、全文条件生成的小候选集合、
mode=pre,以及查询前已明确完成的 entries 持久化。因此它与该 Issue 的触发条件高度吻合。仍未声称已经完成的证明
原始 ANLI 脚本失败后会清理数据库,没有保存同一 fixture 的
FORCE/POST、精确扫描或 entries 持久化前后的对照结果;因此本条证据还不能单独证明具体错误代码行,也不能据此判断是近期提交引入的回归。它也不是 #28843 的首次访问超时问题。资源侧没有发现支持 OOM/重启解释的证据:故障窗口 TP CN working-set 峰值约 40.4 GiB(55 GiB limit),TN 约 22.9 GiB(32 GiB limit),相关 Pod restart counter 为 0。
建议的最小确认
请在同一被测 SHA 上复用这 5 行 fixture,显式保存:
mode=pre、mode=post、mode=force结果;如果 flush 后稳定得到
PRE=空、POST/FORCE=1,2,4,即可把本次 Nightly 作为 #29042 的直接持续复现;否则再把问题收窄到 FULLTEXT 生成成员集合与 IVF PRE reader 的组合路径。本评论仅补充只读 Run/Loki/监控证据,没有修改集群或执行修复。
Fix IVFFLAT membership metadata and retry filtering (#29835)
Ariznawlll commentedon Oct 12, 2026
测试版本
MatrixOne 固定最新
main@02a2823c2007d5e4fb4ada148e93743df337551a,本地单 CN/TN/LogService。MOTR 用例在 matrixorigin/motr#229,脚本issue_29042_ivf_persisted_membership.py。原问题验证
原问题的关键不是 ANN 召回率,而是 IVFFLAT 隐藏 entries 持久化或物理复制后,非主键谓词的小整数主键 membership 在
mode=pre被过滤为空;POST 不足时 AUTO 重试也可能因此漏结果。本次按原证据重新构造 entries flush、COPY ALTER、普通 clone,以及距离较远的 901–950 匹配行造成 POST underfill 的 AUTO 场景。在当前 main 上,PRE/AUTO 与 FORCE 均得到预期结果,未再出现空集。Happy Path 覆盖
INT主键、非主键grp<=10,原始 entries flush 前后FORCE/PRE/AUTO均返回 1–10;ALTER TABLE ... ADD COLUMN和CREATE TABLE ... CLONE后继续正确。id<=10作为独立控制。FORCE/PRE/AUTO都返回 901–910;POST 在相同 fixture 返回空,证明 AUTO 成功并非因为 POST 本来就足够。Unhappy Path 覆盖
grp<0无匹配行时 PRE 返回空,不把任意索引行误报为匹配。白盒验证
测试显式对照
mode=force(基准)与mode=pre/auto,并用mo_ctl('dn','flush', '<测试库>.<entries表>')强制经过原问题的持久化边界。由于此次是 SQL 可观测结果回归,没有据此断言具体内部过滤器实现或多 CN 缓存协议。回归测试
新增 MOTR case 的脚本、golden 与入口均位于上述 PR,记录后
--repeat 3对照通过。该 case 锁定持久化、COPY ALTER、普通 clone、100/101 分界和 AUTO correctness retry;本次尚未复跑原报告中的双 CN、snapshot clone、data branch、全部量化类型、多索引及混合全文过滤。如这些属于此 issue 的正式完整验收,还需在相应环境追加验证,不能把单 CN 结果扩大为那些路径已通过。测试证据
14_issue_regression.issue_29042_ivf_persisted_membership,3/3 success、0 fail;每次包含三轮独立建库,分别检查原始/flush/ALTER/clone/AUTO 分支。validate_29042.py、validate_29042_flush.py、validate_29042_clone.py、validate_29042_auto.py,各场景连续三轮结果正确。当前 main 在本次可验证的核心路径上已恢复正确。我把现有通过证据和未覆盖边界一并转回研发确认;本轮没有关闭 issue。
测试结论
测试通过。