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. mysql 微信用户昵称emoji 完整保存

    微信用户昵称现在丰富多样,一些个性的名称中经常包含有特殊字符,以及emoji表情.起先,我总以为MySQL只能保存纯文本数据.但其实mysql(5.7版本)已非常强大,完整保存微信用户昵称(emoji ...

  2. 学习 ASP.NET MVC

    http://www.cnblogs.com/gaoweipeng/category/203080.html http://blog.csdn.net/liu_ben_qian/article/det ...

  3. TroubleShoot: Fail to deploy Windows UAP to device: 0x80073CFD

    After creating "Blank App(Windows Universal)" targeting Windows Phone 10 in Visual Studio ...

  4. 用SqlConnectionStringBuilder修改连接超时时间

    连接是通过参数传入,欲修改超时时间. SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(connStr); scsb.C ...

  5. Java设计原则之依赖倒转原则

    定义:高层模块不应该依赖低层模块,二者都应该依赖其抽象:抽象不应该依赖细节:细节应该依赖抽象. 问题由来:类A直接依赖类B,假如要将类A改为依赖类C,则必须通过修改类A的代码来达成.这种场景下,类A一 ...

  6. spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情

    <spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情> <服务网关zu ...

  7. python3+selenium3.13的简单操作

    1.浏览器 1.1 浏览器窗口大小位置 driver.set_window_size(self, width, height, windowHandle) 将某个窗口设置为固定大小 driver.se ...

  8. 挂载本地ISO

    http://www.linuxidc.com/Linux/2017-03/142087.htm 挂载本地ISO mount -o loop /home/iso/RHEL-server-7.0-x86 ...

  9. windows 网管常用命令

    Windows网络命令行程序 这部分包括: 使用 ipconfig /all 查看配置 使用 ipconfig /renew 刷新配置 使用 ipconfig 管理 DNS 和 DHCP 类别 ID ...

  10. [UE4]射中机器人