Middle+
What is the difference between the EXPLAIN and EXPLAIN ANALYZE commands in PostgreSQL?
sobes.tech AI
Answer from AI
The EXPLAIN command in PostgreSQL shows the execution plan of an SQL query, that is, how the database engine intends to retrieve the data (used indexes, sequential scans, joins, etc.). It does not execute the query itself, but only analyzes it.
EXPLAIN ANALYZE not only outputs the plan but also actually executes the query, collecting statistics on the execution time of each step and the number of rows processed. This allows you to see the actual performance and identify bottlenecks.
Example:
EXPLAIN SELECT * FROM users WHERE id = 10;
EXPLAIN ANALYZE SELECT * FROM users WHERE id = 10;
The first will show the plan, the second — the plan with real execution metrics.