Bird
0
0

A query retrieves product_id, price, and stock from a table. The existing index is on (product_id, price). Why might the query still perform poorly?

medium📝 Debug Q7 of 15
SQL - Indexes and Query Performance
A query retrieves product_id, price, and stock from a table. The existing index is on (product_id, price). Why might the query still perform poorly?
AThe index does not include the <code>stock</code> column, so the database must access the table rows
BThe index columns are in the wrong order for the query
CThe index is too large and slows down the query
DThe query does not use any indexed columns in its WHERE clause
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the index and query columns

    The index covers product_id and price, but the query also selects stock.
  2. Step 2: Understand covering index behavior

    Since stock is not in the index, the database must perform a lookup on the table rows, causing slower performance.
  3. Step 3: Evaluate options

    The index does not include the stock column, so the database must access the table rows correctly identifies the cause. The index columns are in the wrong order for the query is incorrect because column order affects filtering but not covering. The index is too large and slows down the query is speculative and not necessarily true. The query does not use any indexed columns in its WHERE clause is incorrect because the query does use indexed columns.
  4. Final Answer:

    The index does not include the stock column, so the database must access the table rows -> Option A
  5. Quick Check:

    Missing column in index causes table lookup [OK]
Quick Trick: All selected columns must be in index for speed [OK]
Common Mistakes:
  • Assuming column order always causes slowness
  • Believing index size alone slows query
  • Ignoring that missing columns cause table access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes