Bird
0
0

You wrote this query:

medium📝 Debug Q14 of 15
PostgreSQL - Performance Tuning
You wrote this query:
SELECT * FROM orders WHERE customer_id = 123;
But EXPLAIN shows a sequential scan instead of an index scan. What could be the reason?
AThere is no index on <code>customer_id</code>
BThe table is empty
CThe query syntax is incorrect
DPostgreSQL always uses sequential scan
Step-by-Step Solution
Solution:
  1. Step 1: Check index presence on filter column

    If no index exists on customer_id, PostgreSQL must scan all rows sequentially.
  2. Step 2: Evaluate other options

    Empty table would still show scan but no rows; syntax is correct; PostgreSQL chooses scan type based on indexes.
  3. Final Answer:

    There is no index on customer_id -> Option A
  4. Quick Check:

    No index on filter column = sequential scan [OK]
Quick Trick: No index on filter column causes sequential scan [OK]
Common Mistakes:
  • Assuming syntax error causes scan type
  • Thinking PostgreSQL always uses sequential scan
  • Ignoring missing index as cause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes