Skip to content

[Bug]: materialized CTE spill rejection returns inconsistent 3015 and 20101 errors #27106

Closed

Description

@Ariznawlll

Description

The same materialized-CTE query, under the same processLimitationSpillSize limit, reports two incompatible MySQL errors when HashBuild spill-disk admission is rejected: either 3015 resource exhausted or 20101 internal error.

This was found while validating #26131. The original CTE reuse/cancellation issue is fixed; this report is only about terminal resource-error classification.

Environment

  • Branch: main
  • Commit: 1d7b6311ce91df0968da435bb405f3d68137c595
  • Deployment: embedded 1 Log + 1 TN + 2 CN
  • Both CNs: processLimitationSize=1 GiB, processLimitationSpillSize=32 MiB, max_dop=1

Steps to reproduce

  1. Create a table with 800,000 rows and 19 BIGINT payload columns.
  2. Patch the table statistics to 100,000 rows so a multi-reference CTE is materialized and runtime spill is exercised.
  3. Execute the same two-consumer CTE query repeatedly, alternating the two CN entry points. The 800,000-row form exceeds the 32 MiB spill-disk budget.
  4. Record the MySQL error number, SQLSTATE and message.

The query shape is:

WITH c AS (
  SELECT id, MAX(c1) c1, ..., MAX(c19) c19
  FROM cte_wide WHERE id <= 800000 GROUP BY id
)
SELECT COUNT(*), MIN(a.id), MAX(a.id), MAX(a.c1), MAX(...)
FROM c a JOIN c b ON a.id = b.id;

Actual behavior

Repeated executions of the identical query return both:

ERROR 3015 (HY000): error: resource exhausted: hash build spill disk budget exceeded

and:

ERROR 20101 (HY000): internal error: hash build budget admission rejected

No execution returns a partial result, and both CNs remain healthy.

Expected behavior

Every terminal spill-disk budget rejection should be classified consistently as 3015/HY000 resource exhausted, with actionable requested/used/limit details. An expected capacity limit must not escape as 20101 internal error.

Stability and controls

  • Reproducer: repeated on the latest official main in one fresh 2-CN cluster; both mappings occurred multiple times for the same SQL and configuration.
  • Happy control: the 500,000-row form spills about 12.55 MiB, returns the exact expected result, releases all reserved spill bytes, and succeeds from both CNs.
  • Failure atomicity: rejected executions returned zero rows; subsequent SELECT 1 and the accepted spill query succeeded on both CNs.
  • Duplicate search: [Bug]: hash build budget admission rejected #26454 is a false-admission/estimation regression on a different big-data join. It does not cover inconsistent 3015/20101 classification for one materialized CTE query.

Evidence

Representative pair from the same fresh run:

3015/HY000: resource exhausted: hash build spill disk budget exceeded
20101/HY000: internal error: hash build budget admission rejected:
             requested=1311516 used=32787900 cap=33554432

Related validation comment: #26131 (comment)

Code analysis

pkg/sql/colexec/hashbuild/errors.go:TerminalBudgetError converts a typed HashBuildBudgetError to moerr.NewResourceExhaustedf, but some distributed/materialized-CTE terminal path is still surfacing the raw admission error. The operator diagnostic and client-visible error therefore depend on which path propagates the rejection. This is an inference from runtime evidence and the current error-conversion code; the exact propagation edge still needs owner confirmation.

Regression coverage

After the fix, add a configured multi-CN integration regression that runs the same rejection through both CN entry points for at least three rounds and strictly asserts 3015/HY000, spill-specific cause, zero partial rows and post-error recovery. This needs a low spill cap and generated wide data, so it belongs in the configured Go issue/integration suite rather than default MOTR.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 13, 2026
  2. added
    kind/bug
    on Aug 13, 2026
  3. added theissue type on Aug 13, 2026
  4. assigned and unassigned on Aug 13, 2026
  5. slyunnn commented on Aug 24, 2026

    @slyunnn

    Regression and extended verification for #27106 (2026-08-24)

    Verification Environment

    Validated against MatrixOne origin/main commit 861a0f5ea6cf90cd278cf6d4cdb1c74234cf36039 — feat: esql_tvf / sql_tvf table functions and ENGINE = ESQL|SQL foreign external tables (#27489).

    Related fix: #27109, merge commit 0fc87ec145574bca4ddd5b496e4349894a6e9f5d, fix(compile): normalize materialized CTE spill rejection.

    Topology: 1 Log service + 1 TN service + 2 CN services + 1 Proxy service. Both CNs were restarted from clean state with static [cn.frontend] settings processLimitationSize=1073741824 (1GiB) and processLimitationSpillSize=33554432 (32MiB).

    The three test endpoints were Proxy 127.0.0.1:26009, CN1 127.0.0.1:26001, and CN2 127.0.0.1:26002. The client used the MySQL protocol. Every validation connection explicitly set and verified @@max_dop=1.

    What Was Covered

    • OK — Original scale: created 800000 rows with 19 BIGINT payload columns.
    • OK — Materialized-CTE reachability: EXPLAIN showed one Sink and two Sink Scan consumers before the self-join.
    • OK — Happy path: the 500000-row two-consumer CTE control completed successfully on Proxy, CN1, and CN2.
    • OK — Original rejection boundary: the 800000-row CTE consistently returned MySQL 3015 / HY000 resource exhaustion through Proxy, CN1, and CN2.
    • OK — Stability: each endpoint executed the 800000-row rejection scenario for 3 consecutive rounds; no round returned the prior 20101 internal error.
    • OK — Unhappy-path recovery: every rejected execution returned no result and was followed by a successful SELECT 1 on the same connection.
    • OK — Configuration boundary: both CN static limits were verified in the active configuration; all validation sessions verified @@max_dop=1.
    • Not covered — concurrent competing queries, network partition/failover, and spill-file I/O fault injection; the issue concerns deterministic terminal error classification for one materialized CTE admission failure.

    Findings

    The original low-spill materialized-CTE workload now has one client-visible terminal classification: 3015 / HY000 resource exhaustion. The former 20101 internal-error mapping did not occur in 9 repeated rejection executions across the three endpoints.

    Large-data regression was required and performed. The defect depends on materialized CTE fanout and spill-budget admission, so the issue's minimum stable workload of 800000 wide rows under the 32MiB spill cap was necessary; arbitrary larger data would not add relevant coverage.

    MOTR / BVT Coverage

    No MOTR test or issue branch was added. The required 1GiB process limit and 32MiB static spill limit are CN-startup settings, so a default MOTR SQL case would not faithfully establish the bug boundary.

    The configured end-to-end BVT used the exact materialized CTE shape with MAX(c1) through MAX(c19), a two-consumer c a JOIN c b ON a.id=b.id, and MySQL-protocol verification on Proxy, CN1, and CN2.

    Final Conclusion

    Fixed. The fully configured 2 CN + Proxy environment completed the happy path and consistently classified every original large-data spill rejection as 3015 resource exhaustion, with post-error recovery intact. Large-data regression was required and completed because the failure boundary is spill-size dependent.

  6. Ariznawlll commented on Aug 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:5bc051abc44f34ccb6813e2a0bb5585d5a1db67e
    • 部署方式:1 Log + 1 TN + 2 CN + 1 Proxy;两个 CN 均配置 processLimitationSize=1GiB、processLimitationSpillSize=32MiB
    • 测试日期:2026-08-26

    原问题验证

    创建 800,000 行、19 个 BIGINT payload 列的宽表。EXPLAIN 确认计划包含 1 个 Sink 和 2 个 Sink Scan,命中 materialized CTE 双消费者路径。分别通过 Proxy、CN1、CN2 执行 800,000 行拒绝场景,每个入口连续 3 轮,共 9 次。

    9/9 均稳定返回:3015 / HY000 resource exhausted: hash build spill disk budget exceeded (requested=1311516, used=32787900, limit=33554432);未再出现 20101 internal error。

    Happy Path 覆盖

    1. 三个入口均显式设置并验证 @@max_dop=1,git_version() 均为 5bc051abc。
    2. 500,000 行控制在 Proxy/CN1/CN2 分别成功,count/min/max 为 500000/1/500000,最后 payload 最大值为 500019。
    3. 500,000 行耗时分别为 2742 / 2664 / 2379 ms。

    Unhappy Path 覆盖

    1. 800,000 行超过 32MiB spill cap,三个入口各 3 轮均返回 3015/HY000 和完整 requested/used/limit。
    2. 每次拒绝均未返回结果行。
    3. 每次拒绝后立即在同一连接执行 SELECT 1,9/9 恢复成功;CN/Proxy 未退出。

    白盒验证

    TestMaterializedSpillBudgetUsesProcessLimits 连续执行 3 轮通过,覆盖 spill disk/FD 上限、3015 分类、invalid budget 与资源释放。

    回归测试

    • 修复 PR: #27109
    • 定向 UT:cte_sink_fanout_test.go
    • 未加入普通 MOTR:原问题依赖 CN 启动时 32MiB spill 静态配置和 80 万行宽表,应保留在 configured integration/big-data 层。

    测试证据

    当前 main 上重新执行完整配置化场景:3 个入口的 500k Happy Path 全部成功,800k rejection 9 次错误码、SQLSTATE 和 spill 预算明细完全一致。

    测试结论

    测试通过。

  7. Ariznawlll commented on Aug 26, 2026

    @Ariznawlll
    CollaboratorAuthor

    无需加入普通 MOTR/big-data:该问题依赖 CN 启动时 32MiB spill 静态配置,通用回归无法忠实建立边界;主库已有资源预算/错误分类 UT,并已在 2CN+Proxy 配置环境完成 500k Happy Path 与 800k 共 9 次拒绝验证。现关闭。

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