Docs/Modules/Query Statistics

Query Statistics

Analyze SQL Server Query Store regressions, execution plans, top-impact queries, and exportable AI tuning reports from one workflow.

Overview

Query Statistics is the query-centric performance review module. It helps you identify the highest-impact queries for the current database, inspect source and execution plans, review deterministic scoring signals, and run AI-assisted analysis on one query or a selected batch.

For SQL Server performance tuning, this is usually the best starting point after installation and first-time setup are complete. The module combines Query Store evidence, fallback DMV support, execution-plan inspection, and exportable AI analysis in a single workflow.

What You Can Do
  • Rank queries by impact, duration, CPU, reads, executions, or risk.
  • Inspect source code, query text, and execution plans.
  • Review plan stability, trend, and regression signals.
  • Run AI analysis for one query or a selected query set.
  • Export, compare, and pivot into Wait Statistics or Index Advisor.
Best Companion Pages
Main Screen Layout

The main Query Statistics screen is not tab-based. It is a working list surface built around four practical areas, and the detailed tabs appear only after the user opens a query detail dialog.

  1. Query Store Health banner
  2. Filter toolbar
  3. Batch operations bar
  4. Results list
Screen 1

Query Store Health and Query List

The first screen gives the operator the health banner, filter toolbar, batch controls, and the ranked query list. Review this area first to confirm whether the module is using healthy Query Store data or a degraded fallback path before interpreting top-query results.

Data Source and Health Model
Preferred Source

The module prefers Query Store because it provides better historical depth for impact ranking, trend comparisons, plan history, and regression analysis.

  • sys.query_store_query
  • sys.query_store_plan
  • sys.query_store_runtime_stats
  • sys.query_store_runtime_stats_interval
Fallback Source

If Query Store is unavailable, stale, permission-blocked, or unhealthy, the module can fall back to DMV-based data with lower historical depth.

  • sys.dm_exec_query_stats
  • sys.dm_exec_sql_text
  • sys.dm_exec_query_plan
Health States
  • Green: Query Store is operational and recent.
  • Yellow: Query Store is available but stale or partial.
  • Red: Query Store is disabled, unavailable, not connected, or permission-blocked.
Why It Matters
  • Fallback mode can reduce historical confidence.
  • Missing permissions can disable source access or the whole module path.
  • The health and warning banners explain partial or degraded results.
Interpret degraded states carefully

When the health banner shows stale Query Store data, missing permissions, or DMV fallback, the module can still be useful, but the historical confidence and source-code coverage may be lower than normal.

Filters, Batch Controls, and Indicators
Filter Toolbar
  • Duration: Last 24 Hours, Last 7 Days, or Last 30 Days
  • Order By: Impact Score, Average Duration, Total CPU, Execution Count, Logical Reads, or Risk Score
  • Limit: Top 500, Top 1000, Top 2000, or Top 5000
  • Search: client-side filtering by query display name after the current dataset is loaded
  • Reset to Defaults: restores per-database defaults, clears cached filter memory, and reloads the list
Visibility Controls
  • Show System Queries is off by default.
  • Show Sensitive Data is off by default and requires confirmation.
  • Filter memory is persisted per active connection and database.
Batch Operations Bar
  • Analyze Selected with AI
  • Export Selected to CSV
  • Compare Selected Queries
  • Select Top 10 by CPU
  • Clear Selection
  • Selected: N counter with checkbox-first selection logic
Main Indicators
  • Impact Score prioritizes workload importance, not just latency.
  • Trend % compares the current window to the prior window.
  • Risk Score is a deterministic 0-100 signal.
  • Plan Stability highlights multi-plan or regression-oriented risk.
Selection and Batch Rules
  • The module supports both explicit checkbox selection and row selection.
  • Batch AI currently analyzes the first 10 selected queries from the chosen set.
  • The compare dialog requires at least two selected queries.
Load More and Paging
  • The list loads in pages of 100 results.
  • A Load More button appears only when more results exist under the current Top N limit.
  • This lets large query sets stay usable without forcing a full reload.
Screen 2

Results List and Query Cards

Each result row is a custom query card rather than a plain grid row. The card shows priority, duration, CPU, reads, executions, plan count, trend, impact, risk, and stability. Inline actions let the user move directly into source code, execution plan, AI analysis, wait analysis, or index review.

Quick Actions and Detail Flow
Query Card Actions
  • View opens Source Code.
  • Plan opens Execution Plan.
  • AI and Details & Recommendations open AI Analysis.
  • Related pivots into Wait Statistics.
  • Watch pivots into Index Advisor.
Right-Click Menu
  • Find Missing Indexes for This Query
  • Analyze Wait Stats for This Query
  • Deep Dive into Execution Plan

Once a user opens a single query, the detail dialog becomes the main working surface. It contains the tabs Source Code, Execution Plan, AI Analysis.

Source Code Tab Behavior
How source is loaded
  • If the query maps to a SQL object, the module first tries to load the object definition.
  • If no definition is available, it falls back to the captured query text.
  • If both paths fail, the dialog shows a limited or unavailable message instead of blocking the whole module.
Sensitive data behavior
  • With sensitive mode off, literals are redacted before the SQL text is displayed.
  • With sensitive mode on, the raw text can be shown for local inspection.
  • This same decision also affects what can later be sent into the AI analysis flow.
Screen 3

Execution Plan Tab

The Execution Plan tab loads plan XML through the plan viewer, highlights warnings and missing-index signals, and gives the user an operator tree, detail panel, and export path. This is the right place to validate plan shape, row estimates, missing indexes, and operator-level warnings before taking action.

Execution Plan Detail

Missing Indexes View

When SQL Server surfaces a missing-index recommendation for the selected query, the plan dialog can show the suggested key and include columns together with estimated impact.

Execution Plan Detail

Warnings View

Warnings isolate operator-level issues that deserve extra review before tuning changes are approved, such as scans, plan-shape instability, or missing-index signals.

Execution Plan Behavior
What The Tab Does
  • Loads plan XML for the selected query.
  • Parses the plan through the plan parser and viewer widget.
  • Shows warnings and missing-index signals in dedicated tabs or badges.
  • Can export the current execution plan as standalone HTML.
Sensitive Data Rules
  • When sensitive data is hidden, literals and plan expressions are sanitized.
  • When sensitive data is shown, raw values can be visible in the plan details.
  • Use raw mode carefully because plan XML can expose literals, PII, or environment-specific values.

When a plan is unstable, the detail panel and metric rail help explain whether the problem is cost skew, row-estimate drift, repeated scans, missing indexes, or a multi-plan pattern that deserves follow-up in Wait Statistics or Index Advisor.

Screen 4

AI Analysis Tab

The AI Analysis tab combines deterministic context with LLM-assisted interpretation. It shows context quality, bottleneck classification, progress, and the resulting report. This is where the operator moves from raw evidence into structured recommendations, exportable summaries, and reusable analysis artifacts.

AI Workflow and Exports
Single-query analysis
  • The dialog builds deterministic context first, then adds LLM-assisted interpretation.
  • The AI tab shows context quality, bottleneck, progress, and the final analysis output.
  • Users can copy text, save the report, or save the raw LLM request payload when available.
Batch analysis
  • Batch mode is intended for triaging a selected set of high-impact queries.
  • The results dialog can export the batch summary to CSV or HTML.
  • This is useful when you need a compact tuning pack for a DBA, developer, or customer review.
Example AI Report Downloads

The AI Analysis tab can produce downloadable HTML reports. The examples below show what a visitor can expect from the report structure and how the product frames evidence, risk, and recommendations.

AI Performance Report 1

Single-query HTML report with executive summary, bottleneck diagnosis, plan evidence, and verification guidance.

AI Performance Report 2

Example report that emphasizes evidence framing, remediation priorities, and safe tuning order.

AI Performance Report 3

Alternate report variant showing how the AI output can be exported for team review or customer handoff.

Permissions, Security, and Practical Use
Minimum Permissions
  • VIEW SERVER STATE for full module functionality.
  • VIEW DEFINITION or equivalent source access for object definitions.
Graceful Degradation
  • If Query Store is unhealthy, the module can fall back to DMV-based data.
  • If source permissions are missing, query metrics can still load while Source Code becomes limited.
  • The health banner and warning banner are designed to explain these degraded states explicitly.
Typical Workflow
  1. Review the Query Store Health banner first.
  2. Adjust Duration, Order By, Limit, and visibility settings.
  3. Search for the target query, object, or workload pattern.
  4. Open Source Code, Execution Plan, or AI Analysis depending on the next question.
  5. Use Related or Watch to pivot into Wait Statistics or Index Advisor when needed.
  6. Export or download reports for tuning review, audits, or developer handoff.
Related documentation

Use Dashboard for instance-level triage, Wait Statistics for query-correlated wait evidence, and Index Advisor for missing-index follow-up after plan inspection.