Skip to content

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

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/28943-conservative-4.2-dev
Sep 16, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
iamlinjunhong:codex/28943-conservative-4.2-dev

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:

In multi-CN IVF search, candidates were merged without global distance ordering before the global LIMIT. The result could therefore depend on CN arrival order, and a worse early batch could consume the candidate budget before better candidates arrived.

At the existing multi-CN compiler boundary, this change reuses the existing Top/MergeTop operators to rank the raw IVF distance column before projection and the original global limit. The fix is limited to 17 production lines and preserves the single-CN path, uncapped path, partition dispatch, and candidate-budget guards.

Validation

  • Focused compiler regression tests cover 1/2/3 CNs, empty/short/exact-size inputs, zero/one/bounded caps, reversed arrival order, later better batches, nullable/string payloads, and Reset reuse with memory cleanup.
  • The same boundary check fails against the pre-fix 4.2-dev ancestor and passes with this change.
  • Focused tests pass normally; the result test passes 100 repetitions under -race.
  • The owning pkg/sql/compile package and dependent top/mergetop packages pass; go list, go vet, formatting/diff checks, and incremental lint pass.
  • The multi-CN distributed vector BVT passes twice on the rebased branch: 33/33 cases, 100% success each run.

Scope

This is a conservative 4.2-dev backport of the 4.2.1 fix. It changes candidate ordering only when a bounded multi-CN IVF limit is present; planner, index format, protocol, and single-CN execution are unchanged.

@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 16, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 16, 2026
@XuPeng-SH
XuPeng-SH merged commit d2a3391 into matrixorigin:4.2-dev Sep 16, 2026
49 of 51 checks passed

This branch was previously deployed

1 inactive deployment
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 size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants