Bird
0
0

What is wrong with this query if the goal is to optimize it using an index?

medium📝 Debug Q7 of 15
PostgreSQL - Performance Tuning
What is wrong with this query if the goal is to optimize it using an index?
SELECT * FROM employees WHERE salary * 1.1 > 50000;
AThe query lacks an ORDER BY clause
BThe multiplication operator is invalid in WHERE clause
CThe query should use HAVING instead of WHERE
DThe expression salary * 1.1 prevents index usage on salary
Step-by-Step Solution
Solution:
  1. Step 1: Check expression on indexed column

    Using salary * 1.1 changes the column value, so index on salary is not used.
  2. Step 2: Understand index usage rules

    Indexes work on raw column values; expressions require special indexes.
  3. Final Answer:

    The expression salary * 1.1 prevents index usage on salary -> Option D
  4. Quick Check:

    Expressions on indexed columns block index use [OK]
Quick Trick: Avoid expressions on indexed columns in WHERE [OK]
Common Mistakes:
  • Thinking multiplication is invalid syntax
  • Confusing WHERE with HAVING
  • Assuming ORDER BY affects index use

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes