Problem Statement
What is the primary reason to run EXPLAIN (or EXPLAIN ANALYZE) on a query?
Explanation
EXPLAIN shows how the optimizer intends to execute your SQL: join order, access paths, estimated rows, and operator costs. With ANALYZE, you also see actual rows and timing.
You use this to spot scans where seeks are expected, poor join choices, and misestimates that hint at stale statistics or non-SARGable predicates.
Code Solution
SolutionRead Only
EXPLAIN ANALYZE SELECT o.id, c.name FROM orders o JOIN customers c ON c.id=o.customer_id WHERE o.created_at >= CURRENT_DATE - INTERVAL '30 days';
Practice Sets
This question appears in the following practice sets:
