Press "Enter" to skip to content

ORDER BY Can Change the Query Plan

Erik Darling notes that adding an ORDER BY clause to a query can change the underlying query plan:

Sometimes I think it’s interesting how adding a seemingly useless or harmless thing to a query can change the query plan.

Here’s a quick example using an Order By on an indexed column.

Your mileage may vary on whether that’s a good thing.