檢查sql執行效率


SELECT  SUBSTRING(ST.text, ( QS.statement_start_offset / 2 ) + 1,
                   ( ( CASE statement_end_offset
                         WHEN -1 THEN DATALENGTH(st.text)
                         ELSE QS.statement_end_offset
                       END - QS.statement_start_offset ) / 2 ) + 1) AS '執行語句' ,
  DB_Name(DB.dbid) '數據庫名'
       , OBJECT_ID(db.objectid) '對象'
       , QS.creation_time '編譯計劃的時間'
       , QS.last_execution_time '上次執行計劃的時間'
       , QS.execution_count '執行的次數'
       , QS.total_elapsed_time / 1000 '佔用的總時間(秒)'
       , QS.total_physical_reads '物理讀取總次數'
       , QS.total_worker_time / 1000 'CPU 時間總量(秒)'
       , QS.total_logical_writes '邏輯寫入總次數'
       , QS.total_logical_reads N'邏輯讀取總次數'
       , QS.total_elapsed_time / 1000 N'總花費時間(秒)'
FROM    sys.dm_exec_query_stats AS QS CROSS APPLY
         sys.dm_exec_sql_text(QS.sql_handle) AS ST INNER JOIN
         ( SELECT    *
           FROM      sys.dm_exec_cached_plans cp CROSS APPLY
                     sys.dm_exec_query_plan(cp.plan_handle)
         ) DB
             ON QS.plan_handle = DB.plan_handle
 where   SUBSTRING(st.text, ( qs.statement_start_offset / 2 ) + 1,
                   ( ( CASE statement_end_offset
                         WHEN -1 THEN DATALENGTH(st.text)
                         ELSE qs.statement_end_offset
                       END - qs.statement_start_offset ) / 2 ) + 1) not like '%fetch%'
and isnull(DB_Name(DB.dbid),'') != 'AME1.0'
ORDER BY QS.total_elapsed_time / 1000 DESC sql

 

--by 別人數據庫

相關文章
相關標籤/搜索