如果使用offset fetch next,则select中的子查询仅执行5次rec

时间:2017-03-16 15:43:32

标签: sql-server

这是一个虚拟查询,我想知道,md col查询(相关子查询)将仅执行5条记录或sales.customer表的所有记录。

    SELECT CustomerID, 
(SELECT TOP 1 Sales.SalesTerritory.ModifiedDate
FROM Sales.SalesTerritory 
WHERE Sales.SalesTerritory.TerritoryID = Sales.Customer.TerritoryID) md
FROM Sales.Customer 
ORDER BY CustomerID OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY

你真诚的

1 个答案:

答案 0 :(得分:0)

都不是。它执行了15次。

(5 row(s) affected)
Table 'SalesTerritory'. Scan count 0, logical reads 30, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Customer'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

执行计划:https://www.brentozar.com/pastetheplan/?id=SyAKE4djx

enter image description here