Sobes.tech
Middle+

What is the difference between the EXPLAIN and EXPLAIN ANALYZE commands 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 DBMS intends to execute it, without actually running the query. It provides information about the sequence of operations, index usage, cost estimates, and the number of rows.

EXPLAIN ANALYZE not only shows the plan but also executes the query, collecting real statistical data on the execution time of each operation and the number of processed rows. This allows comparing the plan with actual behavior and identifying bottlenecks.

Example:

EXPLAIN SELECT * FROM users WHERE id = 10;
EXPLAIN ANALYZE SELECT * FROM users WHERE id = 10;

The first will show the estimated plan, the second — the plan with real execution metrics.

What is the difference between the EXPLAIN and… - sobes.tech