我刚刚从 4.0 升级到 CRM 2011,我在应用程序日志中看到很多错误,我认为是由于电子邮件路由器。错误文本是“30.0 秒的查询执行时间超过了 10 秒的阈值”。
这是它正在执行的查询:
WITH Candidates
(
ActivityId
) AS
(SELECT ActivityId
FROM EmailHashBase WITH (NOLOCK)
WHERE ActivityId IN
(SELECT ActivityId
FROM EmailHashBase WITH (NOLOCK)
WHERE HashType = 0
AND Hash IN (111682,1892164739,45,1824023892,54,3805,125879)
GROUP BY ActivityId
HAVING COUNT(ActivityId) >= 7
)
AND HashType = 1
AND Hash IN (969105075,1418975348,547970098,1044570065,-1578559672,1137188287,-1492206818,1365121987,1893861533,-1313312639,-1829169632,-1685403462,-518982188,1123523219,284291011,-981044541,1790111815,-808308608,-599769785,971845046)
GROUP BY ActivityId
HAVING COUNT(ActivityId) >= 2
)
SELECT TOP 1 a.ActivityId
FROM ActivityPointerBase AS a WITH (NOLOCK)
WHERE a.ActivityId IN
(SELECT ActivityId
FROM Candidates AS c
WHERE(
(SELECT COUNT(*)
FROM EmailHashBase AS h
WHERE h.ActivityId = c.ActivityId
AND h.HashType = 0
)
<= 7
)
)
ORDER BY a.ModifiedOn DESC
直接对数据库运行此查询最多需要一分钟。我使用“Set Statistics IO ON”运行它并得到以下结果:
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 'EmailHashBase'. Scan count 17696074, logical reads 53155625, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table 'ActivityPointerBase'. Scan count 1, logical reads 5060, 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 = 36567 ms, elapsed time = 36562 ms.
显然,EmailHashBase 有问题。我在 Hash 列上添加了一个非聚集索引并重建了索引,但我仍然得到很高的扫描和逻辑读取计数。
我无法更改查询。
关于我可以对桌子做些什么来解决这个问题有什么建议吗?