• 存储过程缓存表sys.dm_exec_procedure_stats的不同情况


    --执行SQL查看存储过程的执行信息

    SELECT TOP 10 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

    第一种情况:数据库重启后,数据为空

     第二种情况:同样的一条数据,重复执行两次,以up_com_qry_fundassets存储过程为例,数据库不重启,第一次执行存储过程,耗时22ms,第二次执行存储过程,耗时5ms

     

    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

  • 相关阅读:
    7、python数据类型之集合set
    python基本数据类型练习
    matplotlib
    numpy常用函数
    pillow包
    keras-tensorflow版本对应
    python-激活和切换运行环境
    端口监控
    numpy
    低风险创业笔记
  • 原文地址:https://www.cnblogs.com/lipo/p/13594797.html
Copyright © 2020-2023  润新知