Subjects Questions Quizzes Pricing
Intermediate Open Pro

EXPLAIN ANALYZE Diagnosis

A query SELECT * FROM products WHERE category_id = 3 runs slowly on a table with 2 million rows. You run EXPLAIN ANALYZE and see:

Seq Scan on products  (cost=0.00..45000.00 rows=1200000 width=128)
                      (actual time=0.055..8420.221 rows=1195432 loops=1)
  1. Why is Postgres using a sequential scan instead of an index?
  2. What would you do to investigate and fix this?
← Back to Database Indexing practice