set statistics io on

--清空缓存数据
dbcc dropcleanbuffers
go
--清空缓存计划
dbcc freeproccache
go set statistics io on
go select distinct Productid,unitprice from salesorderdetail_test where Productid=777
go

执行上面代码获取以下信息:

(4 row(s) affected)
Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'SalesOrderDetail_Test'. Scan count 1, logical reads 481, physical reads 1, read-ahead reads 584, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

各数据详解:

1.Table

表的名称

2.scan count

执行的扫描次数

3.logical reads

从数据缓存读取的页数

4.physical reads

从磁盘读取的页数

5.read-ahead reads

为进行查询而预读入缓存的页数

6.lob logical reads

从数据缓存读取的Text,Ntext,Image或大值类型(Varchar(max),Nvarchar(max),Varbinary(max))页的数目

7.lob physical reads

从磁盘读取的Text,Ntext,Image或大值类型(Varchar(max),Nvarchar(max),Varbinary(max))页的数目

8.lob read-ahead reads

为进行查询而预读入缓存的Text,Ntext,Image或大值类型的页数

physical reads+read-ahead reads 就是SQL SERVER为了完成这句查询而从磁盘上读取的页数,如果不为0,说明数据没有缓存在内存里,运行速度一定收到了影响。

05-11 10:50