Skip to content

sp_StatUpdate runs blind to cross-session monitoring — missing SET CONTEXT_INFO and ##sp_StatUpdate_Progress column depth #538

Description

@nanoDBA

Problem

During UPDATE STATISTICS execution, sys.dm_exec_requests.context_info is NULL for the sp_StatUpdate session. A DBA using sp_WhoIsActive to monitor a running maintenance job sees only the inner dynamic SQL (UPDATE STATISTICS [table] [stat] WITH ...) with no procedural context — no indication that sp_StatUpdate is running, which run label, what stat index out of how many, or when the current stat started. RAISERROR WITH NOWAIT (the existing progress mechanism) feeds the Agent job log only; it does not populate context_info. The two monitoring surfaces (DMV/sp_WhoIsActive vs. job log) require separate instrumentation.

Proposed Fix

  1. SET CONTEXT_INFO (128 bytes): Set at loop entry with a truncated payload encoding RunLabel, stat_index/total_stats, and current stat name. Use SET CONTEXT_INFO (not sp_set_session_context) — sp_WhoIsActive reads context_info, not the newer session context API.
  2. ##sp_StatUpdate_Progress column depth: The opt-in progress table (lines 3123–3156) has correct architecture but insufficient columns. Add: CurrentStatName, CurrentStatIndex, TotalStats, CurrentStatStartTime. Makes the table a complete diagnostic surface for dashboard consumers.
  3. Both changes are orthogonal — neither replaces the existing RAISERROR WITH NOWAIT job-log progress path.

Draft Source

memory/persona-trickle/blog-drafts/issue-draft-spid-context-info-observability.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions