Skip to content

[4.2-dev] fix(vector): handle empty reversed prefix-between ranges - #29647

Merged
XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
LeftHandCold:backport/29645-prefix-between-4.2-dev
Oct 6, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:4.2-devfrom
LeftHandCold:backport/29645-prefix-between-4.2-dev

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #29644

What this PR does / why we need it:

Cherry-pick of Main PR #29645, commit
cef0b7215fd10bd31ec73c19c1ddf9f7889cf39a, onto fresh 4.2-dev
e93a5d20524d17e2a89100ce609cf67a45d13aa6. Applied with -x, without
conflicts or branch-specific adaptations. The Main PR was still open when
this user-requested backport was prepared; its patch content is identical.

The same reversed Prepared BETWEEN panic has been observed in the 4.2 Daily
and independently reproduced on an older 4.2 image. Sorted persisted-index
filtering independently searches lower/upper positions, but previously only
rejected start == end. Reversed positions permit a negative-length
selection allocation and a recovered SQL panic instead of an empty result.

Change the existing guard to start >= end. Both binary-search comparisons
remain unchanged, including valid shorter-upper-prefix semantics. Previously
valid nonempty ranges keep the same searches, allocation and returned offsets.
No parameter conversion, planner, cache, distributed execution, index format
or other Main change is backported.

The original extended six-key helper UT and minimal 256-row persisted-index
Prepared BVT are included unchanged. The BVT covers reused/fresh handles,
forward/equal/overlapping/NULL bindings, mixed empty/nonempty OR ranges and
literal/no-secondary-index controls.

Tested with:

  • Exact backport head 1d14bc3476ec3d491cb71c765e0e2258c02f92c5 on an isolated
    Linux amd64 instance on 50; fresh branch-matching CGo artifacts and complete
    make build succeeded with Go 1.26.4.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestCollectOffsetsByPrefixBetweenFactory$' ./pkg/container/vector:
    all 13 subtests pass.
  • Complete ./pkg/container/vector and ./pkg/objectio normal tests pass;
    go vet -mod=readonly ./pkg/container/vector ./pkg/objectio passes with
    matching CGo settings.
  • Real binary-protocol int64 and SQL PREPARE probe on a 32,768-row persisted
    secondary index: reversed ranges now return the independently expected empty
    result, and forward/NULL/rebind/recovery/literal/no-index controls are correct.
    All eight in-scope result-oracle checks pass.
  • The probe's separate outside-INT32 case retains the old 4.2 Error 1690;
    all seven non-reversed probe records match the historical 4.2 records exactly.
    This backport does not claim to repair type-normalization/overflow behavior.
  • Official mo-tester normal comparison, not result recording: 37/37 BVT
    statements pass twice on the same instance
    , zero ignored/abnormal statements,
    zero BVT database residue after each run, and SELECT 1 succeeds afterward.
  • Full four-file self-review, identical Main/backport patch-id and
    git diff --check: no unresolved blockers. No additional normal-range scan,
    copy, allocation, synchronization or I/O.

This is a narrowly scoped longstanding boundary-defect repair, not an
unvalidated broad Prepared-range optimization. Existing 4.2 numerical and
performance issues outside #29644 are not claimed to be fixed.

@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 →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

APPROVE for head 1d14bc3, against 4.2-dev e93a5d2. No blocking findings.

Reviewed all four changed files and the sorted/linear prefix helpers, byte comparison, cached ObjectIO term dispatch and OR union consumers. The first owner of the invariant is the sorted selection factory: independently computed [start,end) is empty whenever start >= end. The change closes the negative-length allocation at that boundary. Keeping the two search predicates intact preserves shorter-upper-prefix matches such as lower=1221/upper=12; rejecting bytewise reversed arguments before searching would be incorrect. Empty offsets contribute no rows to an OR union and do not erase the other term.

The design is proportionate: one condition, no extra state/validation layer, fallback scan, per-row work, allocation or format change. Normal nonempty ranges retain the same computation. Existing numeric/string range helpers already use this empty-range invariant. No new concurrency, persistent-data or upgrade contract is introduced.

Test review: the existing six-key fixture is extended rather than duplicated; explicit offset oracles cover forward/equal/short-upper-prefix/reversed/missing/empty cases and are supplemented by the linear helper. The 256-row persisted-index BVT covers fresh/reused handles, forward/reversed/recovery, NULL, overlap, mixed OR and literal/no-index controls, with cleanup. The expected rows were inspected independently. Implementation is +1/-1, tests +177/-19, documentation +0/-0; the test growth covers distinct boundaries.

Verified identical stable patch-id with Main #29645 and checked the branch-specific ObjectIO consumer contract. Reused the author's exact-backport before/after helper and SQL/BVT validation recorded in #29644, and the current-head successful SCA, UT, coverage and multi-CN BVT checks. Local native test execution was blocked by missing branch-matching libmo; it is not reported as a local pass. No blocking validation gap remains given the branch-specific execution evidence and current-head CI.

Comment audit: no human review or inline thread is outstanding; only the Qodo pause notice. Scope remains #29644, not the separate parameter normalization/performance work in #29606.

This branch was previously deployed

1 inactive deployment
ci — 1d14bc34 Deployed Oct 6, 2026 by XuPeng-SH
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 kind/test-ci 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