Skip to content

[Bug]: Window ORDER BY spill admission rejection returns 20101 instead of 3015 #30391

Closed

Description

@Ariznawlll

Description

When a Window query uses ordered spill and reaches the configured processLimitationSpillSize cap, the SQL client receives the internal execution-resource admission error (20101/HY000) instead of a stable resource-exhausted error (3015/HY000). This is reproducible on current main and is separate from the MergeOrder, Group, and Top paths covered by #27627.

Environment

  • Branch: main
  • Commit: 2305954d0bf4aa5f062adb8b9379e471240abab5
  • Deployment: fresh embedded 1 Log + 1 TN + 1 CN cluster
  • CN limits: GuestMmuLimitation=1GiB, ProcessLimitationSize=1GiB, ProcessLimitationSpillSize=8MiB
  • Session: max_dop=1, sort_spill_mem=1
  • Date: 2026-10-16

Steps to reproduce

Create a database, then run:

set role moadmin;
create database codex_27627_window;
use codex_27627_window;
set @@max_dop = 1;
set @@sort_spill_mem = 1;

create table window_probe (
  id bigint not null,
  k bigint not null,
  payload varchar(2048) not null
);
insert into window_probe
select result, -result,
       repeat(char(65 + mod(result, 26)), 2048)
from generate_series(1, 30000) g;

select id,
       max(payload) over (
         order by k rows between unbounded preceding and current row
       )
from window_probe;

For a normal control under the same settings, create window_control with the same schema, insert 100 generated rows using the same expression, and run the same Window query against it.

Actual behavior

The 30,000-row query returns:

Error 20101 (HY000): internal error: execution resource admission rejected: requested=2048 used=8387625 cap=8388608

It publishes zero result rows before failing.

Expected behavior

Return a client-safe resource-exhausted error (3015/HY000) identifying the Window spill disk budget, without exposing execution resource admission rejected or using generic internal error 20101.

Stability and controls

  • Reproducer: 3/3 on the same fresh isolated cluster.
  • Normal control: the identical Window query over 100 rows succeeded and returned all 100 rows.
  • Failure state: zero rows were published; SELECT 1 on the same connection succeeded after each failure.
  • Fixture baseline: 30,000 rows, each with a 2,048-byte payload; spill cap 8 MiB and process memory cap 1 GiB.

Evidence

SQL-protocol probe on the commit above:

go test ./pkg/tests/issues/isolated -run '^TestCodexIssue27627WindowSpillMapping$' -count=1 -v -timeout=20m

control=window_control rows=100 result=success
fixture=window_probe rows=30000 payloadBytesPerRow=2048 spillCapBytes=8388608
attempt=1 publishedRows=0 mysqlCode=20101 sqlState=HY000 message="internal error: execution resource admission rejected: requested=2048 used=8387625 cap=8388608"
attempt=2 publishedRows=0 mysqlCode=20101 sqlState=HY000 message="internal error: execution resource admission rejected: requested=2048 used=8387625 cap=8388608"
attempt=3 publishedRows=0 mysqlCode=20101 sqlState=HY000 message="internal error: execution resource admission rejected: requested=2048 used=8387625 cap=8388608"

The probe was run in a disposable isolated worktree and was not committed.

Code analysis

pkg/sql/colexec/window/window.go returns the error from ctr.processOrder directly from Window.Call (around lines 400-401). The ordered spill call in processOrder returns the admission error directly (around lines 2483-2494); the Window boundary does not normalize it through TerminalBudgetErrorForOperator.

Regression coverage

After the fix, add SQL-protocol regression coverage for the Window ordered-spill path. Assert 3015/HY000, zero published rows, a successful same-session control, and the normal small-input Window result.

Related

Activity

  1. added this to the MO-202610 milestone on Oct 16, 2026
  2. added
    kind/bug
    on Oct 16, 2026
  3. added theissue type on Oct 16, 2026
  4. added a commit that references this issue on Oct 16, 2026
    8669eed
  5. Ariznawlll commented on Oct 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 官方 main:47b9690d7caec56b589fdefaf0684177412cffb2;修复 PR #30397 已合入,merge commit 8669eedae682f7aea093c6cab3d1b8877f91a8dc 已确认进入该 SHA。
    • 2026-10-17,隔离本地 1 LogService / 1 TN / 1 CN。CN 的 guest/process memory 均为 1 GiB,processLimitationSpillSize=8 MiB;会话 max_dop=1、sort_spill_mem=1。

    原问题验证

    保持 issue 原 SQL:30,000 行、每行 2,048 字节 payload(约 58.6 MiB,超过 8 MiB 限额),执行 ordered Window max(payload) over (order by k rows between unbounded preceding and current row)。SQL 协议诊断探针独立启动 3 次、每次原查询执行 3 次,共 9/9 返回 3015/HY000;每次 0 行提前发布,消息为 window spill disk budget exceeded 且 limit=8388608,没有 20101 或内部 admission 文案。一次实际错误为 requested=2048, used=8387625, limit=8388608,说明确实触达原阈值。

    Happy Path 覆盖

    1. 相同设置、相同窗口 SQL 的 100 行对照:9/9 返回完整结果,每个 id 的 2,048 字节窗口最大值与独立期望一致。
    2. 每次失败后同连接 SELECT 1:9/9 返回 1,连接和 CN 仍可用。

    Unhappy Path 覆盖

    1. 原 30,000 行查询触达 8 MiB spill 上限:9/9 拒绝为 3015/HY000,0 行发布,不泄露内部错误;只读查询不涉及写入原子性。
    2. 每次资源拒绝后的同连接恢复检查均通过;无崩溃或卡死。

    白盒验证

    此次以外部 SQL 协议验收为准;本地诊断探针未提交为 MatrixOne Go UT。未执行 -race(非并发竞争问题)。

    回归测试

    • 已将专用配置场景及稳定预期加入当日唯一的 MOTR 汇总 PR #247,commit d2ba6b0f2bfaab3e3d6639f4095922e3f9a6d005,文件 suites/scenarios/14_issue_regression/issue_30391_window_spill.py 与 out/issue_30391_window_spill.out;未修改 (AOE) incompatible bug fix #237。保持 30,000×2,048 字节和 8 MiB 阈值,断言正常窗口值、3015、0 已发布行和同连接恢复。
    • 在配置了 8 MiB spill cap 的本地服务上,MOTR runner --repeat 3:3/3 success、0 failed、0 skipped;脚本直接运行另 3/3。未显式设置专用配置标志的普通环境 SKIP 77,不能计作通过。
    • PR select without from clause is not supported #247 尚未合入;完整 suite 与专用配置的集成 CI 未执行,后续仍需验收。不擅自触发共享或昂贵 CI。

    测试证据

    • 本地 SQL 协议 9/9 输出:publishedRows=0 code=3015 state=HY000,消息包含 window spill disk budget exceeded (requested=2048, used=8387625, limit=8388608)。
    • MOTR #247 文件和检查;本地定向 runner 汇总 total=3 success=3 failed=0 skipped=0。离线检查不等于专用配置集成测试。

    测试结论

    测试通过。

  6. daviszhen commented on Oct 20, 2026

    @daviszhen
    Contributor

    最新 main 验证(2026-10-20)

    基线:309f618995af4ee23e3b9149365f4af77264090d;关联修复 PR:#30397。

    结论:原问题已解决。window forced-spill UT 通过,之前的 exact-main 集成证据也确认 spill 错误返回正确的 OOM/3015 映射。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions