Middle
What is the difference between EXPLAIN and EXPLAIN ANALYZE?
sobes.tech AI
Answer from AI
EXPLAIN and EXPLAIN ANALYZE are commands in SQL that help understand how the DBMS executes a query.
- EXPLAIN shows the execution plan of a query, i.e., what operations will be performed and in what order, but does not execute the query itself.
- EXPLAIN ANALYZE executes the query and additionally shows the actual execution time of each operation and the number of rows processed.
Example in PostgreSQL:
EXPLAIN SELECT * FROM users WHERE age > 30;
EXPLAIN ANALYZE SELECT * FROM users WHERE age > 30;
The first will show the plan, the second — the plan plus real execution metrics.