Bird
0
0

Given the partial index:

medium📝 query result Q13 of 15
PostgreSQL - Indexing Strategies
Given the partial index:
CREATE INDEX idx_active_users ON users (last_login) WHERE active = true;
What will be the result of this query?
SELECT * FROM users WHERE active = true AND last_login > '2024-01-01';
AThe query will return no rows because partial indexes exclude all rows
BThe query will ignore the partial index and perform a full table scan
CThe query will cause a syntax error due to the partial index
DThe query will use the partial index and return matching rows quickly
Step-by-Step Solution
Solution:
  1. Step 1: Understand partial index condition

    The index covers rows where active = true, indexing last_login.
  2. Step 2: Analyze query filter

    The query filters on active = true and last_login > '2024-01-01', matching the index condition.
  3. Final Answer:

    The query will use the partial index and return matching rows quickly -> Option D
  4. Quick Check:

    Query matches partial index condition = uses index [OK]
Quick Trick: Query filters must match partial index WHERE to use it [OK]
Common Mistakes:
  • Assuming partial index causes syntax errors
  • Thinking partial index excludes all rows
  • Believing query ignores partial index if condition partially matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes