sql server 根據執行計畫查詢耗時操作

來源:互聯網
上載者:User

標籤:

 1 with QS as( 2 select    cp.objtype as object_type,                                                    /*類型*/ 3         db_name(st.dbid) as [database],                                                /*資料庫*/ 4         object_schema_name(st.objectid,st.dbid) as [schema],                        /*架構*/ 5         object_name(st.objectid,st.dbid) as [object],                                /*對象名*/ 6         convert(char(16),qs.creation_time,120) as plan_creation,                    /*計劃產生時間*/ 7         convert(char(16),qs.last_execution_time,120) as last_execution,                /*最後執行時間*/ 8         qs.plan_generation_num, 9         qs.execution_count,                                                            /*執行次數*/10         qs.total_elapsed_time/(1000*qs.execution_count) as avg_elapesd_seconds,        /*總花費時間ms*/11         qs.total_worker_time/(1000*qs.execution_count) as avg_cpu_cost,                /*平均cpu耗時ms*/12         qs.total_logical_reads/qs.execution_count as avg_logical_reads,                /*平均邏輯讀*/13         qs.total_logical_writes/qs.execution_count as avg_logical_writes,            /*平均邏輯寫*/14         qs.total_physical_reads/qs.execution_count as avg_physical_reads,            /*平均屋裡讀*/15         st.text,                                                                    /*執行文本*/16         qp.query_plan                                                                /*執行計畫*/17 from sys.dm_exec_query_stats qs18 join sys.dm_exec_cached_plans cp on cp.plan_handle=qs.plan_handle19 cross apply sys.dm_exec_sql_text(sql_handle) as st20 cross apply sys.dm_exec_query_plan(qs.plan_handle) as qp21 )select top 20 * from QS22  where text like ‘%%‘23  --and object_type=‘Proc‘24  --and avg_logical_reads>20025  and execution_count>100 /*執行次數*/26  --and last_execution_time>dateadd(mi,-10,getdate())27 and last_execution >= ‘2016-05-01 00:00:00.000‘ /*最後執行時間*/28  order by avg_cpu_cost desc29  

 

sql server 根據執行計畫查詢耗時操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.