Skip to content

Fix Memory Grants always 0 in Memory Utilization chart (#978)#984

Merged
erikdarlingdata merged 1 commit into
devfrom
feature/978-memory-grants-zero
May 22, 2026
Merged

Fix Memory Grants always 0 in Memory Utilization chart (#978)#984
erikdarlingdata merged 1 commit into
devfrom
feature/978-memory-grants-zero

Conversation

@erikdarlingdata
Copy link
Copy Markdown
Owner

Summary

Fixes #978 — the "Memory Grants" line on Overview → Resource Overview → Memory Utilization is always 0 MB.

GetMemoryDataAsync correlated collect.memory_grant_stats to collect.memory_stats with an exact collection_time equality. The two tables are filled by separate collectors, each stamping its own SYSDATETIME() default, so the timestamps never align — the correlated subquery matched 0 rows and ISNULL(...,0) collapsed it to 0 on every sample.

Verified on sql2022's PerformanceMonitor DB: 0 rows where memory_stats.collection_time equals any memory_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/toDate and hoursBack).

Dashboard-only embedded-SQL change; no schema or install-script changes. Fixes historical data too.

Test plan

  • Verified the old query matches 0 rows against live data
  • Verified the fixed query returns real non-zero values (e.g. 51 MB) during grant activity
  • dotnet build Dashboard/Dashboard.csproj -c Debug — succeeds, 0 warnings/errors
  • Confirmed Lite is unaffected (plots grants as an independent series, no join)

🤖 Generated with Claude Code

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>
@erikdarlingdata erikdarlingdata merged commit 9f6055c into dev May 22, 2026
2 checks passed
@erikdarlingdata erikdarlingdata deleted the feature/978-memory-grants-zero branch May 22, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant