- All Courses
- PostgreSQL for Application Developers
- Making Queries Fast
- Reading EXPLAIN ANALYZE
Reading EXPLAIN ANALYZE
EXPLAIN shows the plan; adding ANALYZE runs the query and reports what actually happened.
Overview
The plan is the evidence
EXPLAIN shows the plan; adding ANALYZE runs the query and reports what actually happened. Guessing at query performance without it is guesswork, and the guess is usually wrong.
Read from the innermost nodes outward — those run first — and find where the time accumulates. Note that costs shown are cumulative, so the interesting number is the node exclusive time.
A sequential scan is not automatically bad; on a small table it is the fastest option. The red flag is a sequential scan over a large table where you expected an index, which usually means the index cannot serve the predicate as written.
In this lesson you will:
- Read a plan from the inside out
- Compare estimated and actual rows
- Spot the node that dominates the time
Resources
Notes are not saved yet — they clear when you leave this page.
Indexes: B-tree, GIN, and partial
13m
Transactions and isolation levels
8m