Repository navigation
fix(window): support split aggregate results - #25852
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
BVT coverage added in commit Validation with the local
The BVT crosses the 8192/8193 chunk boundary and checks partitioned/non-partitioned Window paths, SUM and ROW_NUMBER, total row/value checksums, and row-to-window-result alignment. |
|
Review notes for approved head
Local validation: full aggexec/window/timewin tests passed; focused new tests passed with |
LeftHandCold
left a comment
There was a problem hiding this comment.
发现 1 个需要修复的资源生命周期问题:TimeWin 支持 split result 后,非最终 flush 会覆盖仍持有 DISTINCT 状态的旧聚合器,造成随中间批次持续累积的 mpool 泄漏。详情见 inline comment。
gouhongshen
left a comment
There was a problem hiding this comment.
Codex automated review
No defects found. The merge preserves row order/types/nulls and transfers vector ownership safely; TimeWin also releases flushed executor state and prior output batches correctly. Local focused tests were blocked by absent CGo third-party headers; PR CI is green.
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#25813 ## What this PR does / why we need it: `AggFuncExec.Flush` returns multiple physical vectors after its result exceeds the aggregation chunk size (8192 rows). `Window` treated that internal storage detail as an unsupported logical result and failed the query. `TimeWin` had copied the same single-vector assumption and was vulnerable when one flush cohort crossed the chunk boundary. This PR introduces a shared aggregate-result merge primitive and uses it in both single-batch consumers: - preserve the common single-chunk path as zero-copy; - reuse the first vector and pre-grow it once for multi-chunk results; - append complete chunks in order through `UnionBatch`, preserving fixed values, NULLs, grouping metadata, and varlen areas; - consume all result vectors on every path, including nil chunks, inconsistent types, allocation failure, and append failure; - keep `Group` unchanged because its physical chunks intentionally correspond to separate output batches. The regression matrix covers ordinary SUM, DECIMAL(20,2) SUM from the issue, ROW_NUMBER's dedicated window executor, partitioned and non-partitioned Window input paths, TimeWin, fixed and varlen vectors, NULLs, multiple chunks, invalid results, off-heap OOM, and mpool cleanup. Performance on Apple M4 with production-style off-heap vectors: - one chunk: ~1.36 ns/op, zero copy, 0 Go allocations; - two fixed chunks: ~10.2 us/op; - four fixed chunks: ~19.3 us/op; - two varlen chunks: ~4.8 us/op. Multi-chunk work is linear in the result bytes and performs one capacity plan instead of incremental or per-row growth. Multi-chunk Window/TimeWin queries previously returned an error, so the existing successful path has no regression. Validation: - `go test ./pkg/sql/colexec/... -count=1 -timeout=300s` with the repository CGo/rpath settings - focused regression tests for Window, TimeWin, and the shared merge helper - focused regression matrix under `go test -race` - `go vet ./pkg/sql/colexec/aggexec ./pkg/sql/colexec/window ./pkg/sql/colexec/timewin` - `BenchmarkMergeSplitResult` with fixed/varlen and 1/2/4 chunk cases
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#25813 ## What this PR does / why we need it: `AggFuncExec.Flush` returns multiple physical vectors after its result exceeds the aggregation chunk size (8192 rows). `Window` treated that internal storage detail as an unsupported logical result and failed the query. `TimeWin` had copied the same single-vector assumption and was vulnerable when one flush cohort crossed the chunk boundary. This PR introduces a shared aggregate-result merge primitive and uses it in both single-batch consumers: - preserve the common single-chunk path as zero-copy; - reuse the first vector and pre-grow it once for multi-chunk results; - append complete chunks in order through `UnionBatch`, preserving fixed values, NULLs, grouping metadata, and varlen areas; - consume all result vectors on every path, including nil chunks, inconsistent types, allocation failure, and append failure; - keep `Group` unchanged because its physical chunks intentionally correspond to separate output batches. The regression matrix covers ordinary SUM, DECIMAL(20,2) SUM from the issue, ROW_NUMBER's dedicated window executor, partitioned and non-partitioned Window input paths, TimeWin, fixed and varlen vectors, NULLs, multiple chunks, invalid results, off-heap OOM, and mpool cleanup. Performance on Apple M4 with production-style off-heap vectors: - one chunk: ~1.36 ns/op, zero copy, 0 Go allocations; - two fixed chunks: ~10.2 us/op; - four fixed chunks: ~19.3 us/op; - two varlen chunks: ~4.8 us/op. Multi-chunk work is linear in the result bytes and performs one capacity plan instead of incremental or per-row growth. Multi-chunk Window/TimeWin queries previously returned an error, so the existing successful path has no regression. Validation: - `go test ./pkg/sql/colexec/... -count=1 -timeout=300s` with the repository CGo/rpath settings - focused regression tests for Window, TimeWin, and the shared merge helper - focused regression matrix under `go test -race` - `go vet ./pkg/sql/colexec/aggexec ./pkg/sql/colexec/window ./pkg/sql/colexec/timewin` - `BenchmarkMergeSplitResult` with fixed/varlen and 1/2/4 chunk cases
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes matrixorigin#25813 ## What this PR does / why we need it: `AggFuncExec.Flush` returns multiple physical vectors after its result exceeds the aggregation chunk size (8192 rows). `Window` treated that internal storage detail as an unsupported logical result and failed the query. `TimeWin` had copied the same single-vector assumption and was vulnerable when one flush cohort crossed the chunk boundary. This PR introduces a shared aggregate-result merge primitive and uses it in both single-batch consumers: - preserve the common single-chunk path as zero-copy; - reuse the first vector and pre-grow it once for multi-chunk results; - append complete chunks in order through `UnionBatch`, preserving fixed values, NULLs, grouping metadata, and varlen areas; - consume all result vectors on every path, including nil chunks, inconsistent types, allocation failure, and append failure; - keep `Group` unchanged because its physical chunks intentionally correspond to separate output batches. The regression matrix covers ordinary SUM, DECIMAL(20,2) SUM from the issue, ROW_NUMBER's dedicated window executor, partitioned and non-partitioned Window input paths, TimeWin, fixed and varlen vectors, NULLs, multiple chunks, invalid results, off-heap OOM, and mpool cleanup. Performance on Apple M4 with production-style off-heap vectors: - one chunk: ~1.36 ns/op, zero copy, 0 Go allocations; - two fixed chunks: ~10.2 us/op; - four fixed chunks: ~19.3 us/op; - two varlen chunks: ~4.8 us/op. Multi-chunk work is linear in the result bytes and performs one capacity plan instead of incremental or per-row growth. Multi-chunk Window/TimeWin queries previously returned an error, so the existing successful path has no regression. Validation: - `go test ./pkg/sql/colexec/... -count=1 -timeout=300s` with the repository CGo/rpath settings - focused regression tests for Window, TimeWin, and the shared merge helper - focused regression matrix under `go test -race` - `go vet ./pkg/sql/colexec/aggexec ./pkg/sql/colexec/window ./pkg/sql/colexec/timewin` - `BenchmarkMergeSplitResult` with fixed/varlen and 1/2/4 chunk cases
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #25813
What this PR does / why we need it:
AggFuncExec.Flushreturns multiple physical vectors after its result exceeds the aggregation chunk size (8192 rows).Windowtreated that internal storage detail as an unsupported logical result and failed the query.TimeWinhad copied the same single-vector assumption and was vulnerable when one flush cohort crossed the chunk boundary.This PR introduces a shared aggregate-result merge primitive and uses it in both single-batch consumers:
UnionBatch, preserving fixed values, NULLs, grouping metadata, and varlen areas;Groupunchanged because its physical chunks intentionally correspond to separate output batches.The regression matrix covers ordinary SUM, DECIMAL(20,2) SUM from the issue, ROW_NUMBER's dedicated window executor, partitioned and non-partitioned Window input paths, TimeWin, fixed and varlen vectors, NULLs, multiple chunks, invalid results, off-heap OOM, and mpool cleanup.
Performance on Apple M4 with production-style off-heap vectors:
Multi-chunk work is linear in the result bytes and performs one capacity plan instead of incremental or per-row growth. Multi-chunk Window/TimeWin queries previously returned an error, so the existing successful path has no regression.
Validation:
go test ./pkg/sql/colexec/... -count=1 -timeout=300swith the repository CGo/rpath settingsgo test -racego vet ./pkg/sql/colexec/aggexec ./pkg/sql/colexec/window ./pkg/sql/colexec/timewinBenchmarkMergeSplitResultwith fixed/varlen and 1/2/4 chunk cases