Some days ago I had a discussion on whether ORDER BY should be used in SQL Queries, or if this should be avoided in any case due to performance issues. My personal opinion is that the database should do these kinds of operations, and the application logic should not have to care about things like sorting. To further prove this thinking, I made some simple investigations on an Oracle 11g database, and I also found some references on the internet on this topic, probably the most relevant one at https://tkyte.blogspot.com/2005/08/order-in-court.html where the author states:
“ The only way to retrieve data from the database in some sorted order is to include an ORDER BY on your query. There is no substitute for ORDER BY.”
Given that, let’s have a look at the performance impact on using ORDER BY.