Bird
0
0

You want to optimize a query that uses Bitmap Index Scan but runs slowly because it matches many rows. Which approach can improve performance?

hard📝 optimization Q15 of 15
PostgreSQL - Performance Tuning
You want to optimize a query that uses Bitmap Index Scan but runs slowly because it matches many rows. Which approach can improve performance?
AAdd more selective WHERE conditions to reduce matching rows before Bitmap Index Scan
BDrop the index to force a sequential scan
CIncrease the work_mem setting to allow larger bitmaps in memory
DRewrite the query to use a JOIN instead of WHERE clause
Step-by-Step Solution
Solution:
  1. Step 1: Understand Bitmap Index Scan memory usage

    Bitmap Index Scan builds a bitmap in memory; if too large, it spills to disk, slowing performance.
  2. Step 2: Improve performance by adding selective conditions

    Adding more selective WHERE conditions reduces matching rows, making bitmap smaller and faster.
  3. Step 3: Evaluate other options

    Increasing work_mem helps but may not be sufficient; dropping index or rewriting query may not improve bitmap scan efficiency.
  4. Final Answer:

    Add more selective WHERE conditions to reduce matching rows before Bitmap Index Scan -> Option A
  5. Quick Check:

    More selective WHERE = smaller bitmap = faster scan [OK]
Quick Trick: Add selective WHERE clauses to reduce bitmap size [OK]
Common Mistakes:
  • Dropping index thinking it helps performance
  • Assuming increasing work_mem always solves slowness
  • Believing rewriting query always improves bitmap scan

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes