Senior
How does EXPLAIN differ from EXPLAIN ANALYZE?
sobes.tech AI
Answer from AI
EXPLAIN and EXPLAIN ANALYZE are commands used to analyze the execution of SQL queries, but they differ in the depth of information provided.
-
EXPLAIN shows the execution plan of the query, i.e., how the DBMS intends to execute it (for example, which indexes to use, the order of operations, join methods). This is a static analysis without actually executing the query.
-
EXPLAIN ANALYZE not only shows the execution plan but also executes the query, collecting real statistics: execution time of each step, number of processed rows, etc. This helps understand how well the plan matches the actual behavior and where bottlenecks might be.
Example in PostgreSQL:
EXPLAIN SELECT * FROM users WHERE age > 30;
EXPLAIN ANALYZE SELECT * FROM users WHERE age > 30;
The first shows the plan, the second — the plan with real metrics.