Using GETSORTED Table Scan

This statement indicates one of the ways in which the result rows can be returned from a table. With Using GETSORTED Table Scan, the rows are returned in sorted order. However, not all queries that return rows in sorted order will have this step. If a query has an ORDER BY clause and an index with the proper sort sequence exists on the columns being ordered, an intermediate sort might not be necessary and the rows can simply be returned in order by using the available index. The Using GETSORTED Table Scan method is used when SQL Server must first create a temporary worktable to sort the result rows and then return them in the proper sorted order.

The following example shows a query that requires a worktable to be created and the rows returned in sorted order:

Query:

SELECT au_id, au_lname, au_fname, city
FROM authors
ORDER BY city

SHOWPLAN:

STEP 1
The type of query is INSERT
The update mode is direct
Worktable created for ORDER BY
FROM TABLE
authors
Nested iteration
Table Scan
TO TABLE
Worktable 1

STEP 2
The type of query is SELECT
This step involves sorting
FROM TABLE
Worktable 1
Using GETSORTED Table Scan