首页 > 数据库技术 > 详细

SQL技术内幕-13 SQL优化方法论之分离重量级的等待

时间:2015-04-06 12:40:02      阅读:198      评论:0      收藏:0      [点我收藏+]

Code

技术分享
-- Isolate top waits
WITH Waits AS
(
  SELECT
    wait_type,
    wait_time_ms / 1000. AS wait_time_s,
    100. * wait_time_ms / SUM(wait_time_ms) OVER() AS pct,
    ROW_NUMBER() OVER(ORDER BY wait_time_ms DESC) AS rn,
    100. * signal_wait_time_ms / wait_time_ms as signal_pct
  FROM sys.dm_os_wait_stats
  WHERE wait_time_ms > 0
    AND wait_type NOT LIKE N%SLEEP%
    AND wait_type NOT LIKE N%IDLE%
    AND wait_type NOT LIKE N%QUEUE%    
    AND wait_type NOT IN(  NCLR_AUTO_EVENT
                         , NREQUEST_FOR_DEADLOCK_SEARCH
                         , NSQLTRACE_BUFFER_FLUSH
                         /* filter out additional irrelevant waits */ )
)
SELECT
  W1.wait_type, 
  CAST(W1.wait_time_s AS NUMERIC(12, 2)) AS wait_time_s,
  CAST(W1.pct AS NUMERIC(5, 2)) AS pct,
  CAST(SUM(W2.pct) AS NUMERIC(5, 2)) AS running_pct,
  CAST(W1.signal_pct AS NUMERIC(5, 2)) AS signal_pct
FROM Waits AS W1
  JOIN Waits AS W2
    ON W2.rn <= W1.rn
GROUP BY W1.rn, W1.wait_type, W1.wait_time_s, W1.pct, W1.signal_pct
HAVING SUM(W2.pct) - W1.pct < 80 -- percentage threshold
    OR W1.rn <= 5
ORDER BY W1.rn;
GO
View Code

 1.从系统最后一次重启或计数器清空,该等待类型的总等待时间(以秒为单位)

2.该类型的等待时间占等待时间的百分比

3.从最重量级的等待类型到当前等待类型的连续百分比。

4.信号等待时间占等待时间的百分比,、(记住,wait_time_ms包含signal_wait_time_ms)

SQL技术内幕-13 SQL优化方法论之分离重量级的等待

原文:http://www.cnblogs.com/alphafly/p/4395679.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!