Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colexec: call SetLength on output batches for window functions #66398

Merged
merged 1 commit into from
Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/sql/colexec/colexecwindow/buffered_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,18 @@ func (b *bufferedWindowOp) Next() coldata.Batch {
// first of the tuples yet to be processed was somewhere in the batch.
b.processingIdx = 0
}
// Although we didn't change the length of the batch, it is necessary to
// set the length anyway (to maintain the invariant of flat bytes).
output.SetLength(output.Length())
return output
}
if b.currentBatch.Length() > 0 {
b.windower.processBatch(b.currentBatch, b.processingIdx, b.nextPartitionIdx)
if b.nextPartitionIdx >= b.currentBatch.Length() {
// This was the last batch and it has been entirely filled.
// This was the last batch and it has been entirely filled. Although
// we didn't change the length of the batch, it is necessary to set
// the length anyway (to maintain the invariant of flat bytes).
b.currentBatch.SetLength(b.currentBatch.Length())
b.state = windowFinished
return b.currentBatch
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/window
Original file line number Diff line number Diff line change
Expand Up @@ -3988,3 +3988,19 @@ ORDER BY x
88.0 7527.842222222222222222222 836.42691358024691358 940.98027777777777778 28.921046204801217626 30.675401835636607970
88.0 7527.842222222222222222222 836.42691358024691358 940.98027777777777778 28.921046204801217626 30.675401835636607970
89.0 8885.844 888.5844 987.316 29.809132828715430446 31.421584937746218024

# Regression test for #64793. The output bytes column should not have decreasing
# offsets.
statement ok
CREATE TABLE t64793 (b TEXT)

statement ok
INSERT INTO t64793 VALUES
('alpha'),
(NULL::TEXT)

query T
SELECT lag(b, 0) OVER (ORDER BY b DESC) FROM t64793 ORDER BY b
----
NULL
alpha