You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: MergeOrder continues spill final merge after cancellation arrives at input EOF #26446
[Bug]: MergeOrder continues spill final merge after cancellation arrives at input EOF
Summary
MergeOrder.Call consumes its child until EOF and then immediately enters prepareSpillFinalMerge when spill runs exist. If the pipeline context is
canceled immediately after the child returns EOF, the operator proceeds with
the final spill merge and returns a normal result instead of context.Canceled.
For a large ORDER BY this leaves a canceled statement doing potentially
expensive spill file reads, run reduction, and output merging.
It creates three small input batches, sets MergeOrder.SpillThreshold = 1 to
force each batch into a spill run, and uses a child operator that cancels the
process exactly when it returns EOF. The expected result of the enclosing
MergeOrder call is context.Canceled.
Run:
go test ./pkg/sql/colexec/mergeorder \
-run TestOrderSpillFinalMergeHonorsCancellationAfterInput -count=1 -v
Actual result
The test fails because MergeOrder.Call returns a nil error after the
cancellation:
Expected error with "context canceled" in chain but got nil.
The test necessarily reaches the spilled path: the threshold is one byte and
the EOF transition triggers prepareSpillFinalMerge before the normal sorted
result can be returned.
Expected result
Once the pipeline context is canceled, MergeOrder should stop before final
spill merge work, return the cancellation error, and let the standard
reset/free path clean up its spill runs and readers.
Reproducibility
Reproduced twice independently on origin/main at ebdc3de0f:
First focused run returned nil after cancellation.
Second focused run returned the same result; its command exits with code 1
only because the test correctly expects context.Canceled.
Suspected area
pkg/sql/colexec/mergeorder/order.go switches from receiving to prepareSpillFinalMerge after its EOF child call without another vm.CancelCheck(proc). The spill finalization and reduction loops in pkg/sql/colexec/mergeorder/spill.go likewise continue without consulting
the canceled process context.
Scope
This report is limited to MergeOrder's spilled final-merge cancellation path.
It does not change production code.
Roadmap grouping: #26563. Fix together with #26444/#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 ChildrenCall semantics or introduce a general cancellation/I/O framework.
部署方式:macOS/arm64 本地 Go 单测;受控 spill runs 与可取消 process.Context。
测试日期:2026-08-05
原问题验证
执行 go test -count=3 ./pkg/sql/colexec/mergeorder 与 go test -race ./pkg/sql/colexec/mergeorder。TestOrderSpillFinalMergeHonorsCancellationAfterInput 覆盖输入 EOF 后、final merge 开始前取消的原问题边界。
Activity
XuPeng-SH commentedon Aug 1, 2026
Roadmap grouping: #26563. Fix together with #26444/#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/mergeorder与go test -race ./pkg/sql/colexec/mergeorder。TestOrderSpillFinalMergeHonorsCancellationAfterInput覆盖输入 EOF 后、final merge 开始前取消的原问题边界。Happy Path 覆盖
TestOrderSpill、TestOrderSpillMultiPass:单轮和多轮 spill merge 均正确返回有序结果。TestOrderSpillMultiKey、TestOrderSpillDesc、TestOrderSpillNullsLast:多 key、倒序和 NULL 排序语义保持正确。TestMergeOrderResetAndOpType:正常 merge 后可 reset/reuse。Unhappy Path 覆盖
TestOrderSpillFinalMergeHonorsCancellationAfterInput。TestOrderSpillWriteHonorsCancellationAfterInputBatch、TestWriteSpillBatchStopsAtBatchBoundary。TestMergeRunsToSpillCancellationCheckpoints、TestOpenSpillReadersCancellationPreservesOwnership、TestSpillReaderRolloverCancellationBoundaries。TestCleanupSpillDiscardsUncommittedActiveRun,不留下可见结果。白盒验证
针对 order_test.go 运行 3 轮 UT 和 1 轮
-race;覆盖 final merge、reader rollover、run cleanup 和 reset。回归测试
取消注入点位于 MergeOrder 内部 final merge,采用 Go UT 回归;不适合用普通 SQL/motr 的非确定性客户端超时替代。
测试证据
执行命令:
go test -count=3 ./pkg/sql/colexec/mergeorder、go test -race ./pkg/sql/colexec/mergeorder,均以 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…