Repository navigation
Conversation
…in#23969) processOrder was clearing ctr.ps at the end, causing processValueFunc to treat all rows as a single partition. Remove the erroneous ctr.ps = nil since cleanup is already handled in processFunc.
There was a problem hiding this comment.
Pull request overview
Fixes a bug in the window operator where value window functions (LAG/LEAD/FIRST_VALUE/LAST_VALUE/NTH_VALUE) could lose PARTITION BY boundaries after ORDER processing, causing rows to be treated as a single partition.
Changes:
- Stop clearing
ctr.ps(partition boundaries) at the end ofprocessOrder, so subsequent value window function evaluation can use it. - Add distributed SQL test coverage for LAG/LEAD with multiple offsets, default values, and PARTITION BY + ORDER BY.
- Update expected results accordingly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/sql/colexec/window/window.go | Preserves computed partition boundaries across processOrder → processFunc for value window functions. |
| test/distributed/cases/window/value_window_functions.sql | Adds regression tests for LAG/LEAD offsets/defaults and partitioned evaluation. |
| test/distributed/cases/window/value_window_functions.result | Records expected outputs for the new regression cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1 task done
ghost
approved these changes
Mar 27, 2026
aunjgr
approved these changes
Mar 27, 2026
This branch was previously deployed
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) does this PR fix?
Fixes #23969
What this PR does
processOrderwas clearingctr.ps(partition boundaries) at the end of the method. WhenprocessValueFunc(which handles lag/lead/first_value/last_value/nth_value) was called afterwards,ctr.pswas alreadynil, so all rows were treated as a single partition.The fix removes the erroneous
ctr.ps = nilat the end ofprocessOrder. The cleanup ofctr.psis already handled inprocessFuncafter the value function results are computed.Non-value window functions (rank, row_number, etc.) were not affected because
processFuncrebuildsctr.psinternally for those cases.BVT
Added test cases covering: