Bird
0
0

Given a table users(id, name, email) with an index on (id, email), which query can use an index-only scan?

medium📝 query result Q13 of 15
PostgreSQL - Indexing Strategies
Given a table users(id, name, email) with an index on (id, email), which query can use an index-only scan?
ASELECT id, email FROM users WHERE id = 10;
BSELECT name FROM users WHERE id = 10;
CSELECT email FROM users WHERE name = 'Alice';
DSELECT * FROM users WHERE email = 'a@example.com';
Step-by-Step Solution
Solution:
  1. Step 1: Check index columns and query columns

    The index covers columns id and email. Query C requests only id and email.
  2. Step 2: Determine if index-only scan is possible

    Query C can use index-only scan because all requested columns are in the index. Others request columns not in the index.
  3. Final Answer:

    SELECT id, email FROM users WHERE id = 10; -> Option A
  4. Quick Check:

    Query columns ⊆ index columns = index-only scan [OK]
Quick Trick: Index-only scan if query columns are subset of index columns [OK]
Common Mistakes:
  • Choosing queries requesting columns not in index
  • Ignoring WHERE clause columns
  • Assuming * always uses index-only scan

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes