Skip to content

Gate Query Store wait stats for SQL 2017+ with capture mode check#142

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/waitstats-version-gate
Mar 25, 2026
Merged

Gate Query Store wait stats for SQL 2017+ with capture mode check#142
erikdarlingdata merged 1 commit intodevfrom
fix/waitstats-version-gate

Conversation

@erikdarlingdata
Copy link
Owner

Summary

sys.query_store_wait_stats only exists on SQL Server 2017+ and Azure SQL DB. Additionally, wait stats capture can be disabled per database via WAIT_STATS_CAPTURE_MODE = OFF. Without this gate, the wait stats queries from PR #137 would fail on SQL 2016 or when capture is disabled.

Changes:

  • Add SupportsQueryStoreWaitStats property to ServerMetadata (major version >= 14 or Azure)
  • Add IsWaitStatsCaptureEnabledAsync() to QueryStoreService — checks wait_stats_capture_mode_desc in sys.database_query_store_options
  • QueryStoreGridControl accepts a supportsWaitStats constructor parameter — when false, hides the wait stats panel, splitter, chevron, and Wait Profile column
  • Both fetch call sites gated on _waitStatsSupported && _waitStatsEnabled
  • QuerySessionControl wires both checks (version + capture mode) before constructing the grid

Behavior on SQL 2016 or capture OFF: No wait stats queries issued, panel collapsed, column hidden. No errors.

Test plan

  • Build succeeds (0 errors)
  • Connect to SQL 2017+ with wait stats capture ON — wait stats panel visible and functional
  • Connect to SQL 2016 — wait stats panel hidden, no errors
  • Connect to database with WAIT_STATS_CAPTURE_MODE = OFF — wait stats panel hidden

🤖 Generated with Claude Code

sys.query_store_wait_stats only exists on SQL Server 2017+ (major >= 14)
and Azure SQL DB. Additionally, wait stats capture can be disabled per
database via WAIT_STATS_CAPTURE_MODE = OFF.

Changes:
- Add SupportsQueryStoreWaitStats property to ServerMetadata (major >= 14 or Azure)
- Add IsWaitStatsCaptureEnabledAsync to QueryStoreService — checks
  wait_stats_capture_mode_desc in sys.database_query_store_options
- Gate QueryStoreGridControl: accept supportsWaitStats flag, hide wait
  stats panel/column/splitter when unsupported, skip all fetch calls
- Wire both checks in QuerySessionControl before constructing the grid

On SQL 2016 or when capture is OFF: no wait stats queries are issued,
the panel is collapsed, and the Wait Profile column is hidden.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 8e5ae2f into dev Mar 25, 2026
2 checks passed
@erikdarlingdata erikdarlingdata deleted the fix/waitstats-version-gate branch March 25, 2026 02:44
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