WITH TMP AS
(
SELECT TOP 100
CAST(SUM(s.total_elapsed_time) / 1000000.0 AS DECIMAL(10, 2)) AS [Total Elapsed Time in S],
SUM(s.execution_count) AS [Total Execution Count],
CAST(SUM(s.total_worker_time) / 1000000.0 AS DECIMAL(10, 2)) AS [Total CPU Time in S],
CAST(SUM(s.total_worker_time) / SUM(s.execution_count) / 1000.0 AS DECIMAL(10, 2)) AS [Avg CPU Time in MS],
SUM(s.total_logical_reads) AS [Total Logical Reads],
CAST(CAST(SUM(s.total_logical_reads) AS FLOAT) / CAST(SUM(s.execution_count) AS FLOAT) AS DECIMAL(10, 2)) AS [Avg Logical Reads],
SUM(s.total_logical_writes) AS [Total Logical Writes],
CAST(CAST(SUM(s.total_logical_writes) AS FLOAT) / CAST(SUM(s.execution_count) AS FLOAT) AS DECIMAL(10, 2)) AS [Avg Logical Writes],
SUM(s.total_clr_time) AS [Total CLR Time],
CAST(SUM(s.total_clr_time) / SUM(s.execution_count) / 1000.0 AS DECIMAL(10, 2)) AS [Avg CLR Time in MS],
CAST(SUM(s.min_worker_time) / 1000.0 AS DECIMAL(10, 2)) AS [Min CPU Time in MS],
CAST(SUM(s.max_worker_time) / 1000.0 AS DECIMAL(10, 2)) AS [Max CPU Time in MS],
SUM(s.min_logical_reads) AS [Min Logical Reads],
SUM(s.max_logical_reads) AS [Max Logical Reads],
SUM(s.min_logical_writes) AS [Min Logical Writes],
SUM(s.max_logical_writes) AS [Max Logical Writes],
CAST(SUM(s.min_clr_time) / 1000.0 AS DECIMAL(10, 2)) AS [Min CLR Time in MS],
CAST(SUM(s.max_clr_time) / 1000.0 AS DECIMAL(10, 2)) AS [Max CLR Time in MS],
COUNT(1) AS [Number of Statements],
MAX(s.last_execution_time) AS [Last Execution Time],
s.plan_handle AS [Plan Handle]
FROM
sys.dm_exec_query_stats s --Most CPU consuming
GROUP BY s.plan_handle ORDER BY SUM(s.total_worker_time) DESC -- Most read+write IO consuming
--GROUP BY s.plan_handle ORDER BY SUM(s.total_logical_reads + s.total_logical_writes) DESC -- Most write IO consuming
--GROUP BY s.plan_handle ORDER BY SUM(s.total_logical_writes) DESC -- Most CLR consuming
--WHERE s.total_clr_time > 0 GROUP BY s.plan_handle ORDER BY SUM(s.total_clr_time) DESC
)
SELECT
TMP.*,
st.text AS [Query],
qp.query_plan AS [Plan]
FROM
TMP
OUTER APPLY
sys.dm_exec_query_plan(TMP.[Plan Handle]) AS qp
OUTER APPLY
sys.dm_exec_sql_text(TMP.[Plan Handle]) AS st

  

Worst Performing Queries的更多相关文章

  1. [转]Raw Queries in Laravel

    本文转自:https://fideloper.com/laravel-raw-queries Business logic is often complicated. Because of this, ...

  2. 如何找出你性能最差的SQL Server查询

    我经常会被反复问到这样的问题:”我有一个性能很差的SQL Server.我如何找出最差性能的查询?“.因此在今天的文章里会给你一些让你很容易找到问题答案的信息向导. 问SQL Server! SQL ...

  3. SQL Server 日常维护经典应用

    SQL Server日常维护常用的一些脚本整理. 1.sql server开启clr权限: GO RECONFIGURE GO ALTER DATABASE HWMESTC SET TRUSTWORT ...

  4. 【转】php容易犯错的10个地方

    原文地址: http://www.toptal.com/php/10-most-common-mistakes-php-programmers-make 译文地址:http://codecloud.n ...

  5. [转]Performance Analysis Using SQL Server 2008 Activity Monitor Tool

    本文转自:https://www.mssqltips.com/sqlservertip/1917/performance-analysis-using-sql-server-2008-activity ...

  6. (转) Written Memories: Understanding, Deriving and Extending the LSTM

    R2RT   Written Memories: Understanding, Deriving and Extending the LSTM Tue 26 July 2016 When I was ...

  7. nodejs应用mysql(纯属翻译)

    原文点击这里 目录 Install Introduction Contributors Sponsors Community Establishing connections Connection o ...

  8. PHP foreach 遍历数组是打印出相同的数据

    https://www.toptal.com/php/10-most-common-mistakes-php-programmers-make PHP makes it relatively easy ...

  9. KoaHub.JS基于Node.js开发的mysql的node.js驱动程序代码

    mysql A node.js driver for mysql. It is written in JavaScript, does not require compiling, and is 10 ...

随机推荐

  1. Quartz是一个完全由java编写的开源作业调度框架

    http://www.quartz-scheduler.org/ 找个时间研究一下

  2. Java精选笔记_集合概述(Collection接口、Collections工具类、Arrays工具类)

    集合概述 集合有时又称为容器,简单地说,它是一个对象,能将具有相同性质的多个元素汇聚成一个整体.集合被用于存储.获取.操纵和传输聚合的数据. 使用集合的技巧 看到Array就是数组结构,有角标,查询速 ...

  3. HTML5开发之 -- 模态突出窗(bootstrap)

    最近在学习web端开发相关,bootstrap非常好用! 有个模态弹出窗的效果,在此记录下: 1.导入: <script src="libs/js/jquery-3.2.1.min.j ...

  4. laravel 使用验证码

    1)php.ini需要开两个扩展 extension=php_fileinfo.dllextension=php_gd2.dll 2)使用composer安装类包 composer require m ...

  5. 第三篇:关于TIME_WAIT状态

    前言 为何TCP ”四次分手“ 的过程中会有一个TIME_WAIT状态?这个状态有什么意义呢?这是网络中的一个经典问题,本文将给出精简的回答. 什么是TIME_WAIT状态 这是TCP通信协议中出现的 ...

  6. case when 的实战应用(分别取图片展示问题)

    SELECT lg.product_id, lg.goods_id, lg.goods_no, lg.product_price, lg.product_stock, lg.limit_amount, ...

  7. 优秀的PHP开发者是怎样炼成的?

    4.在数据库中避免使用联合操作 比起其它的Web编程语言来说,PHP的数据库功能十分强大.但是在PHP中数据库的运行仍然是一件十分费时费力的事情,所以,作为一个Web程序员,要尽量减少数据库的查询操作 ...

  8. Android英文文档翻译系列(2)——HandlerThread

      public class   HandlerThread extends Thread   Class  Overview Handy class for starting a new threa ...

  9. 使用MAT分析Java内存

    Overview MAT(Memory Analyzer Tool) 是一个JAVA Heaper分析器,可以用来分析内存泄露和减少内存消耗.分析Process showmap中的/dev/ashme ...

  10. myBatis调用postgreSQL存储过程

    1.调用没有OUT参数的存储过程: 创建存储过程: create or replace function get_code(a1 varchar(32)) returns varchar(32) as ...