SELECT * FROM employees WHERE department_id = 5; run with EXPLAIN ANALYZE. What kind of information will the output include?EXPLAIN ANALYZE SELECT * FROM employees WHERE department_id = 5;
EXPLAIN ANALYZE executes the query and shows the real execution plan with actual times and rows processed at each step, unlike plain EXPLAIN which only shows estimates.
EXPLAIN ANALYZE is more useful for query optimization than EXPLAIN?EXPLAIN shows only estimated costs, which may differ from reality. EXPLAIN ANALYZE runs the query and shows actual timing and row counts, which helps identify slow parts.
In PostgreSQL, options like ANALYZE and BUFFERS are specified inside parentheses after EXPLAIN, e.g., EXPLAIN (ANALYZE, BUFFERS) ....
EXPLAIN ANALYZE BUFFERS SELECT * FROM products; (missing parentheses around BUFFERS)?Options like BUFFERS must be inside parentheses. Omitting them causes a syntax error near the option keyword.
EXPLAIN ANALYZE on a query and see a step with estimated time 1 ms but actual time 100 ms. What does this difference usually indicate?A large gap between estimated and actual times usually means the planner's statistics are stale or incomplete, causing it to pick a suboptimal plan.
