Bird
0
0

A table sales has indexes on region and sale_date. You run this query:

medium📝 Debug Q7 of 15
SQL - Indexes and Query Performance
A table sales has indexes on region and sale_date. You run this query:
SELECT * FROM sales WHERE region = 'North' AND sale_date < '2023-01-01';

The query is slow. What is a likely cause?
AThe table has no rows
BThe indexes are corrupted
CThe query optimizer is not using a combined index
DThe query syntax is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Understand index usage for multiple conditions

    Separate indexes on region and sale_date may not be combined efficiently; a composite index on both columns would help.
  2. Step 2: Check query and data

    The syntax is valid and table likely has data; slow query suggests optimizer can't use indexes well.
  3. Final Answer:

    The query optimizer is not using a combined index -> Option C
  4. Quick Check:

    Composite indexes help multi-column filters = D [OK]
Quick Trick: Use composite indexes for multi-column WHERE filters [OK]
Common Mistakes:
  • Assuming separate indexes always speed multi-column queries
  • Blaming syntax for slow queries
  • Ignoring composite index benefits

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes