Bird
0
0

A composite index on (category, price) was created, but queries filtering only on price are slow. You try this query:

medium📝 Debug Q7 of 15
SQL - Indexes and Query Performance
A composite index on (category, price) was created, but queries filtering only on price are slow. You try this query:
SELECT * FROM products WHERE price < 100;

What is the best fix?
AChange the composite index to (price, category).
BAll of the above.
CRewrite the query to include category in WHERE.
DCreate a separate index on price alone.
Step-by-Step Solution
Solution:
  1. Step 1: Identify index limitation

    Composite index on (category, price) cannot optimize queries filtering only on price.
  2. Step 2: Consider fixes

    Creating a separate index on price, changing index order, or adding category filter all help.
  3. Final Answer:

    All of the above. -> Option B
  4. Quick Check:

    Multiple fixes possible for index order issues = A [OK]
Quick Trick: Fix slow queries by adjusting index or query filters [OK]
Common Mistakes:
  • Ignoring need for index on filtered columns
  • Assuming query rewrite is always needed
  • Not considering multiple solutions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes