Middle+
What is the difference between EXPLAIN and EXPLAIN ANALYZE in PostgreSQL?
sobes.tech AI
Answer from AI
In PostgreSQL, the EXPLAIN command shows the execution plan of an SQL query, that is, how the database intends to execute it (for example, which indexes to use, the order of operations).
EXPLAIN ANALYZE not only shows the plan but also actually executes the query, collecting statistics on the execution time of each step. This allows obtaining real performance data of the query.
Example:
EXPLAIN SELECT * FROM users WHERE id = 1;
EXPLAIN ANALYZE SELECT * FROM users WHERE id = 1;
The first query will show only the plan, while the second will show the plan plus actual time costs and the number of rows processed.