Repository navigation
Description
[Bug]: Group continues spill reload after cancellation arrives at input EOF
Summary
Group.Call checks cancellation only when the operator call begins. If the
input child reports EOF and the process context becomes canceled immediately
after that child call, Group continues to flush and reload its spill buckets,
then returns a normal result instead of context.Canceled.
This is particularly expensive for a large aggregation because the canceled
statement can still perform the complete spill readback and hash merge.
Reproduction
The focused white-box reproducer is:
pkg/sql/colexec/group/group_test.go
TestGroupSpillReloadHonorsCancellationAfterInput
It creates 65,536 distinct int32 keys, sets Group.SpillMem = 4096 to force
the group-count spill mode, and uses a child that cancels the process exactly
when it returns EOF. The first spill wave has already created 32 bucket files
before EOF. The expected result of the Group call is context.Canceled.
Run:
go test ./pkg/sql/colexec/group \
-run TestGroupSpillReloadHonorsCancellationAfterInput -count=1 -vActual result
The test fails because Group.Call returns nil error after cancellation:
Expected error with "context canceled" in chain but got nil.
The operator diagnostics confirm that it proceeded into the spill reload path
after cancellation, including GroupSpillReloadBuckets=1,
GroupSpillReloadRecords=8, and GroupSpillReloadRows=2026.
Expected result
Once the pipeline context is canceled, Group should stop before doing more
spill I/O or spill-bucket hash merges, return the cancellation error, and let
the normal reset/free path release the bucket resources.
Reproducibility
Reproduced twice independently on origin/main at ebdc3de0f:
- First focused run:
Group.Callreturnednilafter the spill was created. - Second focused run: the same result; the recorded command exited with code
1 only because the test correctly expectedcontext.Canceled.
Suspected area
pkg/sql/colexec/group/exec2.go checks vm.CancelCheck(proc) only at the
start of Group.Call. The loops in pkg/sql/colexec/group/helper.go,
especially loadSpilledData, continue reading and merging spill records
without another cancellation check.
Scope
This report is limited to the Group spill reload cancellation path. It does
not change production code.
Activity
XuPeng-SH commentedon Aug 1, 2026
Roadmap grouping: #26563. Fix together with #26446/#26447 under one narrow invariant: after child EOF, observe cancellation before spill reload/final merge/materialization; during long work, check at bucket/run/chunk boundaries rather than per row. Reuse a shared test fixture, but do not change global
ChildrenCallsemantics or introduce a general cancellation/I/O framework.fix(colexec): honor cancellation at spill phase boundaries (#26675)
Ariznawlll commentedon Aug 5, 2026
测试版本
mainace13bf4b43773dd962f03325b22f58ed31fee91process.Context。原问题验证
执行
go test -count=3 ./pkg/sql/colexec/group,以及go test -race ./pkg/sql/colexec/group。目标回归TestGroupSpillReloadHonorsCancellationAfterInput在 child EOF 后取消 context,断言 reload 不再继续并返回取消结果。Happy Path 覆盖
TestGroupSpillReloadKeepsPreallocationBounded:spill reload 正常完成,预分配受字节上限约束。TestGroupByWithSum与TestGroupNoGroupBy:普通聚合/无 group key 的结果仍正确。TestGroupResetAndReuse:正常执行后 reset 可复用。Unhappy Path 覆盖
TestGroupSpillReloadHonorsCancellationAfterInput,不会进入后续 reload/publish。TestGroupSpillWriteHonorsCancellationAfterInputBatch、TestGroupSpillWriteStopsAtBucketBoundary、TestGroupSpillWriteStopsAfterLastBucket。TestGroupSpillReloadCancellationCleansAndReuses;断言临时资源被清理、下一次执行可用。白盒验证
针对 group_test.go 执行 3 轮普通 UT 和 1 轮
-race,未发现 data race 或泄漏式重放。回归测试
该问题依赖内部 spill reload 与取消时序,现由上述 Go UT 保留;普通 motr SQL 无法可靠将取消精确注入到 EOF 后 reload 边界,因此未重复加入 motr。
测试证据
执行命令:
go test -count=3 ./pkg/sql/colexec/group、go test -race ./pkg/sql/colexec/group,均以 exit code 0 完成。测试结论
测试通过。
fix(colexec): honor cancellation at spill phase boundaries (matrixori…
fix(colexec): honor cancellation at spill phase boundaries (matrixori…
fix(colexec): honor cancellation at spill phase boundaries (matrixori…