【问题标题】:What do multiple parse and compile outputs in Statistics Time mean?统计时间中的多个解析和编译输出是什么意思?
【发布时间】:2015-06-12 06:46:51
【问题描述】:

我正在 Microsoft SQL Server 中调整查询的性能,并且我设置了 SET STATISTICS TIME。

对于输出,我收到多个 SQL Server 解析和编译时间:消息:

SQL Server parse and compile time: 
   CPU time = 0 ms, elapsed time = 2 ms.
SQL Server parse and compile time: 
   CPU time = 5985 ms, elapsed time = 5985 ms.
SQL Server parse and compile time: 
   CPU time = 5953 ms, elapsed time = 5965 ms.
SQL Server parse and compile time: 
   CPU time = 6172 ms, elapsed time = 6173 ms.
SQL Server parse and compile time: 
   CPU time = 6031 ms, elapsed time = 6073 ms.
SQL Server parse and compile time: 
   CPU time = 6000 ms, elapsed time = 6008 ms.
SQL Server parse and compile time: 
   CPU time = 5978 ms, elapsed time = 5978 ms.
SQL Server parse and compile time: 
   CPU time = 5969 ms, elapsed time = 5970 ms.
SQL Server parse and compile time: 
   CPU time = 5953 ms, elapsed time = 5966 ms.

(1 row(s) affected)

(1 row(s) affected)

 SQL Server Execution Times:
   CPU time = 9516 ms,  elapsed time = 9544 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.

有人认为这是由于子查询造成的,但我找不到任何证实这一点的东西。消息多于子查询。

我也不确定为什么我会得到 2 个(1 行受影响),因为只返回 1 个记录集和一行。

编辑:

此查询是一个 SELECT 语句,它使用多个子查询、一个窗口函数和一个偏移量获取。

【问题讨论】:

  • 这是对具有触发器的表的更新/插入子句吗?
  • 查看 SQL 会有所帮助.. 但我猜你不能...所以msdn.microsoft.com/en-us/library/ms190287.aspx 在单独的 SQL 服务器解析中显示每个 go 结果。行影响 Select 的结果。这是在一个包/程序中吗?
  • 只有一个声明。没有 GO。
  • 是否有一些嵌套查询之类的?

标签: sql-server tsql database-performance


【解决方案1】:

解析时间是在检查 SQL 语句的语法错误、将命令分解为组件以及生成内部执行树期间所花费的时间。

编译时间是从刚刚生成的执行树中编译高速缓存内存中的执行计划所花费的时间。

最后,执行时间是执行编译计划的总时间。

如果您的过程/函数/脚本中有多个语句。 SQL Server 必须分别解析和编译它们,并分别向您显示统计时间。因此有多个 Parse 和 Compile 统计信息。

【讨论】:

  • 但我只有一个选择语句。这是一个复杂的 Select 语句,但仍然只有一个。
【解决方案2】:

我在研究类似问题时遇到了这篇文章。虽然它很旧,但我想我会添加我的答案。

很确定您所看到的只是 STATISTICS TIME 的一个错误。我在使用触发器插入表时遇到了类似的行为。您可能还会发现分配给 Parse 和 Compile 的时间(或部分时间)实际上与查询处理有关。我已经通过捕获实际执行计划并检查 XML 中的 CompileTime 和 CompileCPU 验证了这一点(在我的情况下)——它们分别报告为 61 和 27(毫秒)。如果我查看我的 STATISTICS TIME 输出,我有:

SQL Server parse and compile time:  
  CPU time = 7906 ms, elapsed time = 8041 ms.  
SQL Server parse and compile time:   
  CPU time = 7906 ms, elapsed time = 8041 ms.  
SQL Server parse and compile time:   
  CPU time = 7906 ms, elapsed time = 8041 ms.  

比计划中捕获的数字要多得多。

您可以看到重复的相同行,在我的情况下它们显然是错误的,因为执行查询所花费的时间少于这些单独经过的总时间。对于我的查询,我希望我应该只有一行,它应该被标记为 SQL Server 执行时间(不是解析和编译)。

STATISTICS TIME 和 STATISTICS IO 是很棒的工具,但在少数情况下它们会显示不正确的数字,因此对它们进行常识检查也很重要。

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 2016-06-10
    • 2015-09-02
    • 1970-01-01
    相关资源
    最近更新 更多