Bird
0
0

If a composite index is created on columns (A, B), which query will NOT fully benefit from this index?

easy📝 Conceptual Q2 of 15
SQL - Indexes and Query Performance
If a composite index is created on columns (A, B), which query will NOT fully benefit from this index?
ASELECT * FROM table WHERE B = 20;
BSELECT * FROM table WHERE A = 10;
CSELECT * FROM table WHERE A = 10 ORDER BY B;
DSELECT * FROM table WHERE A = 10 AND B = 20;
Step-by-Step Solution
Solution:
  1. Step 1: Review composite index usage

    Composite index on (A, B) helps queries filtering on A or both A and B, but not on B alone.
  2. Step 2: Analyze each query

    Query filtering only on B cannot use the index efficiently because A is the first column.
  3. Final Answer:

    SELECT * FROM table WHERE B = 20; -> Option A
  4. Quick Check:

    Index on (A,B) can't optimize filter on B alone = D [OK]
Quick Trick: Index first column must be in WHERE for full benefit [OK]
Common Mistakes:
  • Assuming index helps filtering on second column alone
  • Ignoring column order in composite index
  • Thinking ORDER BY always uses index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes