Skip to content

fix(window): handle uint64 range bounds - #27568

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
Lundomn:fix/issue-27565-uint64-window-range
Aug 25, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
Lundomn:fix/issue-27565-uint64-window-range

Conversation

@Lundomn

@Lundomn Lundomn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #27565

What this PR does / why we need it:

Handle BIGINT UNSIGNED and BIT Window RANGE bounds without wrapping uint64 arithmetic or mapping out-of-domain bounds to the wrong ASC/DESC insertion boundary. This fixes low-key RANGE ... FOLLOWING frames that were incorrectly returned as empty and also covers subtraction underflow and addition overflow.

Validation

  • go test ./pkg/sql/colexec/window/... -count=1
  • go test -race ./pkg/sql/colexec/window/... -count=1
  • go vet ./pkg/sql/colexec/window/...
  • go test ./pkg/sql/colexec/... -count=1
  • git diff --check origin/main...HEAD
  • pkg/sql/colexec/window coverage: 84.4%
  • latest-main isolated SQL regression for ASC/DESC, zero offset, uint64 underflow/overflow, NULL peers, and empty frames
  • 500,010-row independent-reference regression repeated 3 times: 261,910 wrong rows before the fix, 0 after the fix

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

@aunjgr aunjgr 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.

Reviewed exact head a3027255760850f891e6dad6be95abfe8c7588f8 against merge base 249a458ba567b26d1818fb0496b449135cb05ef2.

The fix correctly separates finite uint64 arithmetic from conceptual below/above-domain bounds and maps those bounds to the proper insertion edge for both ASC and DESC. I checked all four start/end PRECEDING/FOLLOWING direction combinations, equality at zero, addition overflow, subtraction underflow, NULL peer confinement, and the shared BIT representation. The unit and SQL regressions provide independent boundary/result coverage. I found no blocking issue.

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

Deep review of exact head a3027255760850f891e6dad6be95abfe8c7588f8 against merge base 249a458ba567b26d1818fb0496b449135cb05ef2.

The fix closes #27565. uint64RangeBound computes addition/subtraction without wraparound, and outOfDomainRangeBoundary maps conceptual values below 0 or above MaxUint64 to the correct insertion boundary for both ASC and DESC. Using the same logic for BIT is correct because its stored comparison representation is uint64; a narrower BIT domain still maps an in-uint64 but out-of-column-domain target to the same end insertion point.

I checked the complete searchLeft/searchRight closure, peer and NULL handling, all valid PRECEDING/CURRENT/FOLLOWING combinations, zero offset, equality at zero, addition overflow, subtraction underflow, duplicates, and MaxUint64.

Independent validation:

  • a temporary big.Int oracle exhaustively compared 2 types × 2 directions × 5 offsets × 6 frame shapes × 10 rows (including duplicates, 0, and MaxUint64); every computed [start,end) matched;
  • the two new focused regressions and the independent oracle passed under race;
  • the full pkg/sql/colexec/window package passed normally and under race;
  • go list/build/vet, gofmt, and diff checks passed;
  • Q1-Q3: no new resource ownership, wait dependency, or accumulation; the added arithmetic is constant-time and allocation-free.

No blocking correctness, performance, or unhappy-path issue found.

@mergify mergify Bot added the queued label Aug 25, 2026
@mergify

mergify Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-08-25 07:55 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-08-25 08:55 UTC · at abf111e640ceac189a3979f33ef5ef743be7f3ea · squash

This pull request spent 59 minutes 27 seconds in the queue, including 59 minutes 5 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)

@aptend aptend 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.

Deep-reviewed exact head abf111e640ceac189a3979f33ef5ef743be7f3ea against exact base ae12701a888fac102e9641cc7cbb8706527366d8, including the complete feature diff and all review history (2 prior approvals, no inline comments or review threads). The merge from main adds no feature delta beyond the reviewed uint64 RANGE fix.

The new arithmetic correctly distinguishes subtraction underflow from addition overflow, and maps conceptual below/above-domain keys to the correct insertion edge for ASC and DESC. The same handling is valid for BIT’s uint64 comparison representation; NULL peer confinement remains outside the changed arithmetic.

Independent validation: a temporary big.Int oracle compared both uint64/BIT, ASC/DESC, offsets 0/1/5/MaxUint64, five valid PRECEDING/CURRENT/FOLLOWING frame shapes, and rows containing duplicates, zero, and MaxUint64; every computed [start,end) matched. The temporary test was removed. Full window package tests, focused race tests (10x), vet, formatting, and diff checks passed. No blocking issue found.

@mergify
mergify Bot merged commit e866c53 into matrixorigin:main Aug 25, 2026
25 of 26 checks passed
@mergify mergify Bot removed the queued label Aug 25, 2026
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Handle `BIGINT UNSIGNED` and `BIT` Window `RANGE` bounds without wrapping uint64 arithmetic or mapping out-of-domain bounds to the wrong ASC/DESC insertion boundary. This fixes low-key `RANGE ... FOLLOWING` frames that were incorrectly returned as empty and also covers subtraction underflow and addition overflow.

Approved by: @aunjgr, @XuPeng-SH, @aptend
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Handle `BIGINT UNSIGNED` and `BIT` Window `RANGE` bounds without wrapping uint64 arithmetic or mapping out-of-domain bounds to the wrong ASC/DESC insertion boundary. This fixes low-key `RANGE ... FOLLOWING` frames that were incorrectly returned as empty and also covers subtraction underflow and addition overflow.

Approved by: @aunjgr, @XuPeng-SH, @aptend
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Handle `BIGINT UNSIGNED` and `BIT` Window `RANGE` bounds without wrapping uint64 arithmetic or mapping out-of-domain bounds to the wrong ASC/DESC insertion boundary. This fixes low-key `RANGE ... FOLLOWING` frames that were incorrectly returned as empty and also covers subtraction underflow and addition overflow.

Approved by: @aunjgr, @XuPeng-SH, @aptend

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.

[Bug]: BIGINT UNSIGNED Window RANGE FOLLOWING returns empty frames for low keys

5 participants