Bird
0
0

You created a partial index:

medium📝 Debug Q14 of 15
PostgreSQL - Indexing Strategies
You created a partial index:
CREATE INDEX idx_recent_orders ON orders (order_date) WHERE order_date > CURRENT_DATE - INTERVAL '30 days';
But queries filtering order_date > CURRENT_DATE - INTERVAL '30 days' are not using the index. What is the likely problem?
APartial indexes cannot use date intervals
BThe index is missing the column <code>order_date</code>
CThe partial index condition uses a non-immutable function, so it cannot be used
DThe WHERE clause in the index is invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Check partial index WHERE clause

    The WHERE clause uses CURRENT_DATE, which is non-immutable (changes daily).
  2. Step 2: Understand index usage limitation

    PostgreSQL partial indexes require immutable conditions to be used by queries.
  3. Final Answer:

    The partial index condition uses a non-immutable function, so it cannot be used -> Option C
  4. Quick Check:

    Non-immutable functions block partial index usage [OK]
Quick Trick: Partial index WHERE must use immutable expressions [OK]
Common Mistakes:
  • Assuming syntax error causes issue
  • Thinking partial indexes can't use date columns
  • Ignoring function immutability rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes