Repository navigation
Description
问题描述
PR #25822 (fix(sql): reimplement hash MARK join for IN subqueries) 导致 TPC-H 单机性能严重退化。
退化幅度
| Scale | 退化前 (07-17) | 退化后 (07-18) | 最新 (07-24) | 主要退化 Query |
|---|---|---|---|---|
| 1T | ~1,009s | ~2,189s | 2,693s | Q18: 85s → 1,240s (14x) |
| 100G | ~84.5s | ~104.5s | 134.6s | Q16: 0.6s→3.7s (6x), Q14: 0.7s→3.7s (5x) |
| 10G | ~8.9s | ~14.5s | 17.0s | Q18: 0.23s→1.4s (6x), Q16: 0.26s→0.9s (3.4x) |
TKE 集群 (3CN) 退化幅度明显更小:1T 仅 ~10% (Q18 1.6x),10G/100G 无退化。
根因分析
执行计划变化
PR #25822 将 IN 子查询(如 Q18 的 o_orderkey IN (SELECT l_orderkey FROM lineitem GROUP BY l_orderkey HAVING sum(l_quantity) > 314))从 SEMI join 改为 MARK join。
编译路径差异 (pkg/sql/compile/compile.go)
SEMI join → Hash Join(O(P+B)):
// compileShuffleJoinV2 line 3309
case plan.Node_INNER, plan.Node_LEFT, plan.Node_RIGHT, plan.Node_SEMI, plan.Node_ANTI, plan.Node_OUTER:
op := constructHashJoin(...) // ← 高效 hash joinMARK join → Loop Join(O(P×B)):
// compileShuffleJoin line 3505
case plan.Node_MARK:
rs = c.newProbeScopeListForBroadcastJoin(...) // ← broadcast 而非 shuffle
op := constructLoopJoin(...) // ← 嵌套循环 joincompileShuffleJoinV2 的 switch case 中 没有 plan.Node_MARK,导致 MARK join 无法走 shuffle hash join 路径,退化为 broadcast loop join。
Loop Join 的 O(P×B) 嵌套循环
// pkg/sql/colexec/loopjoin/join.go line 199-224
for i := ctr.probeIdx; i < count; i++ { // 每个 probe 行
for idx := 0; idx < len(mpbat); idx++ { // 遍历所有 build batch
for j := uint64(0); j < vec.Length(); j++ { // 每行做条件求值
// O(P × B) 总操作数
}
}
}TPC-H Q18 数据量 (SF=1000)
- Build 侧(子查询结果):~50K 行
- Probe 侧(orders 表):1.5 亿行
- Hash Join: O(P+B) ≈ 1.5 亿次操作
- Loop Join: O(P×B) ≈ 7.5 万亿次操作
为什么单机退化远大于分布式
SEMI (旧) MARK (新)
单机 1CN: broadcast + HASH JOIN broadcast + LOOP JOIN
O(P + B) = 85s O(P × B) = 1,240s → 14x 🔴
TKE 3CN: shuffle + HASH JOIN broadcast + LOOP JOIN
O(P/3 + B/3) = 165s O(P/3 × B) = 268s → 1.6x ⚠️
- 单机:只有 1 个 CN,O(P×B) 全部由一个节点承担,无法用并行缓解
- TKE:3 个 CN 并行处理,每个只承担 O(P/3 × B),部分弥补了算法劣势
复现
128 核单机 Binary Search 测试(commit 51098d6)也能复现:
- Q18: 230ms → 702ms (3.1x) — 在更强硬件上仍然退化,证明是算法问题
- Q16: 260ms → 406ms (1.6x)
建议修复
方案 1(推荐):在编译路径为 MARK join 启用 hash join
在 compileShuffleJoinV2 / compileShuffleJoin / compileProbeSideForBroadcastJoin 中为 plan.Node_MARK 使用 constructHashJoin 而非 constructLoopJoin。
Hash join operator 已通过 PR #25822 添加了 MARK join 支持(TrackNullKeys、IsMark()、validateMarkJoin()),但编译路径没有路由到它。
方案 2:规划阶段回退
当检测到 shuffle 场景时,将 MARK join 降级回 SEMI join + null key tracking 的方案。
验证
修复后应验证:
- TPC-H Q18 在 1T scale 回到 ~85s(单机)
- TPC-H Q16 在 100G scale 回到 ~0.6s
- 所有 IN/NOT IN 子查询的正确性测试通过
相关
- 引入 PR: fix(sql): reimplement hash MARK join for IN subqueries #25822
- 最佳回退 commit:
0d8111ae(07-16, PR fix(sql): reimplement hash MARK join for IN subqueries #25822 合并前) - 影响 Query: Q18 (IN + GROUP BY HAVING), Q16 (NOT IN), Q14, Q15, Q10
Activity
XuPeng-SH commentedon Jul 24, 2026
Controlled same-data A/B does not reproduce the claimed SF10 Q18 regression, and the MARK-join root-cause attribution is incorrect.
Controlled setup
GOMAXPROCS=10etc/launch/launch.toml(identical SHA-256)mo-data/tpch_10gtables and statisticsHAVING sum(l_quantity) > 314)0d8111aef18ed25...rebuilt from source in a detached worktreed8a464eb650d8111aedeclares 4.0.1, the old benchmark build only skips the startup downgrade guard. No planner, compiler, shuffle, group, join, scan, or runtime-filter code was changed.Each binary received 3 warm-up executions followed by 15 timed executions.
0d8111aed8a464eb65Both plans are the same relevant shape:
Q18 is not planned as MARK on either commit. PR #25822 also explicitly states: “ordinary filter-only IN already uses SEMI join planning.” Therefore the proposed chain
Q18 IN -> MARK -> broadcast LoopJoindoes not occur for this query, and adding MARK to the shuffle compiler cannot explain Q18. Q16 is likewise ANTI under the standard NOT NULL TPCH schema, not MARK.Do not compare cross-version
EXPLAIN ANALYZE timeConsumeddirectly here: #25843 changed SQL resource-accounting/analyzer semantics between these commits. Wall-clock under controlled A/B is the reliable comparison.The reported historical SF1000 slowdown may still be a real scale-dependent spill/shuffle regression, but it needs a real before/after Q18 physical plan, spill counters, CN memory, and exact runner/config evidence. It should be investigated under the existing Q18 aggregation/shuffle work (#20560; historical spill failure #24836), not attributed to #25822 without a plan showing MARK. The SF10 claim (0.23 s -> 1.4 s) is not reproducible under controlled same-data testing.
XuPeng-SH commentedon Jul 24, 2026
Follow-up with the two requested 128-runner workflow runs confirms a real Linux/amd64 performance regression, while still refuting the MARK-join attribution.
Compared runs:
9c2e84ad5c: run 30065338834, TPCH job 893957268920d8111aef1: run 30067127559, TPCH job 89400835066The runs are well controlled:
Binary Search On 128 New)128-runnerlabelGOAMD64=v3 GOEXPERIMENT=simdUsing turns 2-5 (excluding the first cold turn):
This is broad rather than Q18-only. Other large warm regressions include:
Counterexamples are important: SF100 Q1/Q6/Q19 are unchanged or slightly faster on current. So this is not a uniform runner-frequency or storage slowdown.
Conclusion:
0d8111aeand9c2e84adis confirmed.Please retitle/reframe this issue as a broad TPCH high-DOP regression and remove the unsupported MARK/LoopJoin causal claim. Keep Q18 as the strongest symptom, but do not implement a MARK-specific Q18 fix.
XuPeng-SH commentedon Jul 24, 2026
Third 128-runner comparison: run 30068844288 built MatrixOne
7d4a3e84e5(the #25822 commit). Same methodology: turns 2-5 only.0d8111ae7d4a3e849c2e84ad7d/basecurrent/7dThis proves that the Q18 regression is already fully present at
7d4a3e84; later changes through9c2e84addid not worsen Q18 (SF100 is actually ~7% faster). Q16 is also mostly regressed by this point: SF10 2.12x and SF100 2.57x versus baseline.However, this still does not isolate #25822.
0d8111ae..7d4a3e84contains 32 commits.7d4a3e84is merely the endpoint of that interval. Its direct parent is:The decisive experiment is
7ffd26c7e1versus7d4a3e84e5on the same 128-runner. Only that adjacent-commit A/B can attribute the regression to #25822.The three runs also show two phases:
7d4a3e84, SF10 is already 1.39x and SF100 1.19x slower overall; Q18/Q16 carry their full regression.7d4a3e84to9c2e84ad, another ~11-14% suite regression appears, concentrated differently (for example SF100 Q9/Q14/Q15/Q20/Q22), while Q18 is stable or better.So continue the binary search, but use the direct parent before changing the issue root cause or implementing a MARK-specific fix.
XuPeng-SH commentedon Jul 24, 2026
Decisive adjacent-commit A/B is now available for SF10:
7ffd26c7e167ff4b5fc3ce01313c49101116ea9b, run 30069979831 / job 894093875147d4a3e84e552f5295ed5ca8f92a34f9c510d723f, run 30068844288 / job 89405897951Same 128-runner workflow; turns 2-5 warm average:
7ffd26c77d4a3e84No query regressed by more than ~6%; changes are normal run variance. Q18 is ~5.3% faster after #25822, not slower. The whole suite is effectively unchanged/slightly faster.
Therefore #25822 is definitively not the cause of the observed SF10 regression. The regression already exists in its direct parent. Compared with the good
0d8111aebaseline:The correct regression range is now
0d8111ae..7ffd26c7(31 commits), excluding #25822. Continue binary search inside that range. A midpoint aroundd8ca64575dwould split it roughly in half.Important limitation: run 30069979831 intentionally ran SF10 only; SF100/1T were skipped. This adjacent A/B settles the claimed SF10 regression, but a direct-parent SF100 run is still needed before making an empirical high-scale claim. The plan-semantics evidence remains unchanged: canonical Q18 is SEMI, not MARK.
The issue title/root-cause section should now be corrected; keeping #25822 as the blamed change contradicts direct adjacent-commit evidence.
perf(malloc): reduce mmap faults for large hash tables (#26143)
perf(shuffle): reduce pool contention (#26160)
XuPeng-SH commentedon Jul 28, 2026
fixed
Ariznawlll commentedon Jul 29, 2026
最新单机main commit:3c877f635be75b918f4e01e1a8abf01c77dfdd19 tpch性能已恢复
job:https://github.com/matrixorigin/mo-auto-test/actions/runs/30383489176
perf(malloc): reduce mmap faults for large hash tables (matrixorigin#…
perf(shuffle): reduce pool contention (matrixorigin#26160)
perf(malloc): reduce mmap faults for large hash tables (matrixorigin#…
perf(shuffle): reduce pool contention (matrixorigin#26160)
perf(malloc): reduce mmap faults for large hash tables (matrixorigin#…
perf(shuffle): reduce pool contention (matrixorigin#26160)