Bird
0
0

Given the table users(id INT, email TEXT) and the index:

medium📝 query result Q4 of 15
PostgreSQL - Indexing Strategies
Given the table users(id INT, email TEXT) and the index:
CREATE INDEX idx_lower_email ON users (LOWER(email));
What will the query SELECT * FROM users WHERE LOWER(email) = 'test@example.com'; use?
AThe expression index idx_lower_email to speed up the search
BA sequential scan ignoring the index
CThe primary key index on id
DAn error because LOWER(email) cannot be indexed
Step-by-Step Solution
Solution:
  1. Step 1: Understand how expression indexes are used in queries

    When a query uses the same expression as the index (LOWER(email)), PostgreSQL can use that index to speed up the search.
  2. Step 2: Analyze the query and index

    The query filters by LOWER(email), matching the expression index idx_lower_email, so the index will be used.
  3. Final Answer:

    The expression index idx_lower_email to speed up the search -> Option A
  4. Quick Check:

    Query expression matches index expression = index used [OK]
Quick Trick: Query expression must match index expression exactly to use it [OK]
Common Mistakes:
  • Assuming expression indexes are ignored in queries
  • Thinking primary key index will be used instead
  • Believing expression indexes cause errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes