我们可以用 SET STATISTICS IO 和 SET STATISTICS TIME 对T-SQL语句进行性能分析。
方法如下:
在SQL Server查询分析器里面,执行:
SET STATISTICS profile ON
SET STATISTICS io ON
SET STATISTICS time ON
GO
-- // The SQL statement to analysis
GO
下面贴两张截图来展示一下执行的结果:
下面我们来详细看一下Messages:
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server parse and compile time:
CPU time = 218 ms, elapsed time = 223 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 0 ms.
(5 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 'tblPanel'. Scan count 1, logical reads 78, physical reads 3, read-ahead reads 78, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblVersion'. Scan count 1, logical reads 26, physical reads 2, read-ahead reads 24, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblLayer'. Scan count 5, logical reads 25, physical reads 8, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblControls'. Scan count 5, logical reads 30, physical reads 13, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblButtonControl'. Scan count 5, logical reads 30, physical reads 10, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblButtonState'. Scan count 5, logical reads 30, physical reads 9, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblButtonCommand'. Scan count 1, logical reads 11383, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
(22 row(s) affected)
CPU time = 125 ms, elapsed time = 509 ms.
尤其是:
一、CPU执行时间
SQL Server Execution Times:
CPU time = 125 ms, elapsed time = 509 ms.
二、I/O消耗
见以下信息:
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 'tblPanel'. Scan count 1, logical reads 78, physical reads 3, read-ahead reads 78, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblVersion'. Scan count 1, logical reads 26, physical reads 2, read-ahead reads 24, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblLayer'. Scan count 5, logical reads 25, physical reads 8, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblControls'. Scan count 5, logical reads 30, physical reads 13, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblButtonControl'. Scan count 5, logical reads 30, physical reads 10, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblButtonState'. Scan count 5, logical reads 30, physical reads 9, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'tblButtonCommand'. Scan count 1, logical reads 11383, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
(22 row(s) affected)
更详细的解释见这篇文章:
《sql查询性能调试,用SET STATISTICS IO和SET STATISTICS TIME---解释比较详细》http://blog.csdn.net/leamonjxl/article/details/6639978