b.duration AS WaitDuration
INTO #t3
FROM #t1 a INNER JOIN #t2 b on a.session_id = b.session_id
and b.timestamp < a.timestamp
and b.timestamp>(
select top 1 timestamp from #t1 c
where a.session_id = a.session_id and a.timestamp > b.timestamp
order by a.timestamp
)
select
case when rn = 1 then SessionId else NULL end as SessionId,
case when rn = 1 then SQLTEXT else NULL end as SQLTEXT,
case when rn = 1 then TotalExecuteTime else NULL end as TotalExecuteTime,
CompletedTime as CompletedTime,
WaitType,
WaitTypeStartTime as WaitTypeStartTime,
WaitDuration
from
(
select ROW_NUMBER()over(partition by SessionId,SQLTEXT,TotalExecuteTime,CompletedTime order by CompletedTime,WaitTypeStartTime) as rn,
* FROM #t3
)
当然该语句仅供参考,目的是为了收集Session级的统计信息,当收集到Session级别的统计信息之后,具体的统计方式也不难。
总结
等待事件可以帮助我们诊断SQL Server上的一些资源瓶颈,对于问题的处理和解决有着比较重要的参考意义,如果能够细化地收集等待事件,对于解决问题的参考意义会更大。
本文通过一个简单的示例,使用扩展事件来收集SQL Server中一些特定场景下的等待信息,来更加有针对性地进行问题的诊断和识别,使得问题的分析更加高效和具有针对性。
以上所述是小编给大家介绍的SQLServer中使用扩展事件获取Session级别的等待信息及SQLServer 2016中Session级别等待信息的增强,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!
您可能感兴趣的文章:sqlserver 模糊查询常用方法SqlServer使用 case when 解决多条件模糊查询问题SqlServer中模糊查询对于特殊字符的处理方法MSSQL Server 查询优化方法 整理sqlserver 中charindex/patindex/like 的比较SqlServer参数化查询之where in和like实现之xml和DataTable传参介绍SqlServer参数化查询之where in和like实现详解SqlServer2016模糊匹配的三种方式及效率问题简析










