Repository navigation
Description
Is there an existing issue for the same bug?
- I searched existing issues and did not find the same bug.
Branch Name
Official tag v4.2.1 (unmodified source).
Commit ID
d2393868a7aaa6343518d80849fe4696aa3577e9
Other Environment Information
- macOS ARM64, Go 1.26.4, native CPU build.
- Local cluster with two CNs and local disk storage.
- 1,000,000 rows;
vecf32(1024); approximately 2 KB question text and 8 KB answer text per row. - One IVF index,
lists=1024,vector_l2_ops; sessionprobe_limit=5. - 894,354 rows satisfy the business filters.
- All data was loaded before creating the index. The data directory and existing index were created with 4.0-dev and reused with v4.2.1, without rebuilding the index or changing the query vector.
- Control: the same fixture/index/query was stable over 30 executions on 4.0-dev commit
da7ad6be78eb48ee81b8b6c33c5a7651c9364587.
Actual Behavior
Repeated identical IVF mode=post queries return different ID multisets, not merely a different row order. The query contains two identical LIMIT 200 branches joined with UNION ALL.
Over 30 executions on v4.2.1, alternating between the two CN endpoints (15 executions per endpoint), every execution returned 400 rows. Results consisted of two disjoint groups A and B, each containing 200 IDs:
| Result multiset | Executions |
|---|---|
| A + A | 25 |
| B + B | 1 |
| A + B | 4 |
Across the 29 consecutive comparisons:
- 22 unchanged;
- 5 replaced 200 rows;
- 2 replaced all 400 rows.
For every repeated ID, its distance and vector-string hash remained identical. Independent float64 L2 recomputation differed by at most 4.935991660542927e-09 from the returned distance. The synthetic input vectors are finite; this reproduction does not require NaN.
Expected Behavior
With unchanged data/index/query, candidate selection across CN partitions must preserve the global distance ranking before applying the candidate budget. Arbitrary arrival order of CN results must not discard an entire partition's better candidates.
This report concerns whole candidate groups being replaced, not the unspecified output order of UNION ALL or an expectation that approximate search always matches exhaustive search.
Steps to Reproduce
This is a reproduced large-fixture case; a standalone minimized reproducer has not yet been prepared. The setup and query shape are below. The query-vector placeholder must be replaced with one fixed 1024-dimensional vector for the fixture, and held unchanged across runs.
- Start a two-CN cluster. Load the million-row fixture described below, then create its IVF index. In the executed experiment these steps ran on 4.0-dev, followed by restarting the same data directory with official v4.2.1.
- Set
probe_limit=5in each session. - Execute two copies of the following branch as
(<branch>) UNION ALL (<branch>), 30 times. Compare ID multisets, ignoring output order. - Inspect
EXPLAIN PHYPLANand confirm that each branch dispatchesivf_searchto both CNs and merges their output through an ordinarylimitbefore the join.
CREATE TABLE ca_comprehensive_dataset (
md5_id varchar(32) PRIMARY KEY,
question text,
answer text,
content_type varchar(32),
source_type varchar(16),
question_vector vecf32(1024),
allow_access varchar(16),
allow_identities varchar(16),
delete_flag int
);
-- Load all 1,000,000 rows first.
SET ivf_threads_build=4;
CREATE INDEX idx_question_vector USING ivfflat
ON ca_comprehensive_dataset(question_vector)
lists=1024 op_type 'vector_l2_ops';
SET probe_limit=5;Each identical branch:
WITH t AS (
SELECT md5_id, question, answer, content_type, source_type,
l2_distance(question_vector, '<fixed 1024-dimensional vector>') AS vec_dist,
allow_access, allow_identities, question_vector
FROM ca_comprehensive_dataset
WHERE delete_flag IS NULL
)
SELECT md5_id, question, answer, source_type, vec_dist, question_vector
FROM t
WHERE (
locate('OPEN', allow_access) > 0
OR (locate('ABO', allow_access) > 0
AND locate('SA_O', allow_identities) > 0)
)
AND locate('日更', content_type) = 0
AND locate('直播', content_type) = 0
ORDER BY vec_dist
LIMIT 200 BY RANK WITH OPTION 'mode=post'Synthetic fixture details
- IDs are
md5(cast(i as varchar)), fori=0..999999. - The first 740,000 vectors form a dense cluster around one normalized float32 vector. Every 370th row in that range uses a distinct normalized near vector, for 2,000 near vectors total. Near vectors are formed by adding Gaussian noise with standard deviation
1e-5to the cluster vector, then normalizing. - Remaining rows use one of 64 normalized background vectors (
i % 64). All vectors have dimension 1024 and finite components. - NumPy RNG seeds: base vectors
20260916, near-vector noise20260917. - Per-row question/answer text is independently generated base64 text, approximately 2 KB/8 KB, to produce a substantial scan instead of a tiny highly compressible fixture.
content_type:直播wheni % 97 == 0, otherwise日更wheni % 89 == 0, otherwise普通.allow_access:CLOSEDwheni % 13 == 0, otherwiseOPEN;allow_identities='SA_O'.delete_flag=1wheni % 101 == 0, otherwise NULL.- Query selection after index creation: take the centroid of the largest bucket; generate a direction with RNG seed
20260918; remove its projection onto the span of nearby centroid offsets (distance < 0.01), normalize, and add0.02 * directionto that centroid. Convert to float32 and freeze the result for all subsequent executions. - The executed fixture had 1,024 non-NULL centroids and approximately 740,000 entries in its largest selected bucket.
Additional information: execution plan and code analysis
The executed plan uses an IVF candidate budget of 260 for each outer LIMIT 200 branch. Each CN produces partition-local candidates. The physical plan merges them with an ordinary LIMIT, with no global distance TopN at that merge:
CN0: tablefunction -> projection -> limit --+
merge -> limit -> hash build
CN1: tablefunction -> projection -> limit --+ |
hash join -> top200
Actual physical-plan excerpt for one branch (the other branch has the same structure):
Scope 1 (Magic: Merge, mcpu: 1, Receiver: [0, 1])
Pipeline: └── hash build
└── limit
└── merge
PreScopes: {
Scope 1 (Magic: Remote, mcpu: 1, Receiver: [])
DataSource: []
Pipeline: └── connect to MergeReceiver [0]
└── limit
└── projection
└── tablefunction
Scope 2 (Magic: Remote, mcpu: 1, Receiver: [])
DataSource: []
Pipeline: └── connect to MergeReceiver [1]
└── limit
└── projection
└── tablefunction
}
Source chain pinned to the reproduced version:
- The IVF rewrite sets both
IndexReaderParam.LimitandtableFuncNode.Limit: apply_indices_ivfflat.go. - IVF search can be dispatched to multiple CNs, with partition-specific reader parameters: compile.go.
- The FUNCTION_SCAN compilation continues through
compileSort: compile.go. A node with Limit and no OrderBy takes thecompileLimitpath: compileSort. compileLimitadds local limits, merges the scopes, and adds another ordinary limit: compile.go.- That operator truncates by received row count, without comparing distances: limit.go.
Causal explanation: either CN can supply the entire 260-row candidate budget. Whichever partition arrives first can therefore displace all candidates from the other partition. The later business filters and outer Top200 cannot recover discarded candidates. The two UNION branches race independently, explaining the observed A+A, B+B, and A+B outcomes. UNION ALL exposes the two independent outcomes; the problematic candidate truncation is inside each branch.
Validation scope / remaining work
- No production-code modifications or fix verification have been performed.
- The executed v4.2.1 test reuses an index built on 4.0-dev; fresh index creation on v4.2.1 has not been covered by this experiment.
- No historical bisect has been performed; the stable 4.0 control is not a claim about the exact introducing commit.
- The inner scan reported DOP 10. v4.2.1 background explain records a representative coordinator-partition query, so its reported input-block count must not be treated as the total across CN partitions; see ivf_search.go.
Activity
fix: rank multi-CN IVF candidates before applying global limit (#28945)
Ariznawlll commentedon Sep 16, 2026
在最新官方
main(d5c4e8b832ad0275766f6d8f8f0be7ec4c0fb544)补充了与本问题相关的两 CN 验证;以下结果只覆盖当前提交,不替代 v4.2.1 的历史复现记录。IVF 多 CN 候选合并
vecf32(4)IVF fixture(lists=8、probe_limit=5)复现原始的两个完全相同mode=post分支UNION ALL形状。LIMIT 200 BY RANK的结果与mode=force精确基线均为 200 行,行集 MD5 一致。merge -> ordinary limit的候选截断形状。FULLTEXT2 + IVFFLAT 混合检索
同表建立
FULLTEXT2(body) WITH PARSER ngram与IVFFLAT(v),在三个独立数据库中执行:4,8,12;mode=force的精确基线也是4,8,12。EXPLAIN同时包含Table Function on fulltext2_search和Vector Index Scan on ivf,即该 IVFFLAT 组合没有退化为仅全文回表排序。分页边界补充
同一 50,000 行 IVF fixture 还覆盖了非首段分页:
0dc16a82d224efe8795236201c201cf0,与mode=force一致。UNION ALL后,40 个并发请求均为 400 行,按 ID multiset 的 MD5 为f0f2f03d24ae90a8ab3180befb38b7bd。mo-service进程,再执行相同的 40 并发双分支查询;40 次仍全部为 400 行及同一 MD5。因而该结论不依赖两个 CN 位于同一进程。DML 可见性边界
FULLTEXT2 是 CDC 驱动的 always-async 索引。
UPDATE后立即查询仍可观察到旧命中;本地两 CN 在后续 CDC 消费完成后都收敛到基表的新命中集合。该延迟符合当前 async 索引模型,不作为本 issue 的错误结果。另外发现的独立问题
带 FULLTEXT/FULLTEXT2 的直接
MATCH过滤与ROW_NUMBER() OVER (...)组合时,窗口算子会阻断全文 rewrite;两类索引、双 CN、各 3 个新库都稳定得到ERROR 20105,而直接 MATCH 与无 MATCH 的窗口查询均正常。该问题与 IVF 全局候选合并无关,已单独记录为 #28974。Ariznawlll commentedon Sep 16, 2026
测试版本
v4.2.1-hotfix9572bd3311abb16d1df939956408a727bcf83eba8.0.30-MatrixOne-v4.2.1-hotfix-20260916mo-search-commit-9572bd3311-20260916数据与索引
anli_test.ca_comprehensive_datasetquestion_vector vecf32(1024)IVFFLAT(question_vector),lists=256,vector_l2_opsprobe_limit=5当前 ANLI fixture 与 Issue 原始 fixture 存在两项规模差异:原始场景为 100 万行、
lists=1024、2 CN;本次为 715,679 行、lists=256、3 CN。本次结论仅针对当前 ANLI 数据集和上述 hotfix commit。原问题验证
从表中固定选择同一个非 NULL 查询向量,保持 Issue 的核心 SQL 形状:两个完全相同的 IVF
mode=post分支,每个分支执行带业务过滤条件的ORDER BY l2_distance(...) LIMIT 200 BY RANK,随后通过UNION ALL合并。验证时没有用返回顺序作为判断依据,而是分别对两个分支的 200 个
md5_id排序后计算 SHA256,并对合并后的 400 个 ID multiset 再计算 SHA256。查询在三个 CN 入口轮转执行,共 15 次,每个 CN 5 次。结果:
d10189ff61f6479054ed36685817bb7f503f6fc1d0160682a61da9e672959f5a。d10189ff61f6479054ed36685817bb7f503f6fc1d0160682a61da9e672959f5a。d13ba4c109b14c0ac2807854057dd33a324fdfd4eb2cbd7734c04d6dc29d8f67。汇总输出:
执行计划与稳定性
top以及汇总阶段的merge top,候选集合在应用全局 LIMIT 前按距离进行合并,不再是历史问题中的无序普通 LIMIT 合并路径。Running。回归范围
本次是现有 ANLI 表和已建立 IVF 索引上的黑盒验证,没有新增或修改回归脚本。该 commit 的修复说明及原始 100 万行 fixture 验证见修复提交
9572bd3311abb16d1df939956408a727bcf83eba(#28945)。测试结论
测试通过。
fix: rank multi-CN IVF candidates before applying global limit (#29021)
Ariznawlll commentedon Sep 17, 2026
https://github.com/matrixorigin/mo-nightly-regression/pull/1695
已加入回归测试
[4.2.1-hotfix] backport ETL marker and multi-CN IVF fixes (#32035)