| 指標 | 含義 | 異常判斷 |
| Total Hash Joins | Hash Join 總執行次數 | 基線對比 |
| Hash Join Overflows | Build 表溢寫磁盤次數 | > 0 表明 sortheap 不足 |
| Hash Joins Small Overflows | 溢出 < 10% 內存 | 增大 sortheap 可消除 |
| Total Hash Loops | 單分區超過 sortheap 觸發遞歸 Hash | 最嚴重,性能指數級下降 |
| Hash Join Threshold | sortheap 請求受 sheapthres 限制次數 | > 0 表明 sheapthres 偏小 |
實驗一:sortheap 影響 (固定 sheapthres=192000 頁)
sortheap(pages) | 相對耗時 | Overflows | Hash Loops | Threshold Hits
-----------------|----------|-----------|------------|---------------
256 | 1.00 (基線) | 多 | 多 | 0
500 | 0.65 | 少 | 明顯減少 | 0
1000 | 0.45 | 少 | 進一步減少 | 0
4000 | 0.20 | 極少 | 0 | 0
40000 | 0.15 (最優) | 3 | 0 | 0
50000 | 0.18 | 多 | 0 | 多
100000 | 0.30 | 更多 | 0 | 更多
核心發現
- Hash Loops 是性能殺手:從 256→4000 頁,Hash Loops 歸零帶來數量級提升
- sheapthres 成為瓶頸:sortheap > 40000 時命中 Threshold,實際獲得內存 < 申請值,反而增加 Overflows
- 最佳點:sortheap 足夠消除 Hash Loops,但未觸及 sheapthres 限制
實驗二:sheapthres 影響 (固定 sortheap,變 sheapthres = 2x~7x sortheap)
sheapthres/sortheap | 相對耗時 | Hash Loops | Threshold Hits
--------------------|----------|------------|---------------
2x | 1.00 | 存在 | 多
3x | 0.70 | 消失 | 明顯減少
4x-7x | 0.65-0.60| 0 | 0
>7x | 持平 | 0 | 0
關鍵結論
- sheapthres ≥ 3x sortheap 可消除 Threshold Hits (官方建議最小 3x)
- sheapthres 對性能影響 次於 sortheap:消除 Hash Loops 收益遠大於消除 Threshold Hits
- 內存資源有限時,優先分配給 sortheap,再滿足 sheapthres ≥ 3x sortheap
調優方法論
- 基線測量:收集典型負載下的監控快照
- 估算併發度:DSS 環境典型併發流數 5-9 (非用戶數)
- 計算初始值:
sheapthres ≈ 物理內存 50% (扣除 Bufferpool)
sortheap = sheapthres / (併發流數 × 單查詢最大並發排序/Hash Join數)
# 典型除數 5-6
- 迭代驗證:單參數變更 → 跑負載 → 對比監控指標 → 確認無 Hash Loops/Threshold Hits
- 生產固化:納入變更管理,監控長期趨勢
黃金法則
使 sortheap 盡可能大以避免 Overflows 和 Hash Loops,但不超過 sheapthres 限制導致 Threshold Hits。
Hash Join 調優本質是內存資源在「單操作最大需求」與「實例總量上限」間的平衡藝術。掌握監控指標含義與參數交互機制,即可科學調優而非盲目試錯。
- 上一篇文章: 數據庫連接算子深度對比:Hash Join vs Nested Loop vs Sort Merge
- 下一篇文章: VMware Ubuntu 忘記密碼單人模式重置全流程
Copyright ©
程式碼之家 All Rights Reserved