Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多次返回SQL查询性能统计信息消息_Sql_Sql Server_Query Performance - Fatal编程技术网

多次返回SQL查询性能统计信息消息

多次返回SQL查询性能统计信息消息,sql,sql-server,query-performance,Sql,Sql Server,Query Performance,我在SQLServerManagementStudio上运行这个查询1,看到它像3条消息一样返回我,但当存储过程中有近10-20条来自统计数据的消息时,返回的消息是相同的。发生了什么,为什么我会看到他们 SET STATISTICS IO,TIME ON; GO SELECT [UserId] ,[UserType] ,[CreateDT] ,[EffectiveDT] FROM [dbo].[People] ORDER

我在SQLServerManagementStudio上运行这个查询1,看到它像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..
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.
现在添加print语句和一些变量

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 = 264 ms..
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


希望这对它的工作原理有所帮助

这是否意味着在您的案例中执行查询所花费的总时间是
1+1+264