Skip to content

[Bug]: hash build budget admission rejected #26454

Closed

Description

Is there an existing issue for the same bug?

Branch Name

main

Commit ID

2e6877406157470e453245ef287d35ff81fc0c84

Image: registry.cn-shanghai.aliyuncs.com/matrixorigin/matrixone:nightly-2e687740

Other Environment Information

- Hardware: single-node MO (docker, host port 16001), rootless docker on Linux
- Host memory: ~251 GiB; container Memory limit unset (0)
- OS: Linux
- Dataset: jinpan_001 (local LOAD DATA INFILE)
- Suite: cases/jinpan_001/join (1000 SQLs), template srm_contract_attach
- processLimitationSize default: 42949672960 (40 GiB) from pkg/config/configuration.go

Actual Behavior

All executed variants of template srm_contract_attach fail immediately (cost_ms=0) with:

(20101) internal error: hash build budget admission rejected

Operator diagnostic (CN log hashbuild/types.go summary), repeated almost identically every hit:

hash_build budget admission rejected:
  requested = 551368048640   (~513 GiB / ~551 GB)
  used      ≈ 1589595280     (~1.48 GiB)
  cap       = 42949672960    (40 GiB = default processLimitationSize)

extra_stats:
  QueryHashBudgetCapBytes   = 42949672960
  QueryHashBudgetPeakBytes  ≈ 6–7e9
  QueryHashBudgetRejects    = 1
  QueryHashBudgetReserves   ≈ 570

Client sees only the short error string; detailed requested/used/cap is in CN operator diagnostics.

Regression evidence

Build Template hits Result
nightly-826a3e3d (before hash-build budget hard path in this form) 31/31 success, cost_ms ≈ 0.7–1.3s, returns rows
nightly-2e687740 (current) 13/13 so far (of 31) failed, cost_ms=0, same admission error

So this is a behavior regression: same SQL + same data used to finish in ~1s.

Expected Behavior

  1. Query succeeds (as on 826a3e3d), returning up to LIMIT rows; or
  2. If build memory is truly tight, HashBuild should spill (code already has shuffle + admission-reject → startSpill() paths) instead of failing with a ~551GB one-shot reserve that cannot be realistic for this query; and
  3. Client / log error should remain actionable (requested/used/cap is good — keep it).

Raising processLimitationSize alone is not a valid fix: even 100GiB cap cannot admit a 551GB request. The 40GiB figure is the default process limit narrowing queryCap, not proof the query needs >40GiB.

Steps to Reproduce

  1. Load jinpan_001 (tables below non-empty).
  2. Execute the SQL (case j_batch_001 / @q0009_srm_contract_attach).
  3. Observe (20101) hash build budget admission rejected with diagnostics as above.

Table sizes (this env)

Table Rows
dwd_dcp.dwd_srm_pur_headers_all ~514,007 (~52,597 after filter)
dwd_dcp.dwd_srm_con_contract_headers ~541,469
dwd_dcp.dwd_srm_fnd_atm_attachment_multi ~1,161,861
dwd_dcp.dwd_srm_fnd_atm_attachment ~1,152,847

Repro SQL

SELECT * FROM (
SELECT DISTINCT
  TRIM(h.display_po_number) AS ebeln,
  '采购合同' AS doctype,
  TRIM(a.file_name) AS file_name,
  CAST(a.attachment_id AS CHAR) AS attachment_id,
  TRIM(m.file_token) AS file_token,
  CAST(ch.contract_header_id AS CHAR) AS owner_id,
  MD5(CONCAT('SRM|采购合同|', CAST(a.attachment_id AS CHAR), '|', COALESCE(m.file_token, ''))) AS attachment_key
FROM dwd_dcp.dwd_srm_pur_headers_all h
JOIN dwd_dcp.dwd_srm_con_contract_headers ch
  ON ch.contract_number = CONCAT(CAST(h.segment1 AS CHAR), '-', CAST(h.revision_num AS CHAR))
JOIN dwd_dcp.dwd_srm_fnd_atm_attachment_multi m
  ON m.table_pk_value = CAST(ch.contract_header_id AS CHAR)
 AND m.table_name = CASE WHEN ch.contract_type_code = 'ATM_CON' THEN 'CON_CONTRACT_HEADERS' ELSE 'CON_CONTRACT_DOC' END
JOIN dwd_dcp.dwd_srm_fnd_atm_attachment a ON a.attachment_id = m.attachment_id
WHERE h.type_lookup_desc = '运输费用采购订单'
  AND h.display_po_number IS NOT NULL AND h.display_po_number <> ''
) w
WHERE 1 = 1
LIMIT 500;

Other failing variants differ only by doctype string / LIMIT (100–2000); all hit the same admission error.

EXPLAIN (plan shape)

AP QUERY PLAN ON ONE CN
Project
  -> Aggregate (DISTINCT) Limit 500
       -> Join INNER  -- attachment_multi ⋈ contract  (CAST / CASE expr conds)
            -> Join INNER shuffle:range(attachment_id)  -- attachment ⋈ attachment_multi
            -> Join INNER  -- contract ⋈ headers (CONCAT expr cond)

Expression join keys (CONCAT / CAST) likely contribute to bad build-size estimation.

Additional information

Why this looks like an engine bug (not “need more RAM”)

  1. Same query succeeded in <2s on older nightly with same dataset.
  2. One-shot requested≈513GiB while peak used under budget was only ~6–7GiB and final result is tiny (LIMIT 500).
  3. Default processLimitationSize=40GiB (10<<32 in pkg/config/configuration.go) explains cap=40GiB, but does not explain requesting 551GB.
  4. HashBuild already documents spill-on-admission-reject for shuffle; this case still fails the pipeline instead of spilling successfully.

Activity

  1. ghost added this to the MO-202607 milestone on Jul 30, 2026
  2. ghost added theissue type on Jul 30, 2026
  3. ghost added
    kind/bug
    on Jul 30, 2026
  4. ghost added
    severity/s0
    on Jul 30, 2026
  5. assigned and unassigned on Aug 5, 2026
  6. assigned and unassigned on Aug 12, 2026
  7. Ariznawlll commented on Aug 23, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 分支:main
    • commit:dc403fbac6a09c77ac93bb023fe83056308a038b
    • 部署方式:本地单节点 1 CN + 1 TN + 1 Log,使用默认查询内存限制;会话设置 max_dop=8、join_spill_mem=0,未通过提高 processLimitationSize 绕过问题
    • 测试日期:2026-08-23

    原问题验证

    按 Issue 原始数据规模和相关字段类型构造 4 张表:

    • headers:514,007 行;segment1/display_po_number/type_lookup_desc 使用 TEXT
    • contract_headers:541,469 行;contract_type_code/contract_number 使用 TEXT
    • attachment_multi:1,161,861 行;table_pk_value/table_name/file_token 使用 TEXT
    • attachment:1,152,847 行;file_name 使用 TEXT

    执行 ANALYZE TABLE 后,使用原问题中的 CONCAT + CAST、CAST、CASE 三层表达式 JOIN、DISTINCT 和 LIMIT 500 执行 EXPLAIN ANALYZE 与结果查询。

    完整用例由 3 个独立测试进程执行,3/3 通过。每轮内部连续查询 3 次,9/9 均返回 500 行;未再出现原问题的 20101 internal error: hash build budget admission rejected。

    另外在本地 MySQL 8.3.0 中装载完全相同的 4 张表、行数、字段类型和 JOIN SQL,生成确定性 Oracle;再在 MatrixOne 上执行同一摘要查询。两边结果逐项一致:总结果 110692、去重 attachment key 110692、owner 范围/求和 10 / 514000 / 26731571780、attachment 范围/求和 1 / 1152838 / 62069757082,排序后的前 10 行与 MD5 key 也一致。

    Happy Path 覆盖

    1. 四张原规模表创建、装载和统计信息更新均成功。
    2. EXPLAIN ANALYZE 通过,计划包含三层 Join Type: INNER,表达式 JOIN 路径被实际执行。
    3. 同一轮连续执行 3 次原查询,结果均为 500 行;3 个独立进程共 9/9 结果一致。
    4. 查询完成后执行新的 SELECT 1 返回 1,连接仍可正常使用。
    5. MySQL 与 MatrixOne 的完整结果摘要及排序样本一致;Golden 不再只校验 LIMIT 500 的行数。

    Unhappy Path 覆盖

    1. 保持默认查询内存限制,不提高 query cap;原始规模与 TEXT 表达式键下未触发 551 GB 错误估算或 admission rejection。
    2. 每轮开始前清理可能残留的同名表和视图,重新创建并执行完整查询;3/3 均成功,未受前一轮状态影响。
    3. 每轮结束恢复会话变量并删除 1 个视图和 4 张临时表;最终核对相关临时对象残留数为 0。
    4. 本 Issue 是只读查询预算误判,不涉及写入、事务回滚或失败写入原子性,因此这些维度不适用。

    白盒验证

    不适用。本问题可通过公开 SQL 接口和原始规模数据完整触发,验收采用黑盒 big-data 查询;HashBuild 强制 spill 已由现有 35_multikey_hashbuild_spill_100M.sql 独立覆盖,本用例不通过人为降低阈值替代原 admission 场景。

    回归测试

    测试证据

    • 最新 main 实跑:完整 big-data 用例独立执行 3/3 通过,内部结果校验 9/9 为 500。
    • MySQL 8.3.0 Oracle 与 MatrixOne dc403fba... 对比:四表行数、完整结果摘要、排序样本和 MD5 key 全部一致;上述完整摘要已固化进 Golden,并在更新后再次 3/3 通过。
    • big-data runner/契约测试:25/25 通过。
    • workflow 矩阵契约测试:9/9 通过,YAML 解析通过。
    • 两个回归 PR 当前均为 MERGEABLE,测试代码、Golden 和矩阵接入可在上述 PR 中核对。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions