Introduction
In this chapter, we analyze some performance issues related to the most time-consuming operation in the database—sort operations.
In the next few recipes, you will see that sorting is related not only to the order-by clause in an SQL query, but also to other type of statements, such as group by and distinct, set operations, ranking, certain kinds of joins and subqueries, as well as index creation.
In the first recipe, we will see the difference between in-memory and on-disk sort operations, and the differences between optimal, one pass, and multi-pass sort operations.
The second recipe is about sorting and indexing. In this recipe, observe how an index can change the execution plan of a query, hence improving the performance by reducing or avoiding sort operations altogether.
In the third recipe, we will investigate what happens when we perform the top n queries, queries which return the first n elements of a sorted set—and how to tune such statements.
In the fourth recipe, we will...