EXPLAIN और EXPLAIN ANALYZE
EXPLAIN वह plan दिखाता है जो PostgreSQL एक query के लिए इस्तेमाल करेगा, और EXPLAIN ANALYZE actually इसे चलाता है और real timings report करता है।
In this page:
Syntax
EXPLAIN SELECT columns FROM table_name WHERE condition;
EXPLAIN ANALYZE SELECT columns FROM table_name WHERE condition;
EXPLAIN/EXPLAIN ANALYZE
Plan को innermost line से बाहर की ओर पढ़ें। Seq Scan पूरी table पढ़ता है, Index Scan और Index Only Scan एक index इस्तेमाल करते हैं, और Bitmap scans index results combine करते हैं।
Cost numbers estimates हैं जबकि ANALYZE actual time और rows add करता है। Estimated और actual rows के बीच बड़े differences stale statistics suggest करते हैं, ANALYZE से fix होते हैं।
Note:
EXPLAIN ANALYZE statement actually execute करता है, इसलिए data-changing वालों को एक transaction में wrap करें और roll back करें।
उदाहरण: EXPLAIN/EXPLAIN ANALYZE
shop=# EXPLAIN ANALYZE SELECT * FROM users WHERE email = '[email protected]';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------
Index Scan using users_email_key on users (cost=0.42..8.44 rows=1 width=72) (actual time=0.030..0.031 rows=1 loops=1)
Index Cond: (email = '[email protected]'::text)
Planning Time: 0.120 ms
Execution Time: 0.055 ms
shop=# EXPLAIN SELECT * FROM users WHERE lower(name) = 'ada';
Seq Scan on users (cost=0.00..25.00 rows=1 width=72)
Filter: (lower(name) = 'ada'::text)
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- destructive statements पर EXPLAIN ANALYZE चलाना
- estimated और actual rows के बीच differences ignore करना
- बिना measuring के optimize करना
चैप्टर सारांश
- EXPLAIN plan दिखाता है
- ANALYZE इसे चलाता है और time करता है
- Seq Scan बनाम Index Scan
- Estimated और actual rows compare करें
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: