CS FundamentalsHardWipro · Cognizant technical pattern
Table Orders has a composite B-tree index on (city, amount). Which WHERE clause can use this index to narrow the search most effectively?
- A. WHERE amount > 500
- B. WHERE amount = 500 OR city = 'Delhi'
- C. WHERE UPPER(city) = 'DELHI'
- D. WHERE city = 'Delhi' AND amount > 500
Correct answer: D. WHERE city = 'Delhi' AND amount > 500
A composite index is sorted by city first, then amount, so it serves predicates on its leftmost prefix: an equality on city plus a range on amount is ideal. amount alone skips the leading column; the OR needs both columns independently; wrapping city in a function hides it from a plain index.
More DBMS and SQL questions
- Which of these queries is NOT valid in standard SQL?
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- Table Orders(id, cust, city, amount) rows: (1, 'Ana', 'Pune', 500), (2, 'Ben', 'Delhi', NULL), (3, 'Ana', 'Pune', 300), (4, 'Chen'…
- R(A, B, C, D) has FDs A → B and C → D. It is decomposed into R1(A, B), R2(C, D) and R3(A, C). Which statement is correct?