"Explain"
- MySQL Query Optimization:從 EXPLAIN 看到實際執行、5 條 query 從 5 秒變 50ms 的 anatomy
MySQL query 慢的根因不在「SQL 寫法」、在「optimizer 選錯 plan」。本文從 5 個常見 production case 開場(5 秒 → 50ms / 30 秒 → 200ms / 8 秒 → 30ms 等)、走 EXPLAIN / EXPLAIN ANALYZE / optimizer trace 三層分析工具、index hint vs optimizer hint 取捨、cardinality estimation 失效時的修法、5 production 踩雷(statistics 過時 / forced index 用錯 / hash join 沒觸發 / range scan 退化 ALL / derived table materialization)
- PostgreSQL Query Optimization:EXPLAIN ANALYZE / pg_hint_plan / auto_explain 三層工具跟 4 個 case
PG query 慢的根因常是 *planner 選錯 plan 或 statistics 過時*。本文從 4 個 production case 開場(seq scan vs index / hash vs nested loop / 多 column 統計缺 / parallel query 沒觸發)、走 EXPLAIN / EXPLAIN ANALYZE / auto_explain 三層工具、pg_hint_plan extension 跟 planner GUC 取捨、5 production 踩雷(ANALYZE 過時 / multi-column statistics / cost-base setting 不對齊硬體 / random_page_cost SSD 沒調 / parallel query 配置)、跟 MySQL query-optimization sibling 對比