Fix Memory Grants always 0 in Memory Utilization chart (#978)#984
Merged
Conversation
GetMemoryDataAsync correlated collect.memory_grant_stats to collect.memory_stats with an exact collection_time equality. Those two tables are populated by separate collectors, each stamping its own SYSDATETIME() default, so the timestamps never line up — the correlated subquery matched 0 rows and ISNULL collapsed it to 0 on every sample. Replace the exact-match subquery with a nearest-snapshot lookup: the TOP (1) grant snapshot within +/-5 minutes, ordered by absolute time distance. Applied to both query branches (fromDate/toDate and hoursBack). Dashboard-only change; fixes historical data too. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #978 — the "Memory Grants" line on Overview → Resource Overview → Memory Utilization is always 0 MB.
GetMemoryDataAsynccorrelatedcollect.memory_grant_statstocollect.memory_statswith an exactcollection_timeequality. The two tables are filled by separate collectors, each stamping its ownSYSDATETIME()default, so the timestamps never align — the correlated subquery matched 0 rows andISNULL(...,0)collapsed it to 0 on every sample.Verified on sql2022's
PerformanceMonitorDB: 0 rows wherememory_stats.collection_timeequals anymemory_grant_stats.collection_time.Fix
Replaced the exact-match subquery with a nearest-snapshot lookup — the
TOP (1)grant snapshot within ±5 minutes, ordered by absolute time distance. Applied to both query branches (fromDate/toDateandhoursBack).Dashboard-only embedded-SQL change; no schema or install-script changes. Fixes historical data too.
Test plan
dotnet build Dashboard/Dashboard.csproj -c Debug— succeeds, 0 warnings/errors🤖 Generated with Claude Code