Problem Statement
How can you help the optimizer avoid an explicit SORT operator for ORDER BY?
Explanation
If an index provides the required order, the engine can scan it and return rows already sorted. This removes the need for a costly sort step.
Column order and ASC or DESC matter. Consider covering includes to avoid extra lookups.
Code Solution
SolutionRead Only
CREATE INDEX idx_orders_date_id ON orders(order_date DESC, id DESC);
Practice Sets
This question appears in the following practice sets:
