Sorts and aggregation
Sort and aggregation operators are present in an execution plan when a query contains an ORDER BY and/or a GROUP BY clause. In some cases, SQL Server will introduce a sort in order to optimize the execution of a query, such as to enable a merge join or to improve the performance of a Nested Loops join. We may also see a Sort operator in an execution plan that contains SELECT DISTINCT. DISTINCT is effectively an aggregation as it requires grouping the rows and only returning one row per distinct set of values. A sort operation is a simple way to perform this type of aggregation. As discussed in the Query Optimization Essentials section of Chapter 2, Understanding Query Processing, SQL Server may also add a sort operator ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access