Junior — Middle
What is the purpose of the EXPLAIN ANALYZE command in a database management system?
sobes.tech AI
Answer from AI
The EXPLAIN ANALYZE command in database management systems is used for analyzing and optimizing queries. It executes the query and simultaneously shows the execution plan with detailed statistics, including the actual time taken for each step and the number of rows processed.
This helps understand which parts of the query are slow, where table scans occur, which indexes are used, and allows for query optimization to improve performance.
Example of usage in PostgreSQL:
EXPLAIN ANALYZE SELECT * FROM users WHERE age > 30;
The output will show the execution plan and actual time costs, which is useful for diagnostics and optimization.