怎么查找执行比较慢的sql语句-DBA给的建议

时间:2015-04-16 23:28:07   收藏:0   阅读:310

如下:

select top 10 b.text,a.total_worker_time,a.total_logical_reads,a.total_elapsed_time,execution_count
from sys.dm_exec_query_stats a
CROSS APPLY sys.dm_exec_sql_text(a.sql_handle) as b
order by total_worker_time/execution_count desc 

查看联机帮助文档视图:sys.dm_exec_query_stats可得到所有字段含义,主要有

total_worker_time:总的cpu消耗时间

total_logical_reads:逻辑读次数

total_elapsed_time:耗时

execution_count:执行次数。

total_worker_time/execution_count desc 表示每次执行需要消耗多少cpu,按照倒叙排序,找到最消耗cpu的sql语句。text

 

上面只可以查找SqlServer清空缓存之后的数据,如果SqlServer重启过,或者SqlServer由于内存不足导致执行计划被释放。那么是无法找到的。

技术分享

勾选以下事件。第一个是存储过程,第二个是sql语句

技术分享

筛选器选择超过100秒的为慢sql(单位为毫秒),点击确定。如下:

技术分享

 

原文:http://www.cnblogs.com/yy3b2007com/p/4433377.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!