Bird
0
0

Why does PostgreSQL sometimes choose a sequential scan over an index scan even when an index exists?

hard📝 Conceptual Q10 of 15
PostgreSQL - Performance Tuning
Why does PostgreSQL sometimes choose a sequential scan over an index scan even when an index exists?
ABecause indexes are only used for sorting, not filtering
BBecause the planner estimates that scanning the whole table is faster when many rows match
CBecause PostgreSQL does not support index scans on large tables
DBecause sequential scans always use less memory
Step-by-Step Solution
Solution:
  1. Step 1: Understand planner cost estimation

    The planner estimates costs and chooses the fastest method based on row counts and data distribution.
  2. Step 2: Recognize when sequential scan is preferred

    If many rows match, scanning the whole table can be faster than using an index.
  3. Final Answer:

    Because the planner estimates that scanning the whole table is faster when many rows match -> Option B
  4. Quick Check:

    Planner picks fastest plan based on row estimates [OK]
Quick Trick: Planner picks sequential scan if many rows match [OK]
Common Mistakes:
  • Thinking indexes are only for sorting
  • Believing PostgreSQL lacks index scan support
  • Assuming sequential scans always use less memory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes