Skip to content

Feature/query history v2#158

Merged
erikdarlingdata merged 9 commits intoerikdarlingdata:devfrom
rferraton:feature/query-history-v2
Mar 30, 2026
Merged

Feature/query history v2#158
erikdarlingdata merged 9 commits intoerikdarlingdata:devfrom
rferraton:feature/query-history-v2

Conversation

@rferraton
Copy link
Copy Markdown
Contributor

What does this PR do?

Big refacto of the Query History :

  • Filter by QueryHash instead of QueryId
  • Chart and grid use an agregate by planHash + Interval
  • add an average line in the chart with label.
  • Legend by plan Hash. One Plan Hash = One Color. Selectable and highlight the line in the chart + recompute average line for the select plan
  • box selection in the chart : will highlight rows in the grid
  • Selection (single or multi) in the grid will highlight dots in the chart
  • Switch Period filter for the Query Hash : Range period (from Query Store window) or Full History
  • new column in the grid to add a color column aligned with color legend
  • increase the size of the query area and add a copy button to copy query text
image

Why this PR

  • I think that analysis of query history is more interesting using Query Hash as filter that QueryID because we can see history :-)
  • I prefer to agregate by plan Hash + Interval for better metrics

Which component(s) does this affect?

  • Desktop App (PlanViewer.App)
  • Core Library (PlanViewer.Core)
  • CLI Tool (PlanViewer.Cli)
  • SSMS Extension (PlanViewer.Ssms)
  • Tests
  • Documentation

How was this tested?

2026-03-29_23h04_31

Describe the testing you've done. Include:

  • Plan files tested : Query History
  • Platforms tested : Windows Only

Checklist

  • I have read the contributing guide
  • My code builds with zero warnings (dotnet build -c Debug)
  • All tests pass (dotnet test)
  • I have not introduced any hardcoded credentials or server names

- Update QueryStoreHistoryWindow constructor to accept query hash, metric tag, and time range parameters
- Update QueryStoreHistoryWindow.axaml.cs LoadHistoryAsync to call new hash-based service method
- Update QueryStoreHistoryWindow.axaml UI layout
- Add average line to chart in UpdateChart method
- Update QueryStoreGridControl ViewHistory_Click to pass queryHash, metric, and time range
• Generate a new query to get query history data Group data by PlanHash and IntervalStart. Get inspired by the existing FetchHistoryAsync but create a new FetchAgregateHistoryAsync. Use smart agregation for other fields
 • sum(field) for Totals% fields and Executions
 • avg(field) for Avg% fields
 • max(last_execution)
• Allow the use to select several dots in the charts using a box selector
• When the user finish the selection with the box (or a single dot selection) hightligh the corresponding rows in the query history grid
• Add a thin color column in the query history grid like the legend in chart
• add a small light grey border for dots
• the label of avg in the chart should only have "avg:<value>". Dont insert the metric inside this label.
• The avg label should have a light grey transparent background and be just above the avg horizontal line
• make the avg horizontal line a little more transparent
• in the chart the Y-axis should always include 0 as origin
• make 2 buttons "Range Period" and "Full History" and highlight the selected and current one
• remove the refresh button
• align the informatial text (number of interval, number of plans...| period) to the right
• remove the word metric on top of the metric selector
• make the X-axis label more smart : hours first (top) and the date and "agregate date". Still use an adaptative X-axis display if the interval is large
- emphasize selected dots : bigger and white border
- allow the user to select multiples rows in the grid using standard CRLT+Click or SHIFT+Click for multiselection
- emphasize the dots of a manually selected rows
- when the user click on a planHash in the legend : highlight all dots and the line (thicker and less transparency). also - - recompute the avg in the chart using selected/highlighted dots
Copy link
Copy Markdown
Owner

@erikdarlingdata erikdarlingdata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Romain, great work on this — the QueryHash approach is the right call for historical analysis, and the chart/grid interaction is really well done. A few things I caught:

Issues

1. Duplicate using System;
QueryStoreHistoryWindow.axaml.cs has using System; twice at the top (same issue as PR #153).

2. FetchHistoryByHashAsync is dead code
The window only calls FetchAggregateHistoryAsync. FetchHistoryByHashAsync (~226 lines) is added but never referenced anywhere. Should either be removed or wired up.

3. LabelBackgroundColor alpha of 270 exceeds byte range

_avgLine.LabelBackgroundColor = ScottPlot.Color.FromHex("#333333").WithAlpha(270);

Max alpha is 255. This will either clamp or overflow depending on ScottPlot's implementation.

4. OrderByToMetricTag maps "memory" to "TotalCpuMs"
Looks like a copy-paste error — should probably map to "AvgMemoryMb".

5. Display properties use N2 for integer-valued totals
TotalLogicalReadsDisplay, TotalLogicalWritesDisplay, TotalPhysicalReadsDisplay format with N2 (two decimal places). These are integer sums so N0 would be more appropriate. The averages as N2 are fine.

SQL

Looks solid — parameterized, READ UNCOMMITTED, proper weighted averaging. 👍

Overall this is a substantial and well-structured rewrite. Happy to merge once those items are addressed.

@rferraton
Copy link
Copy Markdown
Contributor Author

rferraton commented Mar 30, 2026

@erikdarlingdata : it should be OK

@erikdarlingdata erikdarlingdata merged commit bd8efda into erikdarlingdata:dev Mar 30, 2026
2 checks passed
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.

2 participants