Bird
0
0

You have this query:

medium📝 Debug Q14 of 15
PostgreSQL - Performance Tuning
You have this query:
SELECT * FROM orders WHERE order_date = '2023-01-01';
It runs slowly. Which fix will likely improve performance?
AChange SELECT * to SELECT COUNT(*)
BAdd an index on the order_date column
CRemove the WHERE clause
DUse GROUP BY order_date
Step-by-Step Solution
Solution:
  1. Step 1: Identify the cause of slowness

    Query filters on order_date but may scan all rows without an index.
  2. Step 2: Apply optimization by indexing

    Adding an index on order_date lets PostgreSQL find matching rows faster.
  3. Final Answer:

    Add an index on the order_date column -> Option B
  4. Quick Check:

    Index on filter column = Faster query [OK]
Quick Trick: Index columns used in WHERE for faster filtering [OK]
Common Mistakes:
  • Removing WHERE loses filtering purpose
  • Changing SELECT * to COUNT(*) changes result, not speed
  • Using GROUP BY without aggregation is incorrect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes