Contents / Previous / Next


Use Explain to Debug Query Performance

EXPLAIN display how a query will be executed (rather than executing it). EXPLAIN [ ANALYZE ] [ VERBOSE ] query ANALYZE: Carry out the query and show actual runtimes.
VERBOSE: Show detailed query plan.

Example:

EXPLAIN ANALYZE SELECT * FROM stud ; NOTICE: QUERY PLAN: Seq Scan on stud (cost=0.00..1.04 rows=4 width=78) (actual time=0.02..0.05 rows=6 loops=1) Total runtime: 0.11 msec EXPLAIN reports a sequential scan will be used on stud, meaning it will read the entire table.
The cost is an estimate of the work required to execute the query (the numbers are only meaningful for comparison).
The rows indicates the number of result rows expected. The width is the number of bytes per row.
The ANALYZE flag caused the query to be carried out and show actual Total runtime.