zoukankan      html  css  js  c++  java
  • DB中耗时的 存储过程 及执行详细情况

    SELECT  a.object_id, a.database_id, OBJECT_NAME(object_id, database_id) 'proc name',
    a.cached_time, a.last_execution_time, a.total_elapsed_time, a.total_elapsed_time/a.execution_count AS [avg_elapsed_time],
    a.execution_count,
    a.total_physical_reads/a.execution_count avg_physical_reads,
    a.total_logical_writes,
    a.total_logical_writes/ a.execution_count  avg_logical_reads,
    a.last_elapsed_time,
    a.total_elapsed_time / a.execution_count   avg_elapsed_time,
    b.text,c.query_plan 
    FROM sys.dm_exec_procedure_stats AS a
    CROSS APPLY sys.dm_exec_sql_text(a.sql_handle)  b
    CROSS APPLY sys.dm_exec_query_plan(a.plan_handle) c
    ORDER BY [total_worker_time] DESC;
    GO
    
    
    select creation_time '编译时间',
      last_execution_time '上次执行时间',
      total_physical_reads '物理读取总次数',
      total_logical_reads/execution_count '每次逻辑读次数',
      total_logical_reads '逻辑读次数',
      total_logical_writes '逻辑写次数',
      execution_count '执行总次数',
      total_worker_time/1000 '占用CPU总时间(毫秒)',
      total_elapsed_time/1000 '总花费时间(毫秒)',
      (execution_count/total_elapsed_time)/1000 '平均执行时间(毫秒)',
      substring(st.text,(qs.statement_start_offset/2)+1,((case qs.statement_end_offset when -1 then datalength(st.text) else qs.statement_end_offset end -qs.statement_start_offset)/2)+1) '执行的SQL语句',
      getdate() '执行收集时间'
       from sys.dm_exec_query_stats as qs 
    cross apply sys.dm_exec_sql_text(qs.sql_handle)as st
    where substring(st.text,(qs.statement_start_offset/2)+1,((case qs.statement_end_offset when -1 then datalength(st.text) else qs.statement_end_offset end -qs.statement_start_offset)/2)+1)
    not like '%FETCH%'
    ORDER BY total_elapsed_time/execution_count desc
  • 相关阅读:
    telnet退出
    Eclipse srever起来时,时间超过45s。
    maven报错 Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.5.0 from
    需求讨论
    PyTorch学习笔记之计算图
    PyTorch学习笔记之CBOW模型实践
    PyTorch学习笔记之n-gram模型实现
    PyTorch学习笔记之初识word_embedding
    7月3日-9日_周报
    python学习笔记之heapq内置模块
  • 原文地址:https://www.cnblogs.com/davidhou/p/5121667.html
Copyright © 2011-2022 走看看