Sobes.tech
Intern

What is the difference between 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 will execute it, without actually running the query. It provides information about selected indexes, table scan sequences, joins, etc.

EXPLAIN ANALYZE not only shows the plan but also executes the query, collecting real statistical data on the execution time of each step and the number of rows processed. This helps to understand how well the plan matches the actual execution and to identify bottlenecks.

Example:

EXPLAIN SELECT * FROM users WHERE id = 10;
EXPLAIN ANALYZE SELECT * FROM users WHERE id = 10;
What is the difference between EXPLAIN and EXPLAIN… - sobes.tech