Terry Cheng
@terrychengtw
Taipei · UTC+8
主題Theme
語言Lang
按 D 切換主題 · L 切換語言press D for theme · L for language
← 回首頁 ← Back to index
2025·09·05 深入 Deep dive 16 min · postgres

一支 query 吃掉我整個週末的故事

explain analyze 從 300 行讀到 0 行,中間換了三次假設。這是慢 query 修復的完整過程。

事後剖析——撰寫中。

起點

週五下班前收到「query timeout」警告——一支跑三年的 SQL 突然炸了。

假設一(錯)

index 壞了——跑 REINDEX,沒效。

假設二(錯)

統計資訊過期——跑 ANALYZE,沒效。

假設三(對)

plan 換了——新版本 Postgres 改了 cost model,原本被選中的 index scan 變成 seq scan。pg_hint_plan 暫時鎖定 plan,之後再慢慢重寫 query。

一次寫一點 慢慢累積 one thought at a time slowly