CS FundamentalsHardAmazon · Microsoft MCQ pattern

A query planner chooses a full table scan over using an available index on a WHERE column. Which scenario makes this the RIGHT choice, not a missed optimization?

  1. A. The indexed column is the primary key
  2. B. The query's WHERE condition matches a very large fraction of the table's rows (low selectivity), so the extra cost of random-access lookups via the index outweighs just scanning sequentially
  3. C. The table has no rows at all
  4. D. An index always makes every query faster, so this would never be correct

Correct answer: B. The query's WHERE condition matches a very large fraction of the table's rows (low selectivity), so the extra cost of random-access lookups via the index outweighs just scanning sequentially

Indexes help most for highly selective conditions (few matching rows), where seeking directly to matches beats scanning everything. If a condition matches most of the table, a sequential scan reading pages in order can actually be cheaper than a flood of (often random) index-driven lookups, which is exactly the kind of case-by-case decision a cost-based query optimizer is meant to make.

More DBMS and SQL questions

Exams that ask this topic