fix: eliminate O(n²) memory hotspot in value window functions#23963
Merged
mergify[bot] merged 8 commits intomatrixorigin:mainfrom Mar 26, 2026
Merged
fix: eliminate O(n²) memory hotspot in value window functions#23963mergify[bot] merged 8 commits intomatrixorigin:mainfrom
mergify[bot] merged 8 commits intomatrixorigin:mainfrom
Conversation
…ad/first_value/last_value/nth_value) Bypass AggFuncExec Fill/Flush path for WIN_VALUE functions. Instead, compute results directly via index lookup in the window operator: - lag/lead: O(n) partition-based index calculation with offset/default support - first_value/last_value: direct frame boundary lookup - nth_value: proper n-th element semantics (was broken, defaulting to first_value) Also fix valueWindowExec.Free() to actively clear frameValues/currentRowPosition, and fix Size() to account for slice headers, backing arrays and struct overhead.
f0a1e2c to
b396590
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Support non-const offset/n vectors (read per-row for lag/lead/nth_value) - Remove float type support from getInt64FromVec (only integer types) - Add uint64 overflow check (> MaxInt64 returns ok=false) - Shuffle all agg argument vectors in processOrder (not just Vec[0]) - Fix tests to use const vectors for offset/n parameters
- Use unsafe.Sizeof instead of hardcoded struct sizes in valueWindowExec.Size() - Add bat.Clean(mp) and mpool leak assertions to processValueFunc tests
aunjgr
approved these changes
Mar 26, 2026
Contributor
Merge Queue Status
This pull request spent 59 minutes 57 seconds in the queue, including 58 minutes 54 seconds running CI. Required conditions to merge
|
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #23962
What this PR does / why we need it:
Extract lag/lead/first_value/last_value/nth_value from the AggFuncExec/Fill/Flush path and compute results directly via index lookup in the window operator, eliminating O(n²) frame materialization.
Key changes: