简体   繁体   中英

OFFSET | FETCH Order By column - SQL Server

Can anyone explain to me on a very basic level what the performance difference would be for these 2 queries.

ORDER BY (select null)
OFFSET @Offset ROWS
FETCH NEXT @EntriesPerPage ROWS ONLY;

ORDER BY (ItemID)
OFFSET @Offset ROWS
FETCH NEXT @EntriesPerPage ROWS ONLY;

I would expect the first query to perform better because it is not ordering by a column but every time i test this the second query always performs better. Can anyone explain to me why the second query would run better for OFFSET / FETCH even though it is ordering by a column.

I run the queries separately. I wipe the cache plan and buffers between each query so that it doesn't use the previous execution plan.

Thanks

是的,第一个查询应该运行得更快,因为第二个查询需要执行其他排序操作。

First query should be faster .

Did you try executing second query first and see the difference in performance. Might be indexing and other performance attributes makes you feel second query executes faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM