Repository navigation
Description
Description
When a query reaches the configured processLimitationSpillSize limit,
the supported spill paths for ordinary ORDER BY (MergeOrder), high-cardinality
GROUP BY, and ORDER BY ... LIMIT (Top) expose an internal admission error
to MySQL clients instead of a stable resource-exhausted error.
Environment
- Branch:
main - Commit:
5bc051abc44f34ccb6813e2a0bb5585d5a1db67e - Date:
2026-08-26 - Deployment: fresh embedded
1 Log + 1 TN + 1 CNcluster for every run. - CN limits:
GuestMmuLimitation=1GiB,ProcessLimitationSize=1GiB,
ProcessLimitationSpillSize=8MiB. - Session:
set @@max_dop = 1.
Steps to reproduce
Create a wide relation so the spill-disk cap, rather than the process-memory
cap, is the limiting resource:
create table spill_probe (
id bigint not null,
k bigint not null,
payload varchar(256) not null
);
insert into spill_probe
select result,
-result,
concat(lpad(cast(result as char), 16, '0'),
repeat(char(65 + mod(result, 26)), 240))
from generate_series(1, 250000) g;MergeOrder / ordinary sort
set @@sort_spill_mem = 1;
select id, k, payload from spill_probe order by k, id;Top
set @@sort_spill_mem = 1;
select id, k, payload from spill_probe order by k, id limit 250000;High-cardinality Group
set @@agg_spill_mem = 33554432;
select id, max(payload) from group_probe group by id;For the group variant, use group_probe(id bigint not null, payload varchar(256) not null)
and insert the same 250,000-row id,payload data above.
Actual behavior
All three paths spill and then fail at exactly the configured 8 MiB cap. The
client error leaks the internal admission implementation:
Error 20101 (HY000): internal error: execution resource admission rejected:
requested=65536 used=8388608 cap=8388608
Confirmed through the SQL protocol:
| Path | Reproduction | Result |
|---|---|---|
MergeOrder (ORDER BY) |
3/3 | 20101/HY000 internal admission error |
Group (250k distinct groups) |
1/1 | same 20101/HY000 error |
Top (ORDER BY ... LIMIT 250000) |
1/1 | same 20101/HY000 error |
The failed queries published zero result rows. In the same connection, the
normal 10,000-row sort control immediately succeeded after every failure;
EXPLAIN ANALYZE for that control reported SpillSize=, proving the control
uses the real sort spill path. The 10,000-key aggregate control also succeeded.
Expected behavior
The configured spill-disk cap is a supported resource limit, so an unrecoverable
admission rejection must be returned as a stable resource-exhausted error:
3015 / HY000: resource exhausted: <operator> spill disk budget exceeded
The response must not expose execution resource admission rejected or use the
generic internal-error code 20101.
Stability and controls
- Ordinary sort reproducer: 3/3 on a fresh official-main cluster.
- The process-memory ceiling remained 1 GiB, so this is not a process-memory OOM.
- The 8 MiB cap is charged in 64 KiB writes; the rejection consistently occurred
atused=8388608, equal to the configured cap. - No rows were returned before the terminal error, and the post-failure control
confirmed per-query cleanup and connection health.
Evidence
Executed SQL-protocol probes:
CGO_CFLAGS="-I$PWD/cgo -I$PWD/thirdparties/install/include" env -u GOROOT \
go test ./pkg/tests/issues/isolated \
-run '^TestCodexMergeOrderSpillCapProbe$' -count=3 -v -timeout=12m
CGO_CFLAGS="-I$PWD/cgo -I$PWD/thirdparties/install/include" env -u GOROOT \
go test ./pkg/tests/issues/isolated \
-run '^TestCodexGroupSpillCapProbe$' -count=1 -v -timeout=8m
The disposable probes were removed after verification; the isolated worktree
was clean on 5bc051abc44f34ccb6813e2a0bb5585d5a1db67e.
Focused cleanup tests also pass, which distinguishes this from a leak:
go test ./pkg/sql/colexec/mergeorder ./pkg/sql/colexec/group ./pkg/sql/colexec/top \
-run 'TestAccounted(MergeOrderSpillResourceAdmissionCleans|GroupSpillResourceAdmissionCleans|TopSpillResourceAdmissionCleans|MergeOrderForcedSpillKeepsOrdering|GroupForcedSpillReleasesMemoryDiskAndFD)' \
-count=1 -v -timeout=5m
Code analysis
hashbuild.TerminalBudgetError already maps unrecoverable execution-resource
admission failures to a client-safe resource-exhausted error. The CTE-specific
fix in #27106 uses that path. In contrast, the verified MergeOrder, Group,
and Top call paths return spill reservation/write errors directly, allowing
the typed ExecutionResourceError to reach the frontend as 20101.
Fill has a similar direct spill-reservation shape in static review, but it was
not included in the confirmed scope because no equivalent SQL reproducer was run.
Regression coverage
Do not baseline the current 20101 behavior. After the fix, add:
- SQL-protocol regression coverage for the three verified operators that
asserts3015/HY000, zero result rows, and a succeeding same-session control. - Operator unit tests that require admission errors to be normalized before
leavingMergeOrder,Group, andTop. - A threshold/spill regression at a larger scale in big-data once the
client-facing contract is fixed.
Related
- [Bug]: materialized CTE spill rejection returns inconsistent 3015 and 20101 errors #27106 fixed the same client-error-contract problem for materialized CTE spill.
- bug: PR #26284 导致 Big Data Test INSERT...SELECT...ORDER BY spill 磁盘满(no space left on device),级联 inner join 返回 count=0 #26352 is not a duplicate: it concerns an unbounded
/tmpdisk-full failure
in a Big Data workflow, not an explicitprocessLimitationSpillSizerejection.
Activity
Ariznawlll commentedon Aug 26, 2026
补充受影响范围:Time Window 的
GAPFILL(PARTITION) + FILL(next)也会将 spill 资源准入拒绝原样映射为 20101/HY000。验证版本:最新 main
5bc051abc44f34ccb6813e2a0bb5585d5a1db67e。series_id分组;1 秒窗口、10,001 个生成桶,GAPFILL(PARTITION) FILL(next)20101 / HY000,消息为internal error: execution resource admission rejected: requested=65536 used=0 cap=1SELECT 1通过。结论:FILL 的
newFillSpill返回ExecutionResourceError后同样没有在 SQL 边界归一化为资源耗尽错误,和本 issue 已覆盖的 ORDER BY / GROUP BY / TOP 属于同一根因;修复时请将该路径纳入回归。补充说明:普通
FILL(next)不会凭 WHERE 时间范围生成空桶;需要GAPFILL(PARTITION)才会生成连续空窗,这是本次探针首次未触发 spill 后确认的语义。fix: support decimal256 indexes and normalize spill errors (#28845)
fix: support decimal256 indexes and normalize spill errors (matrixori…
fix: support decimal256 indexes and normalize spill errors (matrixori…
Ariznawlll commentedon Sep 22, 2026
当前 origin/main
66da3877e9e77f01083c4aac0cb9f94ab6e11fe6(2026-09-22)上,这条 20101 的客户端映射还在,但已经不是所有 spill 算子都会走到。原始 SQL 没有在这个提交上重跑。客户端入口是
pkg/frontend/protocol.go的sendErrorResponse(264-272 行)。errors.As会沿着Unwrap找到*moerr.Error。*process.ExecutionResourceError(Kind=Admission)的Unwrap返回ErrExecutionResourceAdmission(pkg/vm/process/execution_resource_budget.go:129,194-200),这是ErrInternal20101,MySQL code 是ER_UNKNOWN_ERROR。于是sendErrorResponse使用ErrorCode()20101,报文仍是外层Error():internal error: execution resource admission rejected: requested=... used=... cap=...。hashbuild.TerminalBudgetErrorForOperator(pkg/sql/colexec/hashbuild/errors.go:38-136)会把同一类准入错误转成moerr.NewResourceExhaustedf,即ErrOOM20103,MySQL codeER_ENGINE_OUT_OF_MEMORY3015(pkg/common/moerr/mysql_error_define.go:946)。当前 main 已在这些
Call边界转换:pkg/sql/colexec/group/exec2.go:363-367pkg/sql/colexec/mergeorder/order.go:541-546pkg/sql/colexec/top/top.go:174-176pkg/sql/colexec/fill/fill.go:159,e4511d6af41(2026-09-17)加入Call返回点调用TerminalBudgetError上面 2026-08-26 的 FILL 补充对应的是
5bc051a。那个提交早于e4511d6af41。当前Fill.Call会转换newFillSpill返回的准入错误。这条路径没有在66da3877e9上重跑。本 issue 原始的 ORDER BY、本地 GROUP BY、大 K TOP 复现,在当前 main 上会先经过 MergeOrder / Group / Top 的
Call包装。这些 SQL 同样没有重跑,所以不能据此把 issue 标成已修复。当前 main 上仍会把 spill 准入原样送进
sendErrorResponse、从而仍是 20101 的路径:MergeGroup.Call(pkg/sql/colexec/group/mergeGroup.go:119)没有包装。Prepare在allocationAccount != nil时设置ctr.budget(42-52 行),和Group.Prepare的门槛相同。spill 写入走spillDataToDisk→openSpillBucket(helper.go:734-742)的ReserveSpillFD/ReserveSpillDisk。失败时Call在 147-154、191-192、202-203 行直接返回。多 scope GROUP BY 的 merge 侧因此仍是 20101。Group.Call对同一错误会转成 3015。Window.Call(pkg/sql/colexec/window/window.go:295)没有包装。带 ORDER BY 的窗口在processOrder里调用mergeorder.SortBatchWithPrecomputedOrderAndRelease(2422-2433 行),错误从 397-398 行直接返回。sortBatch(pkg/sql/colexec/mergeorder/batch_sort.go:67-74)总会取GetExecutionResourceBudget(),spill 文件在spill.go:303-308做ReserveSpillFD(1)和ReserveSpillDisk(0)。窗口排序 spill 的准入失败因此仍是 20101。MergeOrder.Call对同一类错误会转成 3015。修复这两处时,在各自
Call的对外返回点使用TerminalBudgetErrorForOperator,并加上 spill disk / spill FD 配额被拒绝的回归。内部 spill 恢复路径应继续保留 typed admission error,和errors.go:27-29的约定一致。Ariznawlll commentedon Sep 22, 2026
再补两条仍会把未包装的
*ExecutionResourceError交到客户端、从而显示成20101的路径。对照 origin/main66da3877e9e77f01083c4aac0cb9f94ab6e11fe6。没有在集群上重跑 SQL。客户端映射和上次评论相同:
pkg/frontend/protocol.go的sendErrorResponse用errors.As走到内层ErrInternal(20101 /ER_UNKNOWN_ERROR),文案仍是外层 admission 字符串。TerminalBudgetErrorForOperator会把它收成ErrOOM(20103 / MySQL 3015)。3.
table_changesTableFunction.Call(pkg/sql/colexec/table_function/table_function.go:98-100)直接返回state.call的错误,没有TerminalBudgetErrorForOperator。tableChangesSpillConfig(pkg/sql/colexec/table_function/table_changes.go:241-264)把budget.ReserveSpillDisk/budget.ReserveSpillFD原样交给 change-range spill。newRangeSpillFile(pkg/vm/engine/disttae/logtailreplay/change_handle.go:322-335)和rangeSpillFile.Append的Grow(同文件:364-365)失败时直接return。CollectChanges的错误从tableChangesState.call(table_changes.go:202-204)原样出去。GetExecutionResourceBudget在没有 generation 时会创建一笔。disk/FD 拒绝时客户端看到 20101,而不是 3015。写到一半的 record 不会被后续读到:调用方出错就
Close这个文件,CreateAndRemoveFile在 close 时 unlink。这里只补错误码,不是结果错误。4. DML
RETURNINGspoolreturningSpool.BeginAttempt(pkg/frontend/returning_spool.go:84-91)ReserveSpillDisk(0)/ReserveSpillFD(1)失败直接返回。Write的Grow失败(:152-153)同样直接返回。pkg/sql/compile/compile2.go:572和:797把BeginAttempt的错误返回给查询。Output.Call(pkg/sql/colexec/output/output.go:87-90)把resultSink.Write原样返回。短写会
ReconcileDown再返回,文件由 spool 的 close 路径收掉。不是泄漏,是同一个 20101 映射。建议
在这两个对外边界包
TerminalBudgetErrorForOperator,和已经包过的 Group / MergeOrder / Top / Fill / HashBuild / HashJoin / DedupJoin / RightDedupJoin 一样。内部恢复路径继续保留 typed error(pkg/sql/colexec/hashbuild/errors.go:27-29)。上次列出的 MergeGroup 和 Window 仍然没包。Ariznawlll commentedon Oct 16, 2026
测试版本
main2305954d0bf4aa5f062adb8b9379e471240abab51 Log + 1 TN + 1 CN集群;CN 配置GuestMmuLimitation=1GiB、ProcessLimitationSize=1GiB、ProcessLimitationSpillSize=8MiB原问题验证
按原 issue 的 250,000 行宽表场景,设置
max_dop=1、sort_spill_mem=1、agg_spill_mem=33554432,经 MySQL SQL 协议复测:ORDER BY(MergeOrder)3015/HY000,merge order spill disk budget exceededORDER BY ... LIMIT 250000(Top)3015/HY000,top spill disk budget exceededGROUP BY(Group)3015/HY000,group spill disk budget exceeded三条查询均返回 0 行,没有暴露
execution resource admission rejected,也没有返回20101。源表基线校验为count=250000, min(id)=1, max(id)=250000, sum(id)=31250125000。每次失败后,同一连接执行SELECT 1成功。Happy Path 覆盖
Window 排序使用相同 SQL 的 100 行小数据控制,成功返回 100 行。失败查询后的同连接健康检查
SELECT 1也均成功。Unhappy Path 覆盖
原 issue 的三个算子都触发 8 MiB spill 配额上限,并稳定返回
3015/HY000。补测 Window 有序 spill 时,30,000 行、每行 2,048 字节的输入 3/3 返回20101/HY000,错误文本为execution resource admission rejected: requested=2048 used=8387625 cap=8388608;失败前 0 行发布,随后同连接SELECT 1成功。这个新问题已单独提交到 #30391。旧评论中提到的 MergeGroup、
table_changes和 DMLRETURNING路径本次未复测;本次结论针对原 issue 描述的 MergeOrder、Group、Top 范围。Window 路径另见 #30391。白盒验证
未运行 UT 或
-race。本次通过 SQL 协议验证客户端错误码、返回行数和失败后的连接状态。回归测试
本次未提交 MOTR、UT 或 big-data 回归用例。#30391 已记录修复后应增加的 Window SQL 协议回归断言。
测试证据
原问题 disposable SQL-protocol probe:三个算子均 3/3 返回 3015/HY000、0 行;补充的 Window probe 命令及三次原始错误输出已记录在 #30391。
测试结论
测试通过。