Skip to content

fix: rank multi-CN IVF candidates before applying global limit - #28945

Merged
XuPeng-SH merged 1 commit into
matrixorigin:v4.2.1-hotfixfrom
iamlinjunhong:codex/fix-28943-ivf-candidate-merge
Sep 15, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:v4.2.1-hotfixfrom
iamlinjunhong:codex/fix-28943-ivf-candidate-merge

Conversation

@iamlinjunhong

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #28943

What this PR does / why we need it:

Partitioned IVF search applied an unordered global candidate LIMIT, so the first CN could consume the entire budget before better candidates from another CN arrived. Identical POST queries could replace an entire 200-row branch of a UNION ALL result.

At the existing multi-CN compiler boundary, use the existing local Top / MergeTop operators on the raw distance column before projection and the original global LIMIT. Preserve the candidate budget, partition dispatch, bucket selection, and all single-CN fallback paths. The change is limited to 17 production lines in the compiler; it does not alter the planner, index format, or configuration.

Validation

  • Regression tests compile the actual candidate pipeline and execute its Top/MergeTop operators against an independent global-sort oracle. Cover 1/2/3 CNs, absent/zero/one/bounded caps, empty/short/exact-size inputs, reversed arrival order, later better batches, INCLUDE NULL payload, and Reset reuse with memory cleanup.
  • The same regression tests fail against the exact unfixed base using a Go source overlay; fixed tests pass.
  • Build and vet; compile package normal and race suites; each new test repeated 100 times under race; dependent Top/MergeTop suites; planner direction/pagination/INCLUDE controls pass.
  • Million-row fixture: vecf32(1024), lists=1024, probe_limit=5, two CNs, large text columns, two POST LIMIT200 branches. All 30 executions return the same 400-row multiset and match the independently established selected-bucket result oracle. Physical plan retains two CNs and has ordered candidate merging before the join.
  • Public SQL controls cover POST pagination/zero/empty, INCLUDE covered and row-fetch paths, residual filters, and repeated prepared execution. Cancelling an active POST query returns context canceled, followed by a successful 400-row POST query.
  • An additional rare-filter INCLUDE expansion case returns empty on both the fixed binary and the clean base binary built in a detached worktree, using the same index/query. This existing boundary behavior is documented rather than changed by this hotfix.

Cost and scope

Global ranking must consume candidates from every partition instead of stopping on the first partition. It adds bounded candidate-selection work, while keeping the join input capped and leaving single-CN execution unchanged. In six warm runs per version on the same fixture and cluster, median latency was 8.26 s on the incorrect baseline and 10.51 s with the fix (about 27% higher). This is a small sequential sample, not a statistically controlled benchmark or a claim of zero overhead. Both versions used two excluded warmups; no concurrent builds/tests ran during these measurements.

Based on v4.2.1-hotfix at 9bf92dc56bc2d3956500425e95f502642e09ae9d. The million-row test reuses the existing index built on 4.0-dev. No changes to NaN handling, equal-score tie-breaking, index training, or main's newer IVF architecture are included.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Sep 15, 2026
@XuPeng-SH
XuPeng-SH merged commit 115c227 into matrixorigin:v4.2.1-hotfix Sep 15, 2026
4 of 6 checks passed

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复核结论:本次代码未发现需要阻断的新增正确性/回归问题。PR 已合入 v4.2.1-hotfix(115c227239),因此记录事后 review 结论,不再提交合并前审批。已确认合入后的 tree 与本次 reviewed head 一致。

范围:9bf92dc56bc2d3956500425e95f502642e09ae9d → b65c1ff,全部 2 个文件 / 264 行新增;独立 review worktree 无改动。普通定点修复,不触发大型设计门禁。

检查结果:

  • 对应 #28943 的跨 CN 候选抢占问题,local Top + MergeTop 在 projection 和原 global limit 前按原始 score 选全局候选,后到分区的更优候选不会再仅因到达顺序被截掉。
  • 原始输出 score 固定为第 2 列 float64;INCLUDE payload 仍整体携带。DESC 在 planner 已禁用 ANN rewrite,不能据硬编码 ASC 推出降序回归。
  • 单 CN、runtime-filter 本地消费者、非只读 workspace、ForceOneCN 的原回退边界未改变;候选 LIMIT 和外层分页预算未修改。planner 的 limit 边界阻止上层过滤直接下推,剩余业务过滤仍按既有 POST 语义处理。
  • UT 不仅比对计划文本,也执行实际生成的 Top/MergeTop,对照独立全局排序,覆盖空/零/边界、不同到达顺序、NULL payload 和 Reset 复用。
审计 结论
Q1 清理 复用既有 operator Reset/Free 与 pipeline cleanup,未引入独立后台资源或新清理责任
Q2 等待 Merge/Connector 沿既有 context/terminal 信号退出;新增全局排序需要消费各分区,这是预期行为
Q3 增长 候选选择受 K 限制,已有 Top 大 K spill/清理路径;不是零额外内存或零性能成本

验证边界:本次运行 diff --check / 新 UT 文件 gofmt 检查并检查上述源码调用链;审阅 PR 提供的 normal/race、基线反例、双 CN SQL/取消及性能验证说明,没有在本次 review 重跑这些重型测试,也没有将说明冒充本次实测。作者记录样本延迟中位数从 8.26s 到 10.51s(约 +27%),是需要保留的性能代价,而非无回归承诺。

另查 Iceberg 红色 job 104411868668:实际退出点是拉取 minio/mc 被 Docker registry 拒绝,未到相关 MO 查询验证;不能据此认定本 PR 导致向量内核失败,也不能宣称 CI 全绿。

XuPeng-SH added a commit that referenced this pull request Nov 2, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #27740 and #28943.

## What this PR does / why we need it:

Backport two existing fixes to `release/v4.2.1-hotfix-20261026`, in
their original order:

- `9bf92dc56b` (#27777): skip directory markers and unsupported entries
during ETL merge; return an error instead of panicking on unsupported
reader paths.
- `115c227239` (#28945): rank multi-CN IVF candidates by distance before
applying the global candidate limit, preserving better candidates from
later streams.

Both cherry-picks apply without conflicts and retain identical patch
IDs. Only the original four files change.

Validation on this release base: full export, compile, Top and MergeTop
package tests in normal and race modes; IVF planner
direction/pagination/INCLUDE controls; incremental lint, vet and
formatting. Existing multi-CN IVF BVT: 26/26 statements pass twice on
one local two-CN cluster, with schema cleanup checked after each run.

IVF global ranking consumes all emitted partition candidates and adds
sorting work. The source PR reported about 27% higher median latency on
one historical million-row fixture; that benchmark was not rerun here.
The local BVT is a topology smoke test; deterministic competing-stream
ordering is covered by generated-operator tests. CI is pending.

---------

Co-authored-by: GreatRiver <[email protected]>
Co-authored-by: aptend <[email protected]>
Co-authored-by: iamlinjunhong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants