• SqlServer 创建索引进度查询


    用于在创建大索引时试试查看创建进度使用。

    参考字https://dba.stackexchange.com/questions/139191/sql-server-how-to-track-progress-of-create-index-command。用于个人记录使用

    1. 在创建索引时添加如下命令

      SET STATISTICS PROFILE ON;

    2. 使用如下sql查询索引创建状态

    DECLARE @SPID INT = 51;
    
    ;WITH agg AS
    (
         SELECT SUM(qp.[row_count]) AS [RowsProcessed],
                SUM(qp.[estimate_row_count]) AS [TotalRows],
                MAX(qp.last_active_time) - MIN(qp.first_active_time) AS [ElapsedMS],
                MAX(IIF(qp.[close_time] = 0 AND qp.[first_row_time] > 0,
                        [physical_operator_name],
                        N'<Transition>')) AS [CurrentStep]
         FROM sys.dm_exec_query_profiles qp
         WHERE qp.[physical_operator_name] IN (N'Table Scan', N'Clustered Index Scan',
                                               N'Index Scan',  N'Sort')
         AND   qp.[session_id] = @SPID
    ), comp AS
    (
         SELECT *,
                ([TotalRows] - [RowsProcessed]) AS [RowsLeft],
                ([ElapsedMS] / 1000.0) AS [ElapsedSeconds]
         FROM   agg
    )
    SELECT [CurrentStep],
           [TotalRows],
           [RowsProcessed],
           [RowsLeft],
           CONVERT(DECIMAL(5, 2),
                   (([RowsProcessed] * 1.0) / [TotalRows]) * 100) AS [PercentComplete],
           [ElapsedSeconds],
           (([ElapsedSeconds] / [RowsProcessed]) * [RowsLeft]) AS [EstimatedSecondsLeft],
           DATEADD(SECOND,
                   (([ElapsedSeconds] / [RowsProcessed]) * [RowsLeft]),
                   GETDATE()) AS [EstimatedCompletionTime]
    FROM   comp;
  • 相关阅读:
    性能测试学习笔记目录
    关于多项式的一些东西
    几道有意思的积性函数题
    关于min_25筛的一些理解
    【清华集训2014】主旋律
    清北冬令营训练计划
    # HNOI2012 ~ HNOI2018 题解
    贪心(qwq)习题题解
    导数与积分总结
    仙人掌 && 圆方树 && 虚树 总结
  • 原文地址:https://www.cnblogs.com/binw/p/13969562.html
Copyright © 2020-2023  润新知