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. [转] web_reg_save_param得到的数组的处理

    方法一: 函数(sprintf,web_reg_save_param),其中红色字体是本文档最重要的#include "web_api.h" Action(){int i,iloo ...

  2. brew 接口的原理

    请查看相关文档的第9章 该文档可以csdn silentjesse帐号下的资源去下载 http://download.csdn.net/detail/silentjesse/5859077

  3. 基于pyteseract google ocr的图形验证码识别

    先灰化图片,把图片二值化,利用pytesseract包的pytesseract.image_to_string转换出文字.

  4. [hibernate]org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter

    org.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type sette ...

  5. 零基础的人怎么学习Java

    编程语言Java,已经21岁了.从1995年诞生以来,就一直活跃于企业中,名企应用天猫,百度,知乎......都是Java语言编写,就连现在使用广泛的XMind也是Java编写的.Java应用的广泛已 ...

  6. POJ 1837 Balance(01背包变形, 枚举DP)

    Q: dp 数组应该怎么设置? A: dp[i][j] 表示前 i 件物品放入天平后形成平衡度为 j 的方案数 题意: 有一个天平, 天平的两侧可以挂上重物, 给定 C 个钩子和G个秤砣. 2 4 - ...

  7. Win10 安装msi 提示2502、2503的错误代码 -- 命令提示符(管理员) -- msiexec /package

    前言: 归根到底是权限不够导致的.win7应该不会有这个问题.     解决方法: 方法1:临时安装方法 1.鼠标移到桌面左下角->右键(或者直接: WIN+X键),命令提示符(管理员):2.输 ...

  8. Linux 下配置网卡的别名即网卡子IP的配置

    what 什么是ip别名?用windows的话说,就是为一个网卡配置多个ip.when 什么场合增加ip别名能派上用场?布网需要.多ip访问测试.特定软件对多ip的需要...and so on. ho ...

  9. Xcode模版生成文件头部注释

    在使用Xcode创建工程或者新建类的时候,顶部都会有一些xcode帮我们生成的注释 //// MySingletonClass.h// 单例模式//// Created by mark on 15/8 ...

  10. 【转载】为ASP.NET MVC及WebApi添加路由优先级

    路由方面的: 转载地址:http://www.jb51.net/article/73417.htm Author:lijiao 这是一个对Asp.Net Mvc的一个很小的功能拓展,小项目可能不太需要 ...