Skip to content

The Query Store grid can show 1 of 20 rows, because the monitor's own statements use up the candidates before they are removed #7736

Closed

Description

@erikdarlingdata

Claude posting for Erik Darling.

The Query Store grid on the Queries tab can show far fewer rows than exist, and a wider range can show fewer rows than a narrower one. Nothing on the page says rows are missing.

What it looks like

On a SQL Server 2025 test server, the grid on a Past day range shows one row. The page asks for 20 (wwwroot/js/pages/server-tabs.js:654), and the reply says truncated: false.

Rows that get_query_store_top returns for the same window as top grows:

Server, window top 20 top 50 top 100 top 200
SQL Server 2025 test server, 24 hours 1 2 3 13
SQL Server 2025 test server, 12 hours 1 1 6 17
SQL Server 2022 test server, 24 hours 16 18 27 32
  • At top: 500 over 24 hours, the SQL Server 2025 test server read 39 rows and 38 fit the response budget. 27 of those 38 are not the monitor's statements, against the one row on the page.
  • At top: 20 on the same server, 4 hours returns 11 rows, 8 hours returns 4, and 12 hours returns 1.

Cause

  • ranked cuts the window to its candidates with LIMIT $8 (Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingDataReader.cs:2736). The value is TopFill.FinalCandidates(top) (:3135, :3260), which is 220 for top: 20 (Darling/PerformanceMonitor.Darling.Storage/TopFill.cs:52, :96).
  • The monitor's own statements are removed after that cut, in the tail (DarlingDataReader.cs:2817, from Leave the monitor's own statement and dropped databases out of Query Store regressions (#6654) #6665), because the marker is only in the text the tail resolves.
  • Darling stores those rows, because its separate text fetch leaves the collector's inline text empty, so the collector's drop does not fire (PerformanceMonitor.Collectors/QueryStoreCollector.cs:1803).
  • The candidate limit was sized for the WAITFOR trim (Top Queries ranked by duration can come back short when WAITFOR statements rank high #5313), which removes a few rows. The monitor's own statements are one candidate for each database, query and plan, and a wider range holds more of them.

The tail removes only WAITFOR text and the monitor's own statements. The removed rows were not read one by one, because they never leave the store.

The Viewer has the same shape (Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.QueryStore.cs:419, :509, :576). Lite keeps inline text and drops these rows when it collects, so this cut does not apply to it.

Who sees it

Any Darling server where the monitor's own statements rank above the real ones for the window: a lightly used server, or one with many databases. On a busy server the real statements rank first and the page fills.

Fix

  1. Leave out the monitor's own statements in ranked, before LIMIT $8, with QueryStoreSelfStatement.NotSelfOfKey (Darling/PerformanceMonitor.Darling.Storage/QueryStoreSelfStatement.cs:83), once QueryStoreSelfKeys.ReadyAsync says the backfill has run. The Regressions read already does this (Darling/PerformanceMonitor.Darling.Service/Mcp/DarlingQueryStoreRegressionReader.cs:290, Darling/PerformanceMonitor.Darling.Storage/QueryStoreRegressionBaseline.cs:1139). Keep the tail's test for a store where the backfill has not run.
  2. Make the same change in the Viewer's read.
  3. Add a test with more of the monitor's rows than candidates, and check that the page still fills with real rows. A test pins the hash of this statement's text, so update that too.

#7730 covers the older unmarked statements on this grid. This fix does not remove those rows until #7730 adds their keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions