Middle+
SQL team command for obtaining the execution plan of a query.
sobes.tech AI
Answer from AI
The EXPLAIN command is used to obtain the execution plan of an SQL query.
Example:
EXPLAIN SELECT * FROM orders WHERE customer_id = 123;
Different database management systems may have extensions; for example, in PostgreSQL, you can use EXPLAIN ANALYZE to get a detailed plan with actual costs and execution time:
EXPLAIN ANALYZE SELECT * FROM orders WHERE customer_id = 123;
This helps understand how the optimizer executes the query, which indexes are used, and identify bottlenecks for optimization.