Bird
0
0

Why might PostgreSQL choose a sequential scan over an index scan even if an index exists and the query filters on the indexed column?

hard📝 Conceptual Q10 of 15
PostgreSQL - Performance Tuning
Why might PostgreSQL choose a sequential scan over an index scan even if an index exists and the query filters on the indexed column?
ABecause the index is only used for sorting, not filtering.
BBecause PostgreSQL does not support index scans on columns with NULL values.
CBecause sequential scans always use less memory than index scans.
DBecause the planner estimates that reading the whole table is cheaper than many random index lookups.
Step-by-Step Solution
Solution:
  1. Step 1: Understand planner cost estimation

    The planner estimates costs for sequential vs index scans based on data distribution and expected rows.
  2. Step 2: Explain scan choice

    If many rows match, sequential scan can be cheaper than many random index lookups, so planner chooses it.
  3. Final Answer:

    Because the planner estimates that reading the whole table is cheaper than many random index lookups. -> Option D
  4. Quick Check:

    Planner cost estimation drives scan choice = D [OK]
Quick Trick: Planner picks cheapest scan based on estimated cost [OK]
Common Mistakes:
  • Thinking NULL values prevent index scans
  • Assuming sequential scan always uses less memory
  • Believing indexes are only for sorting

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes