我在SQL Server Management Studio上运行此查询1,并看到它像3条消息一样返回我,但是当内部存储过程中有来自Statistics的近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。
希望这对它的工作方式有所帮助