Skip to content

[Bug]: 10Y Math SUM(EXP()) runs beyond 7200s and leaves CN execution resources occupied #28560

Closed

Description

@Ariznawlll

Description

在 TKE big-data 10Y 多 CN 环境中,SUM(EXP(...)) 扫描 1B 行数据时不能在回归预算内完成。第一次查询运行满 7200 秒后超时,脚本继续发起后续同类查询;第二次也运行满 7200 秒,第三次仍在执行时整个 workflow 被取消。

Environment

Steps to reproduce

准备 big_data_test.table_basic_for_load_1B 后执行 10Y Math case:

python run.py --sql-timeout 7200 -c ./cases/big_data_test/04_QUERIES/04_math_1B.sql

其中至少包含:

select sum(exp(col3))  from big_data_test.table_basic_for_load_1B;
select sum(exp(col9))  from big_data_test.table_basic_for_load_1B;
select sum(exp(col10)) from big_data_test.table_basic_for_load_1B;

Actual behavior

  • sum(exp(col3)) 从 2026-09-09 10:06:57 UTC 执行到 12:06:57 UTC,客户端记录 (2013, 'Lost connection to MySQL server during query') 和 Execution timeout after 7200s。
  • 脚本随后继续执行 sum(exp(col9)),同样运行 7200 秒后超时;随后启动 sum(exp(col10)),在 14:14:36 UTC workflow 被取消。
  • 超时期间 CN nightly-regression-dis-tp-cn-ngksx 持续出现 iscp transaction finish timeout;同时出现 connector cleanup timeout(context canceled)。
  • 该 CN 的 Prometheus go_goroutines 在 12:00–14:15 UTC 为 1464–1563(平均约 1523),其他两个 CN 分别约 318–420(平均约 339、352)。
  • container_oom_events_total 为 0,CN 无重启;因此当前证据不支持 OOM 或容器崩溃是直接原因。

Expected behavior

SUM(EXP(...)) 应在 big-data 10Y 的正常预算内完成,或及时返回明确的溢出错误;客户端超时后应取消服务端查询并释放执行资源,不应让后续同类查询叠加运行。

Stability and controls

Evidence

  • GitHub Actions job 日志:上述 job 链接,包含两次 7200s timeout、Lost connection 和第三条查询启动记录。
  • Loki(TKE,窗口 12:05:57–12:20:57 UTC 与 14:05:57–14:20:57 UTC):iscp transaction finish timeout、connector cleanup timeout。
  • Prometheus(selector namespace="mo-big-data-commit-4b43f8c-suite-10y"):go_goroutines、container_memory_working_set_bytes、container_oom_events_total。
  • Pyroscope(service mo-big-data-commit-4b43f8c-suite-10y/main,CN ngksx,同两段窗口):goroutine、CPU、Go heap、malloc、mutex、block profile 均有数据。

Code analysis

当前只能确认服务端查询在 1B 行 EXP 聚合路径长时间占用执行资源,并伴随 ISCP transaction finish timeout;尚未从 profile 得到足以确认具体函数的调用栈,因此根因暂标为待 MatrixOne 开发进一步定位,不将其归因于 COS 或 OOM。

Regression coverage

修复后增加一个聚焦的 10Y SUM(EXP()) 回归:记录每条 SQL 耗时,验证超时取消能终止服务端执行,并检查 CN goroutine、事务和连接在取消后回落;同时保留小数据集的溢出语义测试。

Related

Activity

  1. added this to the MO-202609 milestone on Sep 10, 2026
  2. added theissue type on Sep 10, 2026
  3. Ariznawlll commented on Sep 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    详细指标与 profile 分析

    本次分析使用同一 job 的两个 15 分钟窗口:

    • 窗口 A:2026-09-09 12:05:57–12:20:57 UTC(sum(exp(col3)) 超时点)
    • 窗口 B:2026-09-09 14:05:57–14:20:57 UTC(sum(exp(col9)) 超时点及第三条查询启动后)
    • Loki selector:{namespace="mo-big-data-commit-4b43f8c-suite-10y"}
    • Pyroscope selector:{service_name="mo-big-data-commit-4b43f8c-suite-10y/main",pod="..."}
    • Pyroscope 每 15 秒一个点,共 61 个点;CPU 为 process_cpu profile 的纳秒值,Go heap 为 memory:inuse_space,malloc 为 malloc:inuse_space。

    Pyroscope(CNSet)

    窗口 CN pod goroutine(min–max / avg) CPU ns(min–max / avg) Go heap bytes(min–max / avg) malloc bytes(min–max / avg) mutex(min–max) block(min–max)
    A 4659w 314–382 / 327 32.6–46.3G / 38.9G 1.23–1.41G / 1.31G 12.60–12.60G 89.6k–109k 94.6k–109k
    A ngksx 1.47k–1.59k / 1.52k 34.2–63.5G / 48.4G 1.21–1.53G / 1.34G 12.60–12.61G 104k–127k 123k–147k
    A q4dsl 313–392 / 336 44.9–59.3G / 51.4G 1.69–1.88G / 1.77G 12.60–12.60G 88.2k–101k 94.4k–106k
    B 4659w 291–383 / 318 1.55–58.8G / 33.0G 0.97–1.52G / 1.30G 12.60–12.61G 0.1–106k 28.3k–106k
    B ngksx 1.45k–1.56k / 1.50k 3.25–50.3G / 24.5G 0.94–1.44G / 1.18G 12.60–12.61G 23.7k–131k 67.4k–155k
    B q4dsl 289–415 / 314 1.49–46.6G / 27.2G 1.33–1.82G / 1.65G 12.60–12.60G 0.1–102k 27.6k–103k

    结论:ngksx 的 goroutine 数在两个窗口都稳定在约 1.5k,约为另外两个 CN 的 4–5 倍;CPU profile、mutex、block 也同时偏高,但 Go heap 和 malloc 没有出现独立的突增。因此更符合“查询/事务执行未及时结束并产生等待或清理堆积”,而不是 OOM。

    Prometheus(14:06:00 UTC 瞬时值)

    CN pod go_goroutines container_memory_working_set_bytes{container="main"} container_oom_events_total{container="main"}
    4659w 326 21.29 GiB 0
    ngksx 1484 20.60 GiB 0
    q4dsl 322 22.14 GiB 0

    三台 CN 在 14:06 的工作集均低于 55 GiB 限制,OOM 计数均为 0。

    Loki 事件统计

    • 窗口 A:iscp transaction finish timeout 共 91 条,全部来自 nightly-regression-dis-tp-cn-ngksx。
    • 窗口 B:同类事件共 91 条,仍全部来自 ngksx。
    • 窗口 A 在 12:06:58 UTC 出现 connector cleanup timeout,连续 occurrence 1/2/3,err=context canceled。
    • 窗口 B 在 14:06:58 UTC 出现同类 cleanup timeout(occurrence 1/2/3);14:14:36 UTC 仍有 occurrence 14(另有 10 条被 suppressed)。

    与 job 日志的对应关系

    sum(exp(col3)) 和 sum(exp(col9)) 各自完整占用 7200 秒;客户端虽然记录超时并继续下一个 SQL,但服务端对应 CN 仍出现 transaction finish/connector cleanup 超时。第三条 sum(exp(col10)) 启动后,workflow 于 14:14:36 UTC 被取消。

    这些数据确认了超时期间存在 CN 侧执行资源堆积和清理异常,但当前 profile 结果仍不足以确认具体代码函数;具体根因需要开发侧结合对应 goroutine dump/CPU 火焰图继续定位。

  4. added a commit that references this issue on Sep 10, 2026
    e395940
  5. daviszhen commented on Sep 10, 2026

    @daviszhen
    Contributor

    修复已通过 PR #28592 合入 main,merge commit:e3959405658a2607b590aef63e648c5c068fa5e4。

    根因

    EXP 溢出当前采用逐行返回 NULL 的语义,但原执行路径仍会为每个溢出值调用 momath.Exp,创建并格式化一个完整的 moerr.NewOutOfRangeNoCtxf,随后 opUnaryFixedToFixedWithNullOnError 只设置 NULL bitmap 并丢弃该错误。

    在 10 亿行大量溢出的 SUM(EXP(...)) 场景中,这会产生海量无效错误对象、字符串格式化、堆栈采集和 GC 工作,与问题中观察到的高 CPU、mutex/block 和执行资源堆积相符。

    本地未修复版本的 allocation profile 显示:

    • momath.Exp -> NewOutOfRangeNoCtxf 累计占 benchmark 分配空间约 95.5%;
    • 堆栈采集约占总分配空间 45.7%;
    • fmt.Sprintf 约占 22.3%。

    修改

    • 新增不构造 error 的 unary NULL-check 执行路径;
    • EXP 直接执行 math.Exp,通过 infinity 检查识别溢出并设置行级 NULL;
    • 保留原有 SQL 行为:有限值、下溢、输入 NULL、常量输入和 selection mask 语义不变,溢出仍返回 NULL;
    • 增加 allocation-scaling 回归测试和批量溢出 benchmark。

    性能对比

    8192 个全部溢出的输入值,每次 benchmark:

    before: 14.54-16.95 ms/op   4,655,216-4,655,552 B/op   81,928-81,929 allocs/op
    after:   0.103-0.121 ms/op      2,040-2,201 B/op        8 allocs/op
    

    函数热点约提升 120-155 倍,分配次数不再随溢出行数线性增长。修复后 CPU profile 热点回归为实际的 math.Exp 计算和 NULL bitmap 写入。

    验证

    以下本地验证均通过:

    • go test ./pkg/sql/plan/function -count=1
    • EXP/COT 聚焦测试,-count=5
    • EXP/COT 聚焦 race 测试
    • go vet ./pkg/sql/plan/function
    • git diff --check

    还需要 nightly 使用合入后的 commit 重跑原 10Y 三条 SUM(EXP(...)) 查询,确认端到端耗时以及 CN goroutine/connector cleanup 指标恢复。

  6. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    已在 main commit 9a5dd0c6e32a62e4393c2e7fbcab57b53f0c58c0 验证,已包含修复 PR #28592(merge commit e3959405658a2607b590aef63e648c5c068fa5e4)。

    原来运行满 7200 秒仍超时的三条 SQL,本次执行耗时分别为:

    • sum(exp(col3)):2.079 秒
    • sum(exp(col9)):2.008 秒
    • sum(exp(col10)):1.903 秒

    未再出现执行超时或 Lost connection。当前 Math job 标红是已有 golden 与新返回结果不一致,不是该性能问题再次出现。

    验证任务:https://github.com/matrixorigin/mo-nightly-regression/actions/runs/34496566063/job/103101071409

    测试通过。

  7. added 3 commits that reference this issue on Sep 17, 2026
    35a63e5
    607c8d8
    6b9ca89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s-1

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions