在MSSQL Server上,我运行了两个查询,这些查询返回了具有不同统计信息的相同记录。有人可以通过以下统计数据指导我使用哪一个更好地用于报告目的:
查询1:
SQL Server parse and compile time:
CPU time = 359 ms, elapsed time = 602 ms.
(5517 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 'Table1'. Scan count 5972, logical reads 37742, physical reads 87, read-ahead reads 32, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table2'. Scan count 1, logical reads 3061, physical reads 2, read-ahead reads 3084, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table3'. Scan count 1, logical reads 4171, physical reads 2, read-ahead reads 4210, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table4'. Scan count 1, logical reads 843, physical reads 3, read-ahead reads 874, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table5'. Scan count 1, logical reads 6899, physical reads 2, read-ahead reads 6898, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table6'. Scan count 1, logical reads 3176, physical reads 2, read-ahead reads 3207, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table7'. Scan count 2, logical reads 35, physical reads 2, read-ahead reads 71, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table8'. Scan count 1, logical reads 2, physical reads 1, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 484 ms, elapsed time = 16415 ms.
查询2:
SQL Server parse and compile time:
CPU time = 312 ms, elapsed time = 618 ms.
(5517 row(s) affected)
Table 'Worktable'. Scan count 11655, logical reads 807704, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table8'. Scan count 0, logical reads 11452, physical reads 1, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table1'. Scan count 5976, logical reads 24654, physical reads 15, read-ahead reads 3348, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table2'. Scan count 1, logical reads 3061, physical reads 2, read-ahead reads 3084, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table3'. Scan count 1, logical reads 4171, physical reads 2, read-ahead reads 4210, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table4'. Scan count 1, logical reads 843, physical reads 3, read-ahead reads 874, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table5'. Scan count 1, logical reads 6899, physical reads 2, read-ahead reads 6898, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table6'. Scan count 1, logical reads 3176, physical reads 2, read-ahead reads 3207, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'Table7'. Scan count 2, logical reads 35, physical reads 2, read-ahead reads 71, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
SQL Server Execution Times:
CPU time = 1342 ms, elapsed time = 15448 ms.
其中: 表7和表8是查找表,而其他表是事务表。
来自执行计划 - 不同 格式:属性 - 查询1 /查询2
**SELECT NODE**
Cached Plan Size - 200/168 KB
Memory Grant - 32088/38816
Estimated Subtree Cost - 26.1473/24.4291
Estimated No. of Rows - 104.17/13848.8
**LAST NODE/OPERATOR**
Estimated Operator Cost - 0.0125/0.8858
Estimated Subtree Cost - 26.1473/24.4291
Estimated CPU Cost - 0.0011897/0.874608
Estimated I/O Cost - 0.00112613/0.0112613
Estimated No. of Rows - 104.17/13848.8
Actual No. of Rows - 5517/5517
答案 0 :(得分:0)
好吧,在等待很长时间并根据不同的性能统计数据分析两个查询之后,我无法找到一种方法来使用另一种。最后,我使用55K记录的数据集运行两个查询,并且查询1在13秒内返回结果,而查询2花费大约18秒。我用它作为基准来推进查询1。