Build the mental model
`EXPLAIN` shows an estimated plan without executing the query; `EXPLAIN ANALYZE` executes it and adds actual metrics. Cost is not milliseconds. Large estimated-versus-actual row gaps can reveal stale statistics or data correlation. `BUFFERS` exposes cache and page activity.
Connect it to a real scenario
Compare the published-feed plan before and after its index. Remember that `EXPLAIN ANALYZE` really executes writes, so test modifying statements only in a safe transaction or staging environment.
Try the working example
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;The execution plan shows scan type, estimated/actual rows, and buffer usage.5-minute try-it
Capture a plan before and after adding an index, then describe three changes.
One important caution
Do not assume a sequential scan is wrong on a small table; it can genuinely be cheaper than index access.
PostgreSQL — Using EXPLAIN — PostgreSQL Global Development Group