Repository navigation
Leave the monitor's own statement and dropped databases out of Query Store regressions (#6654) - #6665
Conversation
…ery Store regressions (#6654)
| queries would otherwise fill the 50-row cap. A database the user picked is read as asked; an unknown set leaves out nothing. */ | ||
| var excludedDatabases = databaseNames is { Count: > 0 } | ||
| ? null | ||
| : (await CurrentDatabaseScope.NarrowAsync(_dataSource, serverId, DatabaseFilter.All, windowStartUtc: baselineStartUtc, cancellationToken: cancellationToken)).ExcludedNames; |
There was a problem hiding this comment.
This call passes no logger, and an existing guard fails on exactly that.
CurrentDatabaseScopeLoggerThreadingTests.EveryNonTestCaller_OfACurrentDatabaseScopeLookup_PassesALogger walks every *.cs under Darling/ except Darling.Tests/, matches CurrentDatabaseScope\.(…|NarrowAsync|…)\(, takes the text from the match to the next ;, and reports any call expression that does not contain logger (Darling.Tests/CurrentDatabaseScopeLoggerThreadingTests.cs:36-58). The expression here is
CurrentDatabaseScope.NarrowAsync(_dataSource, serverId, DatabaseFilter.All, windowStartUtc: baselineStartUtc, cancellationToken: cancellationToken)).ExcludedNames
— no logger, so this file becomes an offender and the guard goes red. Its own summary is the invariant this breaks: "The Viewer reaches the same readers with no host logger; it calls only the readers, whose logger parameter is optional, never CurrentDatabaseScope directly." (:27-28)
That is not only a test problem. ReadDroppedAsync fails open and reports the failure only through the logger (CurrentDatabaseScope.cs:157-172, whose comment is explicit: "a SQL or ordinal mistake in it turns all of item 4 off, so each failure is logged once per occurrence at Warning"). With no logger, a broken lookup silently turns the grid's exclusion off with nothing written anywhere — while the Lite twin does log it (LocalDataService.CurrentDatabases.cs:152-155, AppLogger.Warn). The viewer has ViewerLogger.Warn for exactly this shape of best-effort step (ViewerServerTab.Queries.cs:446-450); thread an ILogger through, or give the viewer the same once-per-occurrence warn the other two SKU paths have.
| var excludedDatabases = databaseNames is { Count: > 0 } | ||
| ? null |
There was a problem hiding this comment.
No historical anchor: a custom range that ended before the drop loses the database.
Both MCP twins anchor the dropped set at the window's end when the read is historical — DarlingMcpQueryStoreRegressionTools.cs:99 (asOfUtc: string.IsNullOrWhiteSpace(as_of) ? null : windowEnd) and McpQueryTools.cs:632. This call passes windowStartUtc only, so the anchor falls through to DateTime.UtcNow (CurrentDatabaseScope.cs:134).
CurrentDatabaseScope's header states the rule the omission breaks: "Historical reads. With an as_of the set is the newest snapshot at or before it, with the horizon measured from it (#5633 review M2), so a window that ended before a drop still sees the database." (CurrentDatabaseScope.cs:42-43)
Failure: the toolbar is on a custom range of 1–7 Nov (IsCustomRange, ViewerServerTab.Queries.cs:470) and SalesDb was dropped on 20 Nov. ReadDroppedAsync anchored at now sees SalesDb's last snapshot older than the newest, puts it in the dropped set, and the grid drops every SalesDb regression from a window in which the database was alive and collected — where get_query_store_regressions with as_of=2025-11-07 keeps them. The comment two lines up claims parity with that tool ("as get_query_store_regressions and the top-procedures ranking do"), and this is the one respect in which it diverges. asOfUtc: endUtc is a no-op for the presets (whose end is now) and fixes the custom ranges.
| /* #6654: the monitor's own statements are dropped at collection (QueryStoreCollector.SelfQueryMarker), but the text this read | ||
| resolves from query_store_text can still carry the marker, so a candidate whose text does is left out before the cap too. | ||
| The same keyed lookup the output projection makes, with the MAX(query_text) sample as its fallback. */ | ||
| AND strpos(COALESCE((SELECT x.query_sql_text | ||
| FROM query_store_text AS x | ||
| WHERE x.server_id = $1 | ||
| AND x.database_name = f.database_name | ||
| AND x.query_id = f.query_id), f.query_text_sample, ''), '{{QueryStoreCollector.SelfQueryMarker}}') = 0 |
There was a problem hiding this comment.
The premise this comment (and the PR body) rests on does not hold on Darling, and the hole it leaves is wider than this read.
"the monitor's own statements are dropped at collection (
QueryStoreCollector.SelfQueryMarker)"
They are not, on Darling. The client-side drop tests row.QueryText (QueryStoreCollector.cs:1792), and row.QueryText is read from the query_sql_text ordinal — which the shipping SELECT nulls whenever FetchQueryTextSeparately is on:
string queryTextCol = context.FetchQueryTextSeparately
? "query_sql_text = CONVERT(nvarchar(1), NULL),"
: "query_sql_text = qst.query_sql_text,";
(QueryStoreCollector.cs:768-770, and that flag is true for Darling — DarlingCollectorRunner.cs:2783.)
So on Darling the marker filter at collection is a no-op: row.QueryText is always null, the self query's stats rows are stored, and the text lands separately through QueryStoreTextWriter.WriteAsync, whose only per-text gate is the sensitive-statement scrub (QueryStoreTextWriter.cs:93-110) — no marker check. That is the real root cause, and it is why query_store_text carries the marker in the first place.
Two consequences worth deciding on before this merges:
- The PR body's "so
get_query_store_top(which reads stats rows) never shows them" is wrong for Darling.get_query_store_topresolves text from the samequery_store_textlookup (DarlingDataReader.cs:2776-2783) and filters onlyt.query_text NOT LIKE 'WAITFOR%'(:2804). The monitor's own statement is still listed there, and in the Queries grids that share that tail. The collector's own comment asserts the opposite — "The exclusion instead happens in the read loop … identical semantics" (QueryStoreCollector.cs:831-840) — and so doesDarlingSelfQueryMarkerTests' summary ("so they never top a Top Queries or Query Store list"). Both are stale for the separate-fetch path. - One filter at the writer (
QueryStoreTextWriter, beside the existingscrub.TryTexthook) or at the text fetch would close every Darling surface at once, instead of onestrposper reader. If the narrow read-level fix is the deliberate choice for get_query_store_regressions lists the monitor's own Query Store collector statement, and databases the server no longer has #6654, the body should say the other Darling surfaces still show it rather than claim they do not.
Mechanically the predicate itself is fine (it sits in qualified, above ranked/slots/LIMIT, so total_count and the page agree), and the '' tail of the COALESCE keeps it fail-open when neither text is known.
| foreach (var (q, database, text) in new[] | ||
| { | ||
| (20L, Db, "SELECT normal"), | ||
| (21L, Db, "/* " + QueryStoreCollector.SelfQueryMarker + " */ SELECT own"), |
There was a problem hiding this comment.
The fixture carries inline text, which is the one shape a live Darling store does not produce — so the arm that fires in production is the one this does not test.
WriteAsync sets QueryStoreCollector.Row.QueryText, so the marker lands in query_store_stats.query_text and the new predicate finds it in the f.query_text_sample fallback. On a real Darling store that column is null for every row collected since the separate-fetch cutover (QueryStoreCollector.cs:768-770), and the marker lives only in query_store_text — the SELECT x.query_sql_text … arm (QueryStoreRegressionBaseline.cs:580-583). Nothing here puts a row in query_store_text, so a mistake in that subquery's own predicates (wrong column, database_name vs query_id swapped, a missing server_id) passes this test green: the subquery just returns NULL and the fallback answers.
This is the trap in .github/REVIEW-TRAPS.md: "A test that constructs a 'four maintenance anomalies in one run' fixture is testing a shape no live run produces (#3709…). Fixtures should carry the population the engine actually emits, or say they do not."
A second row for query 21 — INSERT INTO query_store_text (server_id, database_name, query_id, query_sql_text, …) with the marker and the inline QueryText left null — would exercise the arm that matters, and would also pin that the keyed lookup matches the projection's.
Non-blocking notes (none of these drive the verdict)1. The suite filters that were run would not have run the guard that fails. The test plan lists 2. Stale doc comment left behind. 3. The exclusion predicate is hand-written rather than aliased. 4. The marker subquery adds a correlated lookup to the hot 5. The viewer grid omits rows with nothing on the surface saying so. The body calls this out ("no banner; the grid has no envelope"), so it stays a note — but it is worth weighing against the reason 6. Parity on the Lite marker filter checks out. "Considered, not added" is right, and for the reason given: |
There was a problem hiding this comment.
Verdict: CHANGES REQUESTED
Findings are inline (two on the viewer call, one on the shared SQL, one on the new fixture); non-blocking notes are in a separate comment.
Claims
- VERIFIED — the new
@@Xexclusion and the marker filter sit inqualified, before the rank and the cap, andBindtakes the new token —QueryStoreRegressionBaseline.cs:574-584aboveranked/slots/LIMITat:586-676; token:239,Bind:243-249. - VERIFIED —
$10in the MCP read,$9in the viewer's, bound withDatabaseFilter.ExcludeParameter—DarlingQueryStoreRegressionReader.cs:117,334;ViewerDataService.QueryStoreRegressions.cs:122,303. - VERIFIED — the MCP tool narrows with
CurrentDatabaseScope.NarrowAsyncand reports both keys on the page and on the empty answers —DarlingMcpQueryStoreRegressionTools.cs:98-100,122-123,160-161. - VERIFIED — a named database is read as asked —
CurrentDatabaseScope.cs:220(unchanged unlessIsAll);McpQueryTools.cs:631-633. Asserted by thenamed/dbarms of both new tests. - VERIFIED — the Lite twin gets the same exclusion and the same two fields —
McpQueryTools.cs:631-636,679-680;LocalDataService.QueryStoreRegressions.cs:131,318,409-410(values bound aftermaxRows, so the positional order holds). - VERIFIED — the viewer grid excludes dropped databases with no banner —
ViewerDataService.QueryStoreRegressions.cs:212-214; nothing added atViewerServerTab.Queries.cs:463-476. - VERIFIED — every by-hand test binder got the parameter: all four sites that bind
plan.HighStart—QueryStoreRegressionsDailyBaselineLiveTests.cs:185,QueryStoreRegressionsFailureGroupsLiveTests.cs:212,QueryStoreRegressionsIntervalTableLiveTests.cs:157,182. All four statements in both twins go throughBind, so none is short a$n. - VERIFIED — "Considered, not added": Lite needs no marker filter —
QueryStoreCollector.cs:768-770keeps Lite's inlineqst.query_sql_text, so the drop at:1792fires; Lite has no text table (LocalDataService.QueryStoreRegressions.cs:95).RegressionCoverageSqlis indeed un-narrowed (DarlingQueryStoreRegressionReader.cs:149-167). - UNVERIFIED — the revert-proof (
Expected [20], Actual [20, 21, 30]) — needs the gated PostgreSQL rig. - UNVERIFIED — "Darling … Total 563, Failed 0" — needs the rig, and is consistent with the guard below still being red: none of the listed filters matches
CurrentDatabaseScopeLoggerThreadingTests. - UNVERIFIED — "Lite … Total 41, Failed 0" — a read-only tree cannot run DuckDB tests.
- REFUTED — "the collector drops its own marker rows at collection, so
get_query_store_top… never shows them" — on Darling the drop testsrow.QueryText(QueryStoreCollector.cs:1792) and the SELECT nulls that column whenFetchQueryTextSeparatelyis on (:768-770), which it is for Darling (DarlingCollectorRunner.cs:2783). The stats rows are stored, text lands unfiltered viaQueryStoreTextWriter.cs:93-110, andget_query_store_topresolves it from the samequery_store_textlookup (DarlingDataReader.cs:2776-2783) behind onlyNOT LIKE 'WAITFOR%'(:2804).
Riskiest lines
Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.QueryStoreRegressions.cs:214— first directCurrentDatabaseScopecall from the viewer, with no logger, so the documented fail-open goes unreported — UNCOVERED as behaviour; the existing source-walking guardEveryNonTestCaller_OfACurrentDatabaseScopeLookup_PassesALoggerfails on it, which is the finding, not the coverage.Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.QueryStoreRegressions.cs:212— noasOfUtc, so a past custom range is judged against today's dropped set — UNCOVERED (ViewerQueriesTests.cs:1270reaches the line but seeds nodatabase_states, so the branch passes either way).Darling/PerformanceMonitor.Darling.Storage/QueryStoreRegressionBaseline.cs:580— the correlatedquery_store_textlookup that decides which rows exist on both surfaces — covered by the new live test only through thequery_text_samplefallback; thequery_store_textarm, the one that fires in production, is UNCOVERED.
Traps near this diff
- "Lite and Darling ship in parity … a fix to one SKU's reader, tool, alert or description without the counterpart's is a finding" — does not apply — both SKUs got the exclusion and both envelope keys (
DarlingMcpQueryStoreRegressionTools.cs:160-161,McpQueryTools.cs:679-680), and the marker filter is rightly Darling-only (QueryStoreCollector.cs:768-770). - "Every MCP filter is part of the query, not a post-filter on the page (#3641)" — does not apply —
QueryStoreRegressionBaseline.cs:574-584,LocalDataService.QueryStoreRegressions.cs:318. - "A
total_*assigned from a.Countis a count of the page unless the set is provably whole (#3699)" — does not apply —total_countisCOUNT(*) OVER ()onqualified, now below the new predicates (QueryStoreRegressionBaseline.cs:597,LocalDataService.QueryStoreRegressions.cs:331). - "Truncation inferred from a full page … the flag is
fetched.Count > limit" — does not apply — over-fetch untouched (DarlingMcpQueryStoreRegressionTools.cs:108,125). - "Two copies of one definition pinned EQUAL … Alias, do not copy (#3684)" — does not apply — one copy, shared by both twins through
Bind;ExcludeClausetakes anintwhere the statement needs a token. - "A test that constructs a … fixture is testing a shape no live run produces (#3709). Fixtures should carry the population the engine actually emits, or say they do not." — applies —
QueryStoreRegressionsFailureGroupsLiveTests.cs:251seeds inlinequery_text, which Darling has not produced since the separate-fetch cutover. - "An empty analysis window is 'unavailable', not an all-clear (#3553)" — does not apply as a verdict item — the viewer omits rows while its empty text names a different cause, but the body documents the missing banner as deliberate.
Divergence (blind read vs PR body)
- The body's root cause is inverted for Darling: it treats the collection-time self-exclusion as working and this read as the only leak. The tree says the exclusion is dead on Darling, so the marker statement is a stored fact row and every reader resolving text from
query_store_textcan list it. One reader is patched; the body says the others need no patch. - "Viewer grid read: leaves the dropped databases out" understates it. It is the first direct
CurrentDatabaseScopecaller in the viewer (which an existing guard forbids without a logger, and whose summary records "neverCurrentDatabaseScopedirectly" as an invariant) and it drops the historical anchor both MCP twins pass, so the stated parity with those two does not hold. - The diff makes a change the body does not mention: the shared
SuffixSqlmeans the viewer grid also stops listing the monitor's own statement. Good, but the viewer bullet and the CHANGELOG entry credit the viewer with only the dropped-database half.
Reviewer checklist
- Build both SKUs;
TryGetQueryStoreRegressionsFromTableAsyncgained a parameter after itsCancellationToken(ViewerDataService.QueryStoreRegressions.cs:335-336), which CA1068 flags at the viewer'slatest-recommendedlevel — a warning here, but confirm the build stays clean. - Re-run Darling with
*CurrentDatabaseScope*added to the filters and confirm the logger guard is green. - On the rig,
EXPLAIN (ANALYZE)both forms over a few thousand flagged candidates and compare the new SubPlan's loop count with the pre-change plan. - On a live Darling store, check whether
get_query_store_topand the Queries grids list the monitor's own marker statement today — the decision point for a writer-side fix instead of a per-reader one.
…read (#6654) Merge dev (one conflict, the Viewer regressions read: keeps dev's measured purge-edge margin and this PR's left-out databases). The Viewer now passes a logger to CurrentDatabaseScope (the Stage=Guard threading test), ExcludeClause has one definition that the shared regressions statement uses, the doc comments name the regressions consumers, and the Viewer grid and the web page say which dropped databases were left out.
There was a problem hiding this comment.
Verdict: LGTM
Claims
- VERIFIED — "The call passes a logger... a small ViewerStoreLogger (new file) forwards warnings to ViewerLogger.Warn" —
Darling/PerformanceMonitor.Darling.Viewer/ViewerStoreLogger.cs(new file) wrapsILogger,IsEnabledgates atWarning,LogcallsViewerLogger.Warn("ViewerDataService", ...);ViewerDataService.QueryStoreRegressions.cs:228passeslogger: ViewerStoreLogger.InstancetoCurrentDatabaseScope.NarrowAsync. - VERIFIED — "New
DatabaseFilter.ExcludeClause(string column, string parameter); theintoverload calls it...QueryStoreRegressionBaselineuses it withExcludeToken" —DatabaseFilter.cs:131,138andQueryStoreRegressionBaseline.cs:576({{DatabaseFilter.ExcludeClause("f.database_name", ExcludeToken)}}). - VERIFIED — "The only change in the shared statement's text: the second
@@Xno longer repeats the::text[]cast" — old hand-written clause was<> ALL(@@X::text[]); the new sharedExcludeClauseemits<> ALL({parameter})with no second cast, matching the pre-existingintoverload's own shape. - VERIFIED — "Left-out databases are now said on both grids" (Viewer banner + web
noteKey) —ViewerServerTab.Queries.csaddsDatabasesLeftOutBannerText/ShowDatabasesLeftOutBanner, wired at the newQueryStoreRegressionsLeftOutBannerXAML row (ViewerServerTab.xaml:1766,RowDefinitionsgrown to 4, grid moved to row 3); web side addsnoteKey: "databases_left_out_note"to the Query Store Regressionstable()call (server-tabs.js:2139) plus a newleftOutStripinutil.jswired into the empty-answer path inpanels.js:208. - VERIFIED — "Tests:
TheLeftOutBanner_NamesTheDatabases_...;ALeftOutNote_IsDrawnOnAnEmptyAnswer_..." — both present and exercise real behavior (ViewerQueryStoreRegressionsDataStartTests.cs,web-partial-window-harness.mjs+WebPartialWindowBehaviourTests.cs), not text/spelling checks. - UNVERIFIED — the cited live-run totals ("Total 563, Failed 0", "Total 4453, Failed 0", etc.) — require executing the test suites against a live PostgreSQL instance, not checkable from a read-only tree.
- REFUTED — none found.
Riskiest lines
Darling/PerformanceMonitor.Darling.Storage/QueryStoreRegressionBaseline.cs:576— the exclude clause now sharesDatabaseFilter.ExcludeClause, dropping the second::text[]cast from the generated SQL text — covered byQueryStoreRegressionsFailureGroupsLiveTests(new#6654 reviewassertions against a live Postgres viaGetQueryStoreRegressionsWithScopeAsync, which fail if the cast removal broke parameter typing).Darling/PerformanceMonitor.Darling.Viewer/ViewerDataService.QueryStoreRegressions.cs:228— now passesViewerStoreLogger.InstanceintoCurrentDatabaseScope.NarrowAsync— covered only byCurrentDatabaseScopeLoggerThreadingTests(a source-text regex scan, not a behaviour test) | UNCOVERED by a behaviour test.Darling/PerformanceMonitor.Darling.Viewer/ViewerServerTab.Queries.cs:472—ShowDatabasesLeftOutBanner(QueryStoreRegressionsLeftOutBanner, read.DatabasesLeftOut)WPF wiring — the pure text builderDatabasesLeftOutBannerTextis unit-tested, but the codebehind call that sets the banner'sText/Visibilityon a live grid load has no WPF-level test | UNCOVERED.
Traps near this diff
- "Lite and Darling ship in parity... a fix to one SKU's reader, tool, alert or description without the counterpart's is a finding" — does not apply here: this follow-up's changes (Viewer logger threading, the shared
ExcludeClausehelper, the Viewer grid banner, the webpanels.js/util.jsnote wiring) are all to Darling-only surfaces (the separate Viewer WPF app and web dashboard). Lite has no Query Store Regressions UI at all (grepfinds onlyLite/Mcp/McpQueryTools.csandLite/Services/LocalDataService.QueryStoreRegressions.cs— tool/service layer only, no WPF grid), and its MCP-leveldatabases_left_outparity was already in place from round 1, untouched by this range. - "never answer a trap with a test that reads source text or asserts how code is spelled" — the modified
EveryTabRead_OfTheGrid_HasItsProberegex-count test (updated for theGetQueryStoreRegressionsAsync→GetQueryStoreRegressionsWithScopeAsyncrename) andCurrentDatabaseScopeLoggerThreadingTests's caller scan are both source-text checks, but neither is newly introduced as the answer to a defect here — the real behaviour coverage for the banner/exclusion logic is the new live-Postgres assertions and theutil.jsNode-harness test; the text scans are incidental rename upkeep on pre-existing guards.
Divergence (blind read vs PR body)
None — the PR body's "Round 1 notes" (items 1-5) match the diff exactly: the ViewerStoreLogger fix, the stale doc-comment updates in DatabaseFilter.cs/CurrentDatabaseScope.cs, the ExcludeClause(string, string) consolidation (including the precise "second cast dropped" detail), and the Viewer-banner/web-noteKey pair are all present and wired as described, with the marker-subquery explicitly left untouched as stated.
Reviewer checklist
- Run the cited live-Postgres suites (
*QueryStoreRegressions*,*DroppedDatabaseScope*, theStage=Guardtrait) to confirm the claimed "Total X, Failed 0" results, and visually confirm the newQueryStoreRegressionsLeftOutBannerrow renders correctly (no clipping/overlap) in the Viewer at a few window sizes.
…; anchor the Viewer's historical range (#6654)
# Conflicts: # Darling/Darling.Tests/InvestigationEvidenceFamiliesLiveTests.cs
Claude posting for Erik Darling. Round 1 findings fixed; round 2 (5636828427) is LGTM.
Claude posting for Erik Darling.
Closes #6654.
Why
get_query_store_regressionslisted the monitor's own statement and queries from a database the server has dropped. On Darling the collector's own-statement drop (QueryStoreCollector.SelfQueryMarker,QueryStoreCollector.cs:1792) never fires: it testsrow.QueryText, andFetchQueryTextSeparately(on for Darling) nulls that column, so the statement's stats rows are stored and its text lands inquery_store_textwith no marker check. Every reader that resolves text fromquery_store_textcan therefore list it. The regressions read had no text filter and no current-database filter, and dropped databases also filled the row cap. Round 1 (review 5636588372) widened the fix to every ranked Query Store reader (below).What changes
QueryStoreRegressionBaseline.SuffixSql(shared by the MCP tool and the Viewer grid): thequalifiedstage, before the rank and the cap, now drops (a) a candidate whose resolved text (the same keyedquery_store_textlookup the projection makes, with the MAX(query_text) sample as the fallback) containsSelfQueryMarker, and (b) a candidate in an excluded database (new@@Xtoken, atext[]parameter:$10in the MCP read,$9in the Viewer read, bound withDatabaseFilter.ExcludeParameter).Bindtakes the new token.CurrentDatabaseScope.NarrowAsync(same as the top-procedures tool), and reportsdatabases_left_outanddatabases_left_out_noteon the payload and on the empty answers (McpHelpers.WithDatabasesLeftOut). A named database is read as asked.get_query_store_regressionsgets the same dropped-database exclusion (GetDroppedDatabasesAsync,BuildDbExcludeClauseinqualified) and the samedatabases_left_outfields.Test plan
QueryStoreRegressionsFailureGroupsLiveTests.TheMonitorsOwnStatementAndADroppedDatabase_AreNotListed_AndTheDroppedOneIsNamed: marker row (21) and dropped-database row (30) absent with no database chosen; 20 stays;databases_left_out = [qsGone]; naming the dropped database lists 30; naming the live database lists only 20. Revert-proved: with both SQL predicates neutered it fails withExpected [20], Actual [20, 21, 30].QueryStoreRegressionsToolTests.ADroppedDatabasesRegression_IsLeftOut_AndNamed_UntilTheDatabaseIsNamed. Revert-proved (exclusion not passed):Expected [20], Actual [20, 30].*QueryStoreRegressions*,*DroppedDatabaseScope*,*ViewerQueriesTests*,*Census*,*Ratchet*: Total 563, Failed 0.*QueryStoreRegressions*,*Census*,*Ratchet*: Total 41, Failed 0.CurrentDatabaseScopeLoggerThreadingTests(Stage=Guard). It FAILED on the Viewer's newNarrowAsynccall (no logger) and passes after the fix below; the wholeStage=Guardtrait passes (Total 4453, Failed 0).CurrentDatabaseScopeLoggerThreadingTests,*QueryStoreRegressions*,*DroppedDatabaseScope*,*ViewerQueriesTests*,*DatabaseFilter*,*WebPartialWindowBehaviourTests*,*WebDataStartNoteTests*,*ServerTabEmptyStatesAndHeadersTests*,*ViewerQueryGridsDataStartLiveTests*,*WebQueryStoreGridGroupsTests*,*Census*,*Ratchet*: Total 885, Failed 0. After a second merge of dev (no conflicts) the non-live classes and the Guard trait were re-run: Total 92 and 4453, Failed 0.pre-push.shper the brief).Round 1 notes
Merged dev. The one conflict,
ViewerDataService.QueryStoreRegressions.cs, was dev's #6686 purge-edge margin against this PR's left-out databases in the table read; both are kept (the margin code, andexcludedDatabasespassed toAddQueryStoreRegressionsParameters).CurrentDatabaseScopeLoggerThreadingTestsfailed on the Viewer call. Fixed the way it asks: the call passes a logger. The Viewer has no host logger, so a smallViewerStoreLogger(new file) forwards warnings toViewerLogger.Warn; a failed dropped-database read now shows in the Viewer log instead of vanishing. The test's class summary said the Viewer never callsCurrentDatabaseScopedirectly; reworded.DatabaseFilter.cs,Excludingand the twoExcludeClausereferences (and the matching one inCurrentDatabaseScope.cs): the regressions read (MCP tool and Viewer grid) is named as a consumer.DatabaseFilter.ExcludeClause(string column, string parameter); theintoverload calls it;QueryStoreRegressionBaselineuses it withExcludeTokeninstead of a hand-written copy. The pinDroppedDatabaseScopeLiveTests(" AND ($6::text[] IS NULL OR database_name IS NULL OR database_name <> ALL($6))") still passes. The only change in the shared statement's text: the second@@Xno longer repeats the::text[]cast.GetQueryStoreRegressionsWithScopeAsyncreturns the rows with the left-out names (GetQueryStoreRegressionsAsyncwraps it, so existing callers are unchanged). A new bannerQueryStoreRegressionsLeftOutBannersits under the "Showing since" banner (a grid row was added; the data grid is now row 3). Text fromDatabasesLeftOutBannerText: "Left out of this grid: Gone. The server's newest database snapshot no longer lists it (dropped or detached since an earlier snapshot did). Pick the database in the filter to read its history." Same rule asDatabasesLeftOut: names sorted and distinct, at most 20 named with "(N in all; the first 20 are listed)", same reason. The plain-English checker reports it clean.databases_left_out_noteat all, on either a populated or an empty answer. It now names the key as itsnoteKey(populated answer), andpanels.jsdraws it on an empty answer through a newleftOutStrip(only for a grid that names the key, so no other panel changes).TheLeftOutBanner_NamesTheDatabases_InTheWordsOfDatabasesLeftOut(text for none, blank, one, several, more than 20);ALeftOutNote_IsDrawnOnAnEmptyAnswer_OnlyForAGridThatNamesIt(the shippedutil.jsunder Node, via the existing harness); the live test now also reads the Viewer path (rows and names with no database chosen; naming the dropped database reads it as asked and names nothing). Two existing text pins were updated for the changed spelling (the data grid's row number; the tab's read call name; the empty-branchmountline).Round 1 review (changes requested)
Review 5636588372. Per finding:
QueryStoreSelfStatement(new,Darling/PerformanceMonitor.Darling.Storage): the marker against the text resolved fromquery_store_text, falling back to the inline sample where a read has one. The regressions read (QueryStoreRegressionBaseline) uses it too. A person or agent no longer sees the monitor's own statement in any ranked Query Store list. The collector is not changed (see Considered, not added). The stale comments are fixed:QueryStoreRegressionBaseline.cs,QueryStoreCollector.cs(the drop site now says it does not fire on the separate-fetch path), and theDarlingSelfQueryMarkerTestssummary.ViewerDataService.QueryStoreRegressions.csnow passesasOfUtc: literalEndUtc(the custom range's end; null for a preset, where the end is now), as both MCP twins anchor at the window end. Test: inTheMonitorsOwnStatementAndADroppedDatabase_AreNotListed_AndTheDroppedOneIsNamed, a custom range ending 2 hours ago, before the database was dropped, still lists the dropped database's query 30 and names nothing. I did not run it against the old code; with no anchor the dropped set is read as of now and query 30 would be left out.query_store_text. Query 21 (inline sample) stays: it covers the fallback arm.TryGetQueryStoreRegressionsFromTableAsynctakesexcludedDatabasesbeforeCancellationToken(it was added after it); three test call sites updated. The build shows no CA1068 for this file.Readers covered (all hide the monitor's own statement):
get_query_store_top(raw, interval table and daily routes)DarlingDataReader.QueryStoreTopTail: tested on the already-resolved lateral text, before theLIMITViewerDataService.QueryStore.csQueryStoreTopSuffix: the sameQueryStoreComparisonSql: tested on the resolved text of the final rows, AFTER the top-100 cut, so a self statement in the top 100 costs the grid one row (the cut is per period by executions; a correlated lookup per window row would cost more than it saves)DarlingQueryStoreAbortsReader)page, before its cap; oneNOT EXISTSprobe per candidate (only queries with an aborted or failed run reach it); no inline fallback, because rows from before the separate fetch were already filtered by the collectorPLAN_REGRESSIONfact (PgFactCollector.QueryPerf.cs)NOT EXISTS, before itsLIMIT 100PgDrillDownCollector.Queries.cs)LIMIT 5(two sites)regression_targets(InvestigationEvidenceCapture.Families.cs)Readers left alone (fetch ONE query by id, no ranking):
DarlingMcpPlanForcePrecheckTools(plan force precheck),DarlingReproScript(repro script),DarlingWorkerResolveStoredQueryStoreForActualPlanSql(actual-plan resolver). The web Query Store page has no read of its own: it calls the MCP readers above. Readers over the plan cache (query_stats,WAITFORfilters inViewerDataService.QueryStats.csand the like) are not Query Store.Tests. New
QueryStoreSelfStatementReadersLiveTests(production shape: NULL inline text, marker only inquery_store_text, one normal query that stays) covers the MCP top, the Viewer grid, the aborts read and the Viewer comparison. The marker case was added to the existing live tests of the PLAN_REGRESSION fact (PlanRegressionBuiltDaysFallbackLiveTests), the drill-down on both routes (PlanRegressionDrillDownDailyParityLiveTests) and the evidence targets (InvestigationEvidenceFamiliesLiveTests). Revert proof: with the marker constant changed to a word that matches nothing, 5 of these classes' tests fail (the new one, the failure-groups test, and the three above); restored, they pass.Spelling pin deleted.
QueryStoreTopDailyReadLiveTests.TheRawAndTableStatements_AreByteIdenticalToTheirPreSplitTextwas a SHA-256 of the top statements' text, re-taken on each past change; its rule is spelling, and a correct change breaks it, so it and its helper are removed (the tail-sharing test beside it stays).Ran (throwaway PostgreSQL from
pg-runtime.zip, stopped after):*QueryStoreRegressions*,*DroppedDatabaseScope*,*ViewerQueries*,*QueryStoreTop*,CurrentDatabaseScopeLoggerThreadingTests, the new class,*Census*,*Ratchet*,DarlingSelfQueryMarkerTests,ViewerQueryStoreRegressionsDataStartTests,QueryStoreAbortsLiveTests,ViewerTextLookupWindowBoundLiveTests,DatabaseFilterTests,*PlanRegression*,*InvestigationEvidence*,*TopQueriesDatabaseFilter*,*DarlingMcpDataToolsTests*,*QueryStoreIntervalWide*,*TopFill*: Total 1048, Failed 1 (the hash pin above, deleted), Skipped 13. After the fixes:QueryStoreTopDailyReadLiveTests+DarlingSelfQueryMarkerTestsTotal 25, Failed 0; the wholeStage=Guardtrait Total 4453, Failed 0;QueryStoreRegressionsFailureGroupsLiveTestsTotal 8, Failed 0 after the last edit. Not run: the full suite and Lite (the only Lite-shared change is a comment inQueryStoreCollector.cs);pre-push.sh; a cost check (EXPLAIN) of the new probes on a large store.Merged dev (326ff65). One conflict, in
InvestigationEvidenceFamiliesLiveTests.cs,ARegressionOfSqlServersOwnCleanup_IsLeftOut_SoTheApplicationQueryLeads: dev (#6660) changed query 512's text to the bracketed formsys.[change_tracking_1228027148], and this PR added query 513 (the monitor's own statement) to the same fixture loop. Kept both: the PR's 513 rows and loop, with 512 using dev's bracketed text. Build is 0 errors (the 2 warnings are in files this PR does not touch and match dev). RanInvestigationEvidenceFamiliesLiveTests,*QueryStoreSelf*,*QueryStoreRegressions*,*QueryStoreTop*, every*Census*and*Ratchet*class on a throwaway PostgreSQL (stopped after): Total 667, Failed 0, Skipped 9 (the two live classes: 24 run, 0 skipped).Considered, not added
NOT LIKEon the text at 75% of the read's time, and rows already stored stay for the whole retention window, so a read-side filter is needed whatever the collector does.qualifiedWHERE: not changed. No measured cost yet, and moving the filter after the ranking would return fewer than the requested number of rows.RegressionCoverageSql) is not narrowed by the exclusion; the empty answer carriesdatabases_left_outinstead.PerformanceMonitor.Common/InternalStatements.cs(Investigations: the #6575 internal-statement filter misses the bracketed change tracking cleanup text that SQL Server records #6659 pattern) is untouched, as instructed.CHANGELOG entry
SECTION: Fixed
ENTRY:
get_query_store_top, the Viewer's Query Store grid and comparison,get_query_store_regressions, the aborted-and-failed queries read, the PLAN_REGRESSION finding, its regressed-queries drill-down and the investigation evidence's regression targets. All of them now leave it out, andget_query_store_regressionsand the Viewer's Regressions grid also leave out queries from databases the server has dropped (the tool names them indatabases_left_out, the grid in a banner, and a custom range is judged by the databases the server had when the range ended). A dropped database no longer fills the regressions' row cap.REF:
[Leave the monitor's own statement and dropped databases out of Query Store regressions (#6654) #6665]: Leave the monitor's own statement and dropped databases out of Query Store regressions (#6654) #6665