Skip to content

fix(vector): handle empty reversed prefix-between ranges - #29645

Merged
mergify[bot] merged 1 commit into
matrixorigin:mainfrom
LeftHandCold:fix/prefix-between-empty-range-29644
Oct 6, 2026
Merged

mergify[bot] merged 1 commit into
matrixorigin:mainfrom
LeftHandCold:fix/prefix-between-empty-range-29644

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:

Persisted, sorted secondary-index filtering can receive reversed Prepared
BETWEEN bounds. CollectOffsetsByPrefixBetweenFactory searches the lower and
upper positions independently, but only rejects start == end. When the
upper position precedes the lower position, make([]int64, end-start) panics
and a valid SELECT returns Error 20101 instead of an empty result.

Reject start >= end before allocation. This is the same empty-selection
invariant already used by the neighboring prefix-range helper. Keep both
existing search comparisons unchanged: rejecting bytewise reversed bounds
before searching would incorrectly discard valid shorter-upper-prefix ranges.
Normal nonempty selections retain the same searches, allocation and offsets.
No planner, parameter conversion, index format, cache or distributed execution
change is included.

Extend the existing six-key unit fixture with forward/equal/short-upper-prefix,
reversed, missing and empty-vector cases, checking explicit expected offsets
and the existing linear helper. Add a self-contained 256-row persisted-index
BVT for reused and fresh SQL PREPARE handles, equal/overlapping/NULL bindings,
a mixed empty/nonempty OR, and literal/no-secondary-index controls.

This is a longstanding component boundary defect, not a proven recent
regression: the missing guard exists in #14893 (March 2024), and the actual
SQL panic also reproduces on the September 30, 2026 4.2 image 28f1f02.
MOTR #215 added the reversed-bound probe on October 5. The earliest release
where this exact SQL plan became reachable has not been bisected.

Tested with:

  • Fresh Main base c65991043b10fb39988d45b72af1485560ac5433 plus this patch;
    matching native artifacts built locally and on the isolated Linux test host.
  • .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s -run '^TestCollectOffsetsByPrefixBetweenFactory$' ./pkg/container/vector:
    the added reversed case panics without the production fix; all 13 subtests
    pass with it, both on macOS arm64 and Linux amd64.
  • Complete ./pkg/container/vector tests pass on both platforms; complete
    ./pkg/objectio tests and go vet ./pkg/container/vector ./pkg/objectio
    pass locally with matching CGo settings.
  • The original real binary-protocol int64 probe on a 32,768-row persisted
    secondary-index fixture: all nine result checks match an independent
    finite-domain oracle on the fixed Main binary. Includes forward, reversed,
    NULL, out-of-INT32, rebind/recovery, SQL PREPARE, literal and no-index cases.
  • Official mo-tester normal comparison (not result recording) on the isolated
    host: the new BVT fails on exactly three queries on the incident Main image;
    fixed Main passes 37/37 statements twice on the same instance, with zero
    ignored/abnormal statements and zero BVT database residue after each run.
  • SQL remains usable after the protocol probe and first BVT. The owned test
    container remained running without OOM and exited 0 after deliberate stop.
  • Complete self-review and git diff --check: no unresolved blockers. Valid
    ranges gain no additional scan, allocation, copy, synchronization or I/O.

This PR targets Main only. Unrelated Prepared performance/type-normalization
failures in #29606 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 →

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review 结论:APPROVE recommendation,未发现 blocking finding。

范围:base/merge-base c659910 → HEAD cef0b72;四个文件的全部改动已审查。属于局部 R2 SQL 结果/错误合同修复,不引入新设计、状态或资源机制。

正确性与回归:

  • 生产改动仅把 start == end 扩展为 start >= end。新增处理的 start > end 原本会用负长度分配并 panic;对已排序数据,两个搜索谓词选出的交集 [start,end) 此时确实为空。所有正常非空区间的搜索、分配和 offsets 保持不变。
  • 没有提前按原始边界字节比较拒绝区间,因此 lower=1221、upper=12 这样的较短上界前缀仍返回 offsets 3,4。等值前缀、等值 key、缺失值和空向量也有明确 oracle。
  • 已跟踪 legacy PKFilter、ObjectIO cached search、OR term union、block reader 和 PK-change 消费链:空 offsets 表示零命中,OR 的另一有效分支不会丢失;Top-K 的空结果规范化也不会把 nil 误当成全选。
  • 正常业务没有新增逐行扫描、拷贝、分配、锁、goroutine、缓存、I/O 或参数转换。索引格式及 planner/pruning 策略不变;未发现具体性能回归路径。

证据按 mo-self-review/mo-dev 的有效性规则复用,没有重跑重型测试:四个文件 SHA256 与保留的测试源码证据逐项一致;核验了 13 个具名 UT 的修复前 panic/修复后通过、macOS/Linux vector 完整包通过、objectio 包及 vet 记录、真实 binary-int64 独立有限域 oracle 的九项结果,以及持久化基表/隐藏索引 BVT。旧版本该 BVT 的三条反向 indexed PREPARE 查询实际触发同一 makeslice 栈;修复后正常比较模式两次均 37/37,ignored/abnormal=0,并有清理后零数据库残留记录。本轮 Go 1.26.4 gofmt 和 git diff --check 通过,审查 worktree 干净。

这能修复 #29644 的反向 Prepared BETWEEN panic,但不宣称解决 #29606 的其他类型归一化或性能问题。GitHub Shared Build 和 UT Coverage 已成功,其余 UT/SCA/BVT 检查仍在运行;本 review 不表示全 CI 已绿,也未等待或重跑它们。

当前认证账号与 PR 作者相同,GitHub 不允许自审 APPROVE,因此以 COMMENT review 记录通过建议,不是正式 Approval。

@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 cef0b72, against main c659910. No blocking findings.

All four changed files were reviewed. The sorted factory owns the [start,end) selection invariant; changing start == end to start >= end prevents the confirmed negative-length allocation while preserving both existing search predicates. Shorter upper prefixes can still form valid selections, so the position-based correction is preferable to an argument-level byte ordering rejection. Cached ObjectIO search and OR union handle empty selections correctly; the change does not turn nil into an unrestricted match.

Normal nonempty paths add no scan, copy, allocation, I/O, synchronization or persistent format change. The production correction is +1/-1. Tests extend the existing helper fixture with explicit expected offsets, and add a small persisted-index SQL fixture with orthogonal prepared/reuse/reversed/NULL/overlap/mixed-OR controls. Test increment +177/-19 and zero documentation changes were assessed separately; no duplicate execution path or unnecessary abstraction was added.

I verified the patch against the 4.2 counterpart and checked Main's actual ObjectIO consumer rather than assuming its surrounding code is identical. The stable patch-id matches. Reused the recorded before/after panic and independent result-oracle evidence in #29644, the author's current-head helper/package/BVT validation, and current-head green SCA, UT, coverage and multi-CN BVT. No new runtime benchmark claim is made; the unchanged valid-range work follows directly from the one-condition diff.

Comment audit: the existing self-review is a COMMENT recommendation, not an approval; no unresolved inline threads or human change requests exist. This review supplies the independent approval. #29606's separate numeric-normalization/performance scope remains outside this repair.

@mergify mergify Bot added the queued label Oct 6, 2026
@mergify

mergify Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-06 06:53 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-10-06 06:53 UTC · at 5c449cfe837ac90667c2a85ee3f442263440552c · squash

This pull request spent 12 seconds in the queue, including 1 second running CI.

Required conditions to merge

@mergify
mergify Bot merged commit 5c449cf into matrixorigin:main Oct 6, 2026
@mergify mergify Bot removed the queued label Oct 6, 2026
XuPeng-SH pushed a commit that referenced this pull request Oct 6, 2026
…29647)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] 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.

This branch was previously deployed

1 inactive deployment
ci — cef0b721 Deployed Oct 6, 2026 by mergify[bot]
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