Bird
0
0

You created a partial index:

medium📝 Debug Q7 of 15
PostgreSQL - Indexing Strategies
You created a partial index:
CREATE INDEX idx_active_products ON products (price) WHERE available = true;
After running queries filtering on available = true, you notice the index is not used. What could be the problem?
AThe statistics are outdated; running ANALYZE may help.
BPartial indexes cannot be used on boolean columns.
CThe index must be created with UNIQUE keyword to be used.
DPostgreSQL does not support partial indexes on numeric columns.
Step-by-Step Solution
Solution:
  1. Step 1: Understand index usage

    Partial indexes can be used on boolean and numeric columns without UNIQUE.
  2. Step 2: Consider query planner behavior

    If statistics are outdated, PostgreSQL may not choose the index; running ANALYZE updates stats.
  3. Final Answer:

    The statistics are outdated; running ANALYZE may help. -> Option A
  4. Quick Check:

    Update stats to enable partial index use = A [OK]
Quick Trick: Run ANALYZE to refresh stats for index usage [OK]
Common Mistakes:
  • Believing partial indexes can't be on boolean columns
  • Thinking UNIQUE is required for partial indexes
  • Assuming numeric columns are unsupported

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes