SQL 多次返回的查询性能统计消息
SQL query performance statistics messages returned multiple times
我是 运行 在 SQL Server management studio 上查询 1 并且看到它 returns 我喜欢 3 条消息,但是当内部存储过程有近 10 - 20 条消息时统计数据。发生了什么事,为什么我看到他们?
SET STATISTICS IO,TIME ON;
GO
SELECT [UserId]
,[UserType]
,[CreateDT]
,[EffectiveDT]
FROM [dbo].[People] ORDER BY [UserId]
SET STATISTICS IO,TIME OFF;
GO
我收到的消息如下
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
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.
Table 'People'. Scan count 1, logical reads 155, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 143 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 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 Execution Times:
CPU time = 0 ms, elapsed time = 143 ms.
查询的总耗时是 143ms + 143ms 吗?
见下文
set statistics time on
select * from test
set statistics time off
输出:
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 264 ms..
现在添加打印语句和一些变量
set statistics time on
print' statistics time '
declare @a int
set @a =1
select * from test
set statistics time off
输出:
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
(59 row(s) affected)
(1 row(s) affected)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 264 ms.
以上代码总执行时间为1+1+264。
希望这对它的工作原理有所帮助
我是 运行 在 SQL Server management studio 上查询 1 并且看到它 returns 我喜欢 3 条消息,但是当内部存储过程有近 10 - 20 条消息时统计数据。发生了什么事,为什么我看到他们?
SET STATISTICS IO,TIME ON;
GO
SELECT [UserId]
,[UserType]
,[CreateDT]
,[EffectiveDT]
FROM [dbo].[People] ORDER BY [UserId]
SET STATISTICS IO,TIME OFF;
GO
我收到的消息如下
SQL Server parse and compile time:
CPU time = 0 ms, elapsed time = 0 ms.
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.
Table 'People'. Scan count 1, logical reads 155, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 143 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 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 Execution Times:
CPU time = 0 ms, elapsed time = 143 ms.
查询的总耗时是 143ms + 143ms 吗?
见下文
set statistics time on
select * from test
set statistics time off
输出:
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 264 ms..
现在添加打印语句和一些变量
set statistics time on
print' statistics time '
declare @a int
set @a =1
select * from test
set statistics time off
输出:
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 1 ms.
(59 row(s) affected)
(1 row(s) affected)
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 264 ms.
以上代码总执行时间为1+1+264。
希望这对它的工作原理有所帮助