SQL Server time-consuming operation based on execution plan query

Source: Internet
Author: User

1  withQs as(2 SelectCp.objtype asObject_type,/*type*/3         db_name(st.dbid) as [Database],/*Database*/4Object_schema_name (St.objectid,st.dbid) as [Schema],/*Architecture*/5         object_name(st.objectid,st.dbid) as [Object],/*Object Name*/6         Convert(Char( -), Qs.creation_time, -) asPlan_creation,/*Scheduled build time*/7         Convert(Char( -), Qs.last_execution_time, -) asLast_execution,/*Last Execution Time*/8 Qs.plan_generation_num,9Qs.execution_count,/*Number of executions*/TenQs.total_elapsed_time/( +*Qs.execution_count) asAvg_elapesd_seconds,/*Total time spent Ms*/ OneQs.total_worker_time/( +*Qs.execution_count) asAvg_cpu_cost,/*average CPU time consuming Ms*/ AQs.total_logical_reads/Qs.execution_count asAvg_logical_reads,/*average logical Read*/ -Qs.total_logical_writes/Qs.execution_count asAvg_logical_writes,/*average Logical Write*/ -Qs.total_physical_reads/Qs.execution_count asAvg_physical_reads,/*Average room reading*/ theSt.text,/*Execute text*/ -Qp.query_plan/*Execution Plan*/ -  fromsys.dm_exec_query_stats QS - JoinSys.dm_exec_cached_plans CP onCp.plan_handle=Qs.plan_handle +  CrossApply Sys.dm_exec_sql_text (sql_handle) asSt -  CrossApply Sys.dm_exec_query_plan (Qs.plan_handle) asQP +)Select Top  - *  fromQS A  where text  like '%%' at  --and object_type= ' Proc ' -  --and avg_logical_reads>200 -   andExecution_count> - /*Number of executions*/ -  --and Last_execution_time>dateadd (Mi,-10,getdate ()) -  andLast_execution>= '2016-05-01 00:00:00.000' /*Last Execution Time*/ -  Order  byAvg_cpu_costdesc in  

SQL Server time-consuming operation based on execution plan query

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.