how does SELECT TOP works when no order by is specified?

后端 未结 1 373
梦如初夏
梦如初夏 2020-12-09 16:42

The msdn documentation says that when we write

SELECT TOP(N) ..... ORDER BY [COLUMN]

We get top(n) rows that are sorted by column

相关标签:
1条回答
  • 2020-12-09 17:23

    There is no guarantee which two rows you get. It will just be the first two retrieved from the table scan.

    The TOP iterator in the execution plan will stop requesting rows once two have been returned.

    Likely for a scan of a heap this will be the first two rows in allocation order but this is not guaranteed. For example SQL Server might use the advanced scanning feature which means that your scan will read pages recently read from another concurrent scan.

    0 讨论(0)
提交回复
热议问题