PostgreSQLQuestion 02 of 11
Why a Seq Scan instead of an Index Scan?
Answer out loud or in your head first, then compare.
Answer
The planner compares the estimated cost of plans based on statistics and the query's conditions. A sequential read can be better for a small table or a query that returns a large share of the data.
SQL
EXPLAIN (ANALYZE, BUFFERS)
SELECT id, created_at
FROM orders
WHERE customer_id = 42;I check: estimated versus actual row counts, the number of loops, buffer reads, sorting and timing. A large estimation error can point to a statistics problem.
Pitfall: EXPLAIN ANALYZE actually runs the statement. For writes it changes data — it isn't a harmless preview. A Seq Scan alone doesn't prove there's a problem.
How did it go? Be honest — “Not yet” puts the question on your review list.