with QS as(  
    select cp.objtype as object_type  
          ,db_name(st.dbid)as [database]  
          ,object_schema_name(st.objectid,st.dbid)as [schema]  
          ,object_name(st.objectid,st.dbid)as [object]  
          ,convert(char(16),qs.creation_time,120)as plan_creation  
          ,convert(char(16),qs.last_execution_time,120)as last_execution  
          ,qs.plan_generation_num  
          ,qs.execution_count  
          ,qs.total_worker_time  
          ,qs.total_physical_reads  
          ,qs.total_logical_writes  
          ,qs.total_logical_reads  
          ,qs.total_elapsed_time/(1000000*qs.execution_count)as avg_elapesd_seconds  
          ,qs.total_worker_time/qs.execution_count as avg_cpu_cost  
          ,qs.total_logical_reads/qs.execution_count as avg_logical_reads  
          ,qs.total_logical_writes/qs.execution_count as avg_logical_writes  
          ,qs.total_physical_reads/qs.execution_count as avg_physical_reads  
          ,st.text  
          ,qp.query_plan  
    from sys.dm_exec_query_stats qs  
         join sys.dm_exec_cached_plans cp on cp.plan_handle=qs.plan_handle  
         cross apply sys.dm_exec_sql_text(sql_handle)as st  
         cross apply sys.dm_exec_query_plan(qs.plan_handle)as qp  
    where 1=1  
    --and cp.objtype='Proc'                 --对象类型  
    --and db_name(st.dbid)='GprsRun'        --数据库  
    --and st.text not like '%时间%' and st.text not like '%@queryStr%'        --查询字符串  
    --and qs.execution_count>100         --执行次数  
    --and qs.total_worker_time>100           --cpu总时间      
    --and qs.total_physical_reads>100        --物理读次数  
    --and qs.total_logical_writes>100        --逻辑写次数  
    --and qs.total_logical_reads>100     --逻辑读次数  
)  
 
select *, '执行次数最多的' type from (select top 5 * from QS order by execution_count desc)a               --执行次数最多的  
union all  
select *, '执行时间最长的' type from (select top 5 * from QS order by total_worker_time desc)a             --执行时间最长的  
union all  
select *, '物理读次数最多的' type from (select top 5 * from QS order by total_physical_reads desc)a         --物理读次数最多的  
union all  
select *, '逻辑写次数最多的' type from (select top 5 * from QS order by total_logical_writes desc)a         --逻辑写次数最多的  
union all  
select *, '逻辑读次数最多的' type from (select top 5 * from QS order by total_logical_reads desc)a          --逻辑读次数最多的  
union all  
select *, '平均cpu时间最长的' type from (select top 5 * from QS order by avg_cpu_cost desc)a                   --平均cpu时间最长的  
union all  
select *, '平均逻辑读最多的' type from (select top 5 * from QS order by avg_logical_reads desc)a                --平均逻辑读最多的  
union all  
select *, '平均逻辑写最多的' type from (select top 5 * from QS order by avg_logical_writes desc)a           --平均逻辑写最多的  
union all  
select *, '平均物理写最多的' type from (select top 5 * from QS order by avg_physical_reads desc)a           --平均物理写最多的  
order by text

查询sql执行速度的更多相关文章

  1. 查询SQL执行情况

    /* 查询SQL执行情况 包含逻辑读取信息,执行信息等情况*/ SELECT creation_time N'语句编译时间' ,last_execution_time N'上次执行时间' ,total ...

  2. Mysql资料 查询SQL执行顺序

    目录 一.Mysql数据库查询Sql的执行顺序是什么? 二.具体顺序 一.Mysql数据库查询Sql的执行顺序是什么? (9)SELECT (10) DISTINCT column, (6)AGG_F ...

  3. sql运算符优先级及逻辑处理顺序--查询sql执行顺序

    sql逻辑处理顺序 --开启和关闭查询 --SET STATISTICS TIME ON---------------------------------------------请先来看看SET ST ...

  4. Hibernate 模糊查询 ' %?% ' SQL执行异常

    今天我在使用Hibernate 的SQL预编译之后注入参数的形式写了一条模糊查询语句.刚开始我是这么写的

  5. showplan_text查询计划查询 sql执行顺序 时间 IO

    http://www.cnblogs.com/happyday56/archive/2009/09/10/1564144.html   set showplan_text ongoselect exp ...

  6. pgsql SQL监控,查询SQL执行情况

    SELECT procpid, START, now() - START AS lap, current_query FROM ( SELECT backendid, pg_stat_get_back ...

  7. 一条查询sql的执行流程和底层原理

    1.一条查询SQL执行流程图 2.查询SQL执行流程之发送SQL请求 (1)客户端按照Mysql通信协议将SQL发送到服务端,SQL到达服务端后,服务端会单起一个线程执行SQL. (2)执行时Mysq ...

  8. 面试官:说说一条查询sql的执行流程和底层原理?

    一条查询SQL执行流程图如下 序章 自我介绍 我是一条sql,就是一条长长的字符串,不要问我长什么样,因为我比较傲娇. 额~~不是我不说啊,因为细说起来,我可以细分为DML(Update.Insert ...

  9. 【知识点整理】Oracle中NOLOGGING、APPEND、ARCHIVE和PARALLEL下,REDO、UNDO和执行速度的比较

    [知识点整理]Oracle中NOLOGGING.APPEND.ARCHIVE和PARALLEL下,REDO.UNDO和执行速度的比较 1  BLOG文档结构图 2  前言部分 2.1  导读和注意事项 ...

随机推荐

  1. logging 的配置和使用

    logging 的配置和使用 reference : logging cookbook logging HOWTO 测试源码,example import logging nt = 'xwei' # ...

  2. bzoj1799(洛谷4127)同类分布(月之谜)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1799 https://www.luogu.org/problemnew/show/P4127 ...

  3. POJ2279杨氏矩阵+钩子定理

    题目:http://poj.org/problem?id=2279 有dp做法,但会MLE. dp的思想很好,是通过 “按身高由小到大往进放” 把 “身高小于” 的条件转化成 “放进去的先后” ,于是 ...

  4. Open Flash Chart 之线图

    天公司要求开发一个曲线图,简单看了一下之前公司的一个系统,发现一个曲线图效果还不错,查了一下叫OpenFlashChart,还是很不错的,很多人用.研究了一下,发现还不错,特地写了个DEMO测试下. ...

  5. 【python】重定向输出

    重定向的理解:就是把所要输出的结果输出到其他的地方.常用方法:"print >>",(若有其他方法后续补充) 举个例子: __author__ = 'paulwinfl ...

  6. view的setTag() 和 getTag()应用 ViewHolder

    转自 http://www.cnblogs.com/qingblog/archive/2012/07/03/2575140.html View中的setTag(Onbect)表示给View添加一个格外 ...

  7. Java中对话框的弹出

    最近在做学校的课程设计,java编程需要用到对话框弹出,第一反应是js中的alert和confirm,java的话瞬间懵,查阅学习总结如下,用以以后的学习 1.显示一个错误对话框,该对话框显示的 me ...

  8. R语言学习——数据分析

    complete.cases查看缺失值 箱图:

  9. 杂项:MSMQ

    ylbtech-杂项:MSMQ MicroSoft Message Queuing(微软消息队列)是在多个不同的应用之间实现相互通信的一种异步传输模式,相互通信的应用可以分布于同一台机器上,也可以分布 ...

  10. python selenium-1 环境搭建new

    1.Mac安装Anaconda集成环境 集成环境有助于快速编写脚本. 将安装的python3版本设置为python,系统的python更改为python2 Anaconda地址 https://www ...