နားလည်ထားရမယ့် အချက်
`EXPLAIN` က query မrun ဘဲ estimated plan ပြပြီး `EXPLAIN ANALYZE` က query ကိုတကယ် run ကာ actual metrics ထည့်ပေးပါတယ်။ Cost က milliseconds မဟုတ်ပါ။ Estimated rows နဲ့ actual rows အလွန်ကွာရင် statistics သို့ data correlation ပြဿနာဖြစ်နိုင်ပါတယ်။ `BUFFERS` က cache/disk page activity ကိုမြင်စေပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Published feed query ကို index မတိုင်မီ/ပြီးနောက် plan နှိုင်းမယ်။ Production write query ကို `EXPLAIN ANALYZE` လုပ်ရင် တကယ်ပြောင်းလဲမှာဖြစ်လို့ read-only transaction သို့ staging data ပေါ်မှာသာစမ်းပါ။
အတူတူ စမ်းရေးကြည့်မယ်
EXPLAIN (ANALYZE, BUFFERS, VERBOSE)
SELECT tutorial_id, title, published_at
FROM app.tutorials
WHERE is_published = true
ORDER BY published_at DESC, tutorial_id DESC
LIMIT 10;Scan type၊ row estimate/actual နှင့် buffer usage ပါသော execution plan ရမည်။၅ မိနစ် စမ်းကြည့်
Index တစ်ခု drop/create မလုပ်ခင်နှင့်လုပ်ပြီးနောက် plan ကိုကူးပြီး ဘာပြောင်းသလဲသုံးချက်ရေးပါ။
သတိလေးတစ်ချက်
Table သေးသေးမှာ sequential scan ရွေးတာကို အမှားမယူဆပါနှင့်—index lookup ထက်တကယ်ဈေးသက်သာနိုင်ပါတယ်။
PostgreSQL — Using EXPLAIN — PostgreSQL Global Development Group