Repository navigation
fix: prevent H0 aggregate spill panic - #26736
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? |
iamlinjunhong
left a comment
There was a problem hiding this comment.
Reviewed the complete diff from base c31b46d to head 2d14b8e. No P0-P3 findings.
The H0 guard matches the execution invariant: an ungrouped aggregate has one aggregate group and no grouping hash table, so MergeGroup must not enter generic hash-partition spill. H8/HStr group-count and byte-threshold behavior remains unchanged, memory accounting still runs, and ordered GROUP_CONCAT retains its aggregate-owned spill path. The tests cover low and byte thresholds, ordered-aggregate spill, the real partial Group -> MergeGroup hand-off, Reset reuse, mpool cleanup, and the public SQL regression. CI evidence for this head includes successful UT/coverage/SCA and group_h0_spill.sql (11/11 statements).
2d14b8e to
6173a85
Compare
|
Post-rebase review against main The only conflict was the common insertion point in Fresh validation on head |
aptend
left a comment
There was a problem hiding this comment.
Reviewed latest HEAD. The H0 guard matches the execution invariant: scalar aggregation has no grouping hash table and therefore cannot enter generic hash-partition spill. H8/HStr spill behavior and memory accounting remain intact, ordered GROUP_CONCAT keeps aggregate-owned spill, and the regressions cover Group to MergeGroup hand-off, Reset reuse, and mpool cleanup. No code blocker found.
Fixes matrixorigin#26453 ## Summary - skip generic hash-table spill decisions for H0 scalar aggregates, which have no grouping hash table - preserve ordered GROUP_CONCAT H0 spill through its aggregate executor - add H0 threshold, Group -> MergeGroup reuse, and SQL BVT regressions ## Validation - .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s ./pkg/sql/colexec/group - .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s ./pkg/sql/colexec/group - focused H0 regressions: -race -count=100 each - GOWORK=off go build/vet -mod=readonly ./pkg/sql/colexec/group ./pkg/sql/compile - dependent compile test: TestRefreshGroupConcatMaxLenForPreparedCompileReuse
Fixes matrixorigin#26453 ## Summary - skip generic hash-table spill decisions for H0 scalar aggregates, which have no grouping hash table - preserve ordered GROUP_CONCAT H0 spill through its aggregate executor - add H0 threshold, Group -> MergeGroup reuse, and SQL BVT regressions ## Validation - .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s ./pkg/sql/colexec/group - .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s ./pkg/sql/colexec/group - focused H0 regressions: -race -count=100 each - GOWORK=off go build/vet -mod=readonly ./pkg/sql/colexec/group ./pkg/sql/compile - dependent compile test: TestRefreshGroupConcatMaxLenForPreparedCompileReuse
Fixes matrixorigin#26453 ## Summary - skip generic hash-table spill decisions for H0 scalar aggregates, which have no grouping hash table - preserve ordered GROUP_CONCAT H0 spill through its aggregate executor - add H0 threshold, Group -> MergeGroup reuse, and SQL BVT regressions ## Validation - .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=120s ./pkg/sql/colexec/group - .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=240s ./pkg/sql/colexec/group - focused H0 regressions: -race -count=100 each - GOWORK=off go build/vet -mod=readonly ./pkg/sql/colexec/group ./pkg/sql/compile - dependent compile test: TestRefreshGroupConcatMaxLenForPreparedCompileReuse
## What type of PR is this? - [ ] API-change - [x] BUG - [ ] Improvement - [ ] Documentation - [ ] Feature - [ ] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Related to #32233 ## What this PR does / why we need it: On `4.2-dev`, running the first scalar aggregate on a freshly created table while the session holds a low debug `agg_spill_mem` threshold panics with a nil pointer dereference and surfaces internal error 20101: ```sql CREATE TABLE fresh_count (id INT); INSERT INTO fresh_count VALUES (1); SET @@agg_spill_mem = 256; SELECT COUNT(*) FROM fresh_count; -- panic in group.(*container).needSpill ``` **Root cause** `pkg/sql/colexec/group/helper.go` `needSpill()` evaluates the debug group-count mode (`spillMem < 10000`) by dereferencing `ctr.hr.Hash.GroupCount()` without checking the container mode. An H0 container (no GROUP BY) never builds the grouping hash table, so `ctr.hr.Hash` is nil and the call panics. MergeGroup reaches the same call on its H0 merge path, which is why plain `SELECT COUNT(*)` on a fresh table triggers it. Values of 10000 and above are a byte threshold and were never affected. This is the 4.2-dev counterpart of main PR #26736 (issue #26453): generic group-spill partitioning requires the grouping hash table, H0 holds exactly one aggregate group, and aggregates that bring their own H0 spill behavior (such as ordered GROUP_CONCAT) keep spilling through their own executors. **Exact change** - `pkg/sql/colexec/group/helper.go`: `needSpill()` returns false for H0 before either threshold branch; the analyzer memory accounting and the grouped (H8/HStr) threshold semantics are unchanged. - `pkg/sql/colexec/group/group_test.go`: ports of the #26736 unit regressions: - `TestH0NeverRequestsGenericGroupSpill`: H0 requests no generic spill at the 256 group-count threshold and at a 10 KiB byte threshold with memory retained in the pool; `SetMemUsed` accounting is still published. - `TestH0OrderedGroupConcatSpillsIndependently`: an H0 ordered GROUP_CONCAT still spills (SpillRows > 0) with zero generic `GroupSpillWriteCalls`. - `TestMergeGroupH0SkipsGenericSpillAndReuses`: the real Group → MergeGroup H0 hand-off over multiple partial batches returns the correct scalar count, performs no generic spill, stays H0 with an empty hash, and resets cleanly between generations. - `test/distributed/cases/qexec/group_h0_spill.sql` + `.result`: BVT that creates a fresh one-row table, runs scalar COUNT at `agg_spill_mem = 256` and then at the normal 536870912 byte threshold on one connection, and resets the variable afterwards. **Issue-to-test proof (red/green)** - With the 4.2-dev base `helper.go` restored, the three focused UTs panic with the reported `runtime error: invalid memory address or nil pointer dereference` at `needSpill` - the exact stack from issue #32233. - With the fix, the same tests pass; the grouped spill behavior exercised by the package's existing tests is unchanged and the full package passes under `-race`. - End-to-end SQL on a locally built `mo-service` from this branch (1 LOG / 1 TN / 1 CN on isolated ports): the issue's exact sequence returns `1` for 3/3 fresh tables at `agg_spill_mem = 256`, `1` at 536870912, the grouped control returns `1 | 1`, and an empty-input scalar COUNT returns `0`; no internal error or panic appears in the service log. **Test commands** ``` .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=600s \ -run 'TestH0NeverRequestsGenericGroupSpill|TestH0OrderedGroupConcatSpillsIndependently|TestMergeGroupH0SkipsGenericSpillAndReuses' \ ./pkg/sql/colexec/group # red on base, green with fix .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=100 -timeout=600s \ -run 'TestH0NeverRequestsGenericGroupSpill|TestH0OrderedGroupConcatSpillsIndependently|TestMergeGroupH0SkipsGenericSpillAndReuses' \ ./pkg/sql/colexec/group # pass .agents/skills/mo-dev/scripts/mo-cgo-test -race -count=1 -timeout=1200s \ ./pkg/sql/colexec/group # full package passes .agents/skills/mo-dev/scripts/mo-cgo-test -v -count=1 -timeout=600s \ -run TestRefreshGroupConcatMaxLenForPreparedCompileReuse \ ./pkg/sql/compile # dependent package passes GOWORK=off go build ./pkg/sql/colexec/group ./pkg/sql/compile # clean GOWORK=off go vet ./pkg/sql/colexec/group ./pkg/sql/compile # clean ``` The new BVT pair runs in the CI mo-tester matrix. **Residual risk** Low. `agg_spill_mem` values below 10000 are a debug group-count mode rather than a byte threshold, and the guard adds an H0 early return before it; H8/HStr grouping, distinct aggregate spilling rules and aggregate-owned spilling are untouched. The `.sql`/`.result` BVT pair was compared against the observed output on a local instance; the full mo-tester baseline remains a CI job. Upstream context: main fixed the same defect in PR #26736 for issue #26453; this PR carries that decision to `4.2-dev` with the same regressions. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]>
Fixes #26453
Summary
Validation