Find the bugs: retrieving items from two orders
Retrieve items from orders 1 and 2 with quantities between 5 and 10, inclusive. Show each item's ID, order ID, and quantity. Sort the results by item ID. The production database has a composite B-tree index on (order_id, quantity). A developer has tried to use the index by comparing composite keys. Find the lines that cause the query to return incorrect results.
Find the errorsIndexesMiddleBackendData EngineerQA
Input data · iv_order_items
| id | order_id | product | quantity | price |
|---|---|---|---|---|
| 1 | 1 | pen | 10 | 2.00 |
| 2 | 1 | notebook | 1 | 10.00 |
| 3 | 2 | pen | 1 | 4.00 |
| 4 | 3 | notebook | 5 | 10.00 |
| 5 | 3 | bag | 1 | 50.00 |
| 6 | 4 | pen | 2 | 3.00 |
| 7 | 5 | pen | 3 | 10.00 |
| 8 | 7 | bag | 2 | 60.00 |
| 9 | 8 | notebook | 2 | 40.00 |
SELECT id,
order_id,
quantity
FROM iv_order_items
WHERE (order_id, quantity) >= (1, 5) AND (order_id, quantity) <= (2, 10)
ORDER BY id