Data paging through stored procedures is commonly used in programming.
Mssql2000 uses set rowcount N for paging, but after mssql2005
Using Top N for paging is much more convenient, but some friends told me that set rowcount N is more efficient.
I don't know much about it, so I went online to find Top N and set rowcount N, and then found the answer on the official website:
The Top N clause is as fast as the set rowcount n statement when the index is correctly performed.
However, if the data is not sorted, the Top N is faster. Top N
During the operation, a small intermediate temporary table is used, and only the last row of the table is replaced.
If the input is approximately sorted, the Top N engine must delete or insert the last row, but only a few operations are required.
The approximate sorting means that the heap you are processing can be inserted in sequence during initial build, and
You do not need to perform many operations, such as updating, deleting, and moving the Pointer Forward.
Sorting an approximate sorting heap is more efficient than sorting a huge table. In a test, use
Top N is used to sort a table created by the unordered insert operation with the same number of rows,
Topn is not efficient. Generally, if you have performed an index or have not performed an index,
I/O time is the same, but if no index has been performed, sqlserver must perform
A full table scan. Processor time and actual consumption time indicate that the approximate sorting of stacks should be more
Efficiency. However, the I/O time is the same, because no matter how SQL Server reads all rows.