Bird
0
0

If a table sales has an index on sale_date, what is the expected result of this query?

medium📝 query result Q5 of 15
PostgreSQL - Indexing Strategies
If a table sales has an index on sale_date, what is the expected result of this query?
SELECT COUNT(*) FROM sales WHERE sale_date BETWEEN '2023-01-01' AND '2023-01-31';
AThe index will speed up counting rows in the date range
BThe index will slow down the query
CThe query will ignore the index and scan all rows
DThe query will return zero rows
Step-by-Step Solution
Solution:
  1. Step 1: Understand index range scans

    Indexes on date columns allow efficient range queries like BETWEEN to quickly find matching rows.
  2. Step 2: Analyze the query

    The query counts rows in a date range, so the index on sale_date will speed up the search.
  3. Final Answer:

    The index will speed up counting rows in the date range -> Option A
  4. Quick Check:

    Range queries on indexed columns use index range scans [OK]
Quick Trick: Indexes speed up range queries on indexed columns [OK]
Common Mistakes:
  • Thinking indexes slow down counting
  • Assuming full table scan always
  • Believing query returns zero without data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes