Skip to content

[Bug]: TPC-DS 1T Q4 exceeds 1200s with repeated CTE scans in plan #32806

Closed

Description

@Ariznawlll

Description

TPC-DS 1T Q4 did not finish within 1,200 seconds in two independent runs on the same official main commit. EXPLAIN shows the year_total CTE expanded into repeated sales-table scans, aggregations, and joins. This is a performance investigation request: the repeated scans may contribute to the long runtime, but operator timings and the root cause are not yet established.

Environment

  • MatrixOne official main: 7fcd9bdff8433d72983f0399fd5c10dcab91a00a; single host mo-srv-129, 64-core plan.
  • Freshly imported TPC-DS 1T database; source and database row counts were checked for all 25 tables.
  • processLimitationSize=42949672960 (40 GiB); service MemoryMax=180 GiB, swap disabled; TN auto-merge disabled and verified for the diagnostic run.
  • Diagnostic session settings join_spill_mem, agg_spill_mem, sort_spill_mem, max_dop: 0, 0, 0, 0. Disk safety floor: 200 GiB.

Steps to reproduce

  1. Load TPC-DS 1T data into tpcds_1t, using the above configuration.
  2. Run the original /data4/weilu/tpcds/query_1t_mo/query4.sql against tpcds_1t with a 1,200-second client timeout. The exact SQL and output are in the linked artifacts; Q4 SQL SHA-256: b4804b6da5f5d4a2c809041d961df64021155eaca9fa723740cd0c080a6fccb5.
  3. Compare with Q3 on the same database and inspect the Q4 EXPLAIN plan.

Actual behavior

  • Q4 returned no rows before the client timeout in both runs: exit status 124, 1,200 seconds, 0 output lines. The client timeout is an external test limit; these runs do not prove the query would never complete.
  • In the diagnostic plan, store_sales, catalog_sales, and web_sales each appear in six Table Scan nodes, and customer appears in 18. The plan also contains repeated aggregations and joins. These are plan-node counts, not measured physical scan counts.
  • In the fourth process sample, the MO process showed cumulative average CPU of 5,685% and RSS of 13,578,660 KiB. Q4 was still present in the process list. Earlier samples showed RSS around 17.4 GiB.
  • The captured service logs did not show the original hash build memory budget exceeded error or an OOM error. In the diagnostic run the lowest sampled /data3 available space was 346,915,270,656 bytes (about 323 GiB), above the protection floor.

Expected behavior

Q4 should complete within a reasonable and documented performance envelope on the 1T dataset. Please review the repeated CTE expansion and identify the actual runtime bottleneck; an authoritative Q4 baseline or SLO is not yet available for this environment.

Stability and controls

  • Reproducer: 2/2 exceeded 1,200 seconds on the same main commit; the runs used the same 1T database and configuration. An earlier run on another commit exceeded 600 seconds.
  • Control: Q3 returned successfully in 6 seconds in both 1,200-second Q4 runs.
  • The independent correctness of query results was not assessed. Four attempted goroutine stack captures produced empty files, so the slow operator and whether forward progress continues are not established.
  • The dedicated MO service was stopped after timeout (ActiveState=inactive, Result=success), and the workflow log confirms its owned drain was released.

Evidence

Code analysis

No confirmed code-level cause yet. Repeated year_total expansion in EXPLAIN is an investigation lead, not proof of causation. Please examine CTE reuse, operator runtime profiles, and a comparable Q4 baseline.

Regression coverage

After diagnosis and fix, add a TPC-DS 1T performance regression check with an agreed time envelope and relevant plan/operator metrics; independently validate query results.

Activity

  1. added this to the MO-202611 milestone on Nov 16, 2026
  2. added
    kind/bug
    on Nov 16, 2026
  3. added theissue type on Nov 16, 2026
  4. XuPeng-SH commented on Nov 17, 2026

    @XuPeng-SH
    Contributor

    转 QA 验证(不是验收通过,也不关闭本 issue)。

    关联修复:#32833 已于 2026-11-17 合入 main,merge SHA 7fc45a2be2424d887199c5949362855cbacfe30f(PR head a19258fbe50a25e15b774525df49559048b79fc0)。修复多输入谓词尚不可用时过早选择笛卡尔连接,并修正 SEMI 匹配覆盖率估计;未修改执行器、spill 或预算,也不是 CTE 物化/复用实现。

    已公开的验证证据及边界:

    • 作者报告同机 1T、单 CN / 64 CPUs:Q4 从 >300.051 s 超时到 85.360 s,结果与历史成功输出逐字节一致;超时对照没有完整结果可比较。Q35 两对均值 62.175→33.630 s,输出一致。测量基于历史 main 8e8708a8d3 加对应补丁,不是最终合并 SHA 的复测。
    • 上述实验采用 agg spill 4 GiB、sort spill 512 MiB、join spill 自动、MemoryMax 192 GiB 等条件,不是本 issue 原 40 GiB process limit / 全自动 spill / MemoryMax 180 GiB 环境的复测。不能直接把 85.360 s 当作原环境已验收的 SLO。
    • 作者报告 rebase 后完整 planner 测试通过;103 条 TPC-DS / 22 条 TPC-H 的捕获 fixture 计划构建通过,Q4/Q31 无条件 INNER JOIN 各从 1 降为 0;这不是新一轮原生 TPC-H 性能证据。
    • 评审在 37a72bd205867cac56506c09cba2e44b3ef9db52 上报告 7 项 focused planner tests、完整 planner suite(47.438 s)、EXPLAIN consumer、go vet 与 fresh native build 通过;精确 merge-base 负对照命中预期缺陷。评审明确未独立重跑作者的 1T 性能、fixture 对比与 111 包静态检查,且未取得这些项目的原始 receipts。
    • 合并前队列曾报 Ubuntu UT 失败。已读取 该 job 日志:失败发生于 setup-java 的 socket hang up,未产生 UT report,不能称为 UT 通过,也不是已验证的查询反例。本次交接没有自行运行测试。

    请 QA 在最终 main 上优先复跑本 issue 的原始 Q4 SQL(含记录的 SHA-256)、1T 数据及原 40 GiB / 自动 spill 配置,保留完整结果、耗时、operator profile、内存/磁盘与超时清理证据,并独立验证结果正确性;与同环境基线比较并明确性能 envelope。兼顾多输入/volatile 谓词、未知 tag/list 依赖、不可避免的 cross join,以及 SEMI 唯一/非唯一 key、空输入和物理换边;回归 Q35 和其他 TPC-DS/TPC-H 查询。未测范围由 QA 补齐,不把历史重复 CTE plan 节点数直接当作物理扫描次数或已证实根因。

    已读完 issue 与 PR 的现有完整评论,未发现适用的当前已验证反例或明确未完成的开发 follow-up。按持续交接流程改派唯一 @Ariznawlll;若原环境复测出现反例,请携带具体 SHA、配置与证据回转开发。

  5. Ariznawlll commented on Nov 18, 2026

    @Ariznawlll
    CollaboratorAuthor

    QA 阶段性验证(planner 层)+ 回归交付;1T 性能 envelope 待远端环境复测,issue 保持 OPEN。

    已验证(最终 main 517e1695388cbaf1135238d5ab0c19a4556fb551)

    1. 原始 Q4 SQL 溯源:从 issue 链接的 mo-auto-test artifact 下载 query4.sql,SHA-256 校验 b4804b6da5f5d4a2c809041d961df64021155eaca9fa723740cd0c080a6fccb5 与正文记录一致。
    2. Planner 单测(修复 fix(plan): avoid premature cross joins and correct semi-join coverage #32833 的 join_order/stats SEMI 覆盖率 focused 测试):PASS。
    3. 完整 pkg/sql/plan 包测试(35.3s,最终 main):ok,无回归。
    4. Q4 EXPLAIN 计划形态(5 表骨架 + 空 schema 即可成形):INNER join 41 个全部携带 Join Cond,无条件笛卡尔 join = 0,与官方声明"Q4 无条件 INNER JOIN 从 1 降为 0"一致;空数据集上 Q4 正常执行返回空输出(不再超时/卡死)。

    回归交付

    未覆盖(遵守正文边界,不算验收)

    • TPC-DS 1T 数据集上的原始 Q4 全量复跑(1200s 客户端超时、40 GiB process limit、MemoryMax 180 GiB、自动 spill 的原环境):本地资源不可承载,需在 mo-srv-129 或等价 64C/大内存远端执行;完成前本 issue 不关闭。
    • Q35 回归、operator profile、内存/磁盘采样等性能证据:同样待远端复测。

    下一步(需要):远端 1T 环境的一次完整复跑(含修复 SHA 与 operator profile),QA 即可给出最终 envelope 结论。

  6. Ariznawlll commented on Nov 18, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。129 上使用修复后的 main 复测 TPC-DS 1T 原始 Q4,95.107 秒正常完成,未复现原先 1,200 秒超时。

    关键证据

    • 版本:官方 main 87c44445f83e308ef12dd7ca0e570cec1e6690d9,包含修复 #32833;2026-11-18 在 129 单机验证。
    • 原 issue Q4 SQL 的 SHA-256 为 b4804b6da5f5d4a2c809041d961df64021155eaca9fa723740cd0c080a6fccb5。执行退出码 0,客户端耗时 94.260 秒、总耗时 95.107 秒;返回 100 行,输出 SHA-256 为 6017713acffe4e96b1d125969e4e09f33a663eb7b41ea1c91d67aefdb082b0cd,与 11 月 12 日保存的 MatrixOne 成功输出逐字节一致。Q3 对照正常完成,总耗时 7.302 秒。
    • 数据为迁移后的 TPC-DS 1T 库,迁移前后 25 表行数一致;TN auto-merge 已确认关闭。原始 SQL、计划、输出、耗时和资源采样保存在 129 的 /data3/codex-tpcds-sorted-1t-lab/catalog-reuse-20261118-87c44445/baseline-r3/,其中 summary.tsv、output-comparison.tsv 和 results/query4/ 可供核查。

    待解决点

    • 本次 agg_spill_mem=4 GiB、sort_spill_mem=512 MiB、join_spill_mem=0,服务 MemoryMax=192 GiB;与原报告的全自动 spill、180 GiB 服务内存配置不同,40 GiB process limit 尚未核实。输出已与历史 MO 结果对照,尚未完成独立引擎结果对照。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions