Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters: Apple Silicon local test host
- OS type: macOS (arm64)
- Others: fresh single-CN MatrixOne instance, dedicated data directory and port;
the binary was built from a clean detached worktree at the commit above.
Actual Behavior
With agg_spill_mem in its documented low-threshold mode, a plain non-empty
COUNT(*) aggregate returns an internal nil-pointer panic instead of a query
result or a normal database error. The reproduction uses one ordinary table
with one row; it does not depend on joins, special data types, constraints, or
user spill files.
The error consistently starts at:
internal error: panic runtime error: invalid memory address or nil pointer dereference
github.com/matrixorigin/matrixone/pkg/sql/colexec/group.(*container).needSpill
pkg/sql/colexec/group/helper.go:784
Source inspection shows that the no-GROUP BY (H0) MergeGroup path has no
hash table, while needSpill unconditionally calls
ctr.hr.Hash.GroupCount() when the threshold is below 10,000.
Expected Behavior
COUNT(*) over a non-empty table should return the correct count regardless
of a valid agg_spill_mem setting. A no-GROUP BY aggregate must not attempt
to read hash-group state that is not created for that execution path.
Steps to Reproduce
create database spill_count_panic;
use spill_count_panic;
create table tiny_scalar (id int);
insert into tiny_scalar values (1);
set @@agg_spill_mem = 256;
select count(*) from tiny_scalar;Reproduction Result
On the clean main build, the SQL above failed 3/3 times with error 20101 and
the same group.(*container).needSpill nil-pointer stack. It did not leave
spill files, and the service remained usable for subsequent queries.
The same SQL with a normal threshold was a stable control:
set @@agg_spill_mem = 536870912;
select count(*) from tiny_scalar;
-- 1 (3/3)Additional low-threshold controls that returned 1 were SELECT SUM(id) and
SELECT COUNT(*) ... GROUP BY id, which narrows the failure to the ungrouped
COUNT MergeGroup path.
Duplicate Check
I checked open and closed issues for agg_spill_mem, needSpill, scalar
aggregate spill, and MergeGroup spill panic. Closed #23562 concerns a
multi-CN nested aggregation/partial-state ordering problem at a different
threshold; it does not cover this one-row ungrouped COUNT(*) nil-pointer
path.
Activity
XuPeng-SH commentedon Aug 1, 2026
Roadmap decision: #26563. Fix this by expressing the H0 execution capability: an ungrouped aggregate has no generic group hash table and must not enter the group-count hash-spill decision. Do not special-case
COUNT(*), and do not use a broadHash == nilreturn that could hide an invalid non-H0 state. Preserve byte-threshold and ordered-aggregate spill behavior and verify Reset/Free returns the mpool to baseline.XuPeng-SH commentedon Aug 5, 2026
Implementation status: #26736 is open, mergeable, and currently at
6173a85b6d, rebased onmain@ab28d1b4ac.The fix follows the capability boundary described here: H0 has no group hash table, so it cannot enter the generic grouped-spill predicate. The guard is based on execution mode rather than special-casing COUNT or treating every nil hash as valid. The regression matrix covers H0 with low row and byte thresholds, grouped spill preservation, ordered GROUP_CONCAT behavior, and Reset/Free memory cleanup.
This fixes the panic and preserves existing spill behavior. It intentionally does not claim generic H0 spill support. Any genuinely unbounded H0 state and ordinary DISTINCT spill work is now called out separately in #26563 so this correctness fix does not grow into an unrelated framework.
After #26736 merges and CI evidence is final, this issue can be closed.
fix: prevent H0 aggregate spill panic (#26736)
slyunnn commentedon Aug 12, 2026
Regression and extended verification for #26453 (2026-08-12)
Follow-up to
fix: prevent H0 aggregate spill panic(#26736).Verification environment
9a7c98b8f3aa07fad24b411d54c7a9f6cb3a8731fix(plan): enforce index metadata invariants safely (#26982)09e02eea38bfa87e4c4333ffb57b370091136bc8fix: prevent H0 aggregate spill panic (#26736)test/issue-26453-h0-aggregate-spillde7de0868186cff76fb9b556cf37734db9bf5730What was covered
Original regression:
agg_spill_mem = 256with ungroupedCOUNT(*).Happy path:
COUNT(v),SUM(v),AVG(v),MIN(v), andMAX(v).Boundary path:
COUNTreturned0;SUMreturnedNULL.Grouped control:
GROUP BYaggregate.Session cleanup:
agg_spill_memvalue after the test.Findings
The original nil-pointer panic on the no-
GROUP BYH0 aggregate path was not reproduced on currentmain.The fix correctly skips the generic hash-group spill decision for H0 aggregates, which have no grouping hash table.
This does not claim generic H0 spilling for all unbounded aggregate states; ordered aggregate spill behavior remains
separately handled by the aggregate executor, as scoped by #26563.
MOTR / BVT coverage
Existing MatrixOne BVT already covers the minimal original
COUNT(*)reproduction in:test/distributed/cases/qexec/group_h0_spill.sqlAdded MOTR coverage:
suites/14_issue_regression/t/issue_26453_h0_aggregate_spill.testsuites/14_issue_regression/r/issue_26453_h0_aggregate_spill.resultMOTR record and replay both passed: 13/13 statements.
The MOTR files were added to retain the original panic regression and to verify scalar aggregate variants, empty-input
semantics, grouped control behavior, and session-variable restoration. No MatrixOne service source code was modified.
Final conclusion
#26453 is fixed on current
main.The verified MOTR commit is ready to be included in the daily regression PR.
Ariznawlll commentedon Aug 12, 2026
关闭说明:原问题已在 current
main完成扩展验证,低阈值下 ungroupedCOUNT(*)不再 panic,常见标量聚合、空输入、grouped control 和 session 配置恢复均通过;已有 MatrixOne BVT 与 MOTR 回归覆盖。该缺陷由受控
agg_spill_mem阈值即可稳定触发并验证,不依赖数据规模,因此不需要额外加入 big-data 回归。测试证据见:#26453 (comment)fix: prevent H0 aggregate spill panic (matrixorigin#26736)
fix: prevent H0 aggregate spill panic (matrixorigin#26736)
fix: prevent H0 aggregate spill panic (matrixorigin#26736)
fix(colexec): prevent H0 aggregate spill panic on 4.2-dev (#32352)