What is the difference between EXPLAIN and EXPLAIN ANALYZE?
Asked at
AI answer
EXPLAIN shows the plan the optimizer intends to use: the estimated access types, indexes, and row counts. It usually does not execute the query itself.
EXPLAIN ANALYZE executes the query and shows actual metrics—for example, the time taken and number of rows processed at each step of the plan. This helps compare the optimizer’s estimates with reality, but the query generates normal database load, so use it cautiously in production. In MySQL, EXPLAIN ANALYZE is available starting with 8.0.18 and uses the TREE format.
Also asked at SkyCoach
Similar questions
- What do you know about indexes? How can you determine which indexes are used in a query, and how can you tell which indexes are unnecessary or missing?
- What is the difference between COUNT(*) and COUNT(column_name)?
- What is a composite index, what is the main principle behind how it works, and how do you choose which fields to include?
- Explain what the EXPLAIN command does in SQL queries.
- What are the standard transaction isolation levels?