feat: cost CI runs against stored production statistics (#3353 analyzer half)#154
Merged
Conversation
There was a problem hiding this comment.
Query Doctor Analysis
3 queries analyzed
0 regressed · 0 improved · 0 new · 0 removed
2 pre-existing issues
SELECT "guests"."id", "guests"."session_id", "guests"."username", "guests"."avatar_path", "guests"."color", "guests"."side", "guests"."audio_recording_path", "guests"."audio_recording_public", "gue...
indexassets(event_id, inserted_at desc)
cost 31,003,449 → 1,498 (100% reduction)SELECT * FROM guest_ip_addresses WHERE ip_address = '127.0.0.1';
indexguest_ip_addresses(ip_address)
cost 154,402 → 8 (100% reduction)
Using assumed statistics (10000000 rows/table). For better results, sync production stats.
More detail → get_ci_run({ runId: "019edcc2-921a-70af-92f7-a0254e49fa46" }) · view run · docs
At CI time, pull the project's stored production stats over the relay RPC (getProductionStats, @query-doctor/core 0.10.4) and cost queries with fromStatisticsExport when present, falling back to the synthetic assumption otherwise. The resulting statisticsMode flows through to the Site API payload, so runs modeled on real prod cardinality are labelled as such instead of being scored on 10M-row / 0.9-correlation defaults. Stats-mode precedence in determineStatsMode is now: API production stats > explicit stats file > synthetic assumption. This replaces the standing "grab recent stats from API if they exist" TODO. Closes the analyzer half of #3353 (Query-Doctor/Site). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bf5bf26 to
3a1d2c3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
At CI time, the analyzer now pulls the project's stored production statistics over the relay RPC
getProductionStats()and costs queries withStatistics.statsModeFromExport(...)when a snapshot exists — instead of always scoring against syntheticfromAssumption(10M-row / 0.9-correlation) defaults.The resulting
statisticsModealready flows through to the Site API CI payload (reportContext.statisticsMode), so runs modeled on real prod cardinality are labelled as such on the dashboard (the Site indicator shipped in Query-Doctor/Site).How
main.ts (runInCI)— pullapi.getProductionStats()(scoped server-side to this CI connection's project; no args). On RPC failure → warn + fall back to synthetic. Pass intoRunner.build.runner.ts (determineStatsMode)— new precedence: API production stats → explicit stats file → synthetic assumption. Reuses the existingstaticStatisticsStrategypath the file branch already used, so no new sync/restore machinery. Replaces the standingTODO: grab recent stats from API if they exist.@query-doctor/corebumped^0.10.3 → ^0.10.4(the published version that carries thegetProductionStatscontract).Why this is safe / backwards-compatible
Runner.buildpass noproductionStats, sodetermineStatsModeskips the new branch and behaves exactly as before — a no-op for every pre-existing path.ExportedStats.array().parse()is intentional and matches the siblingupdateStatisticspath (api-client.ts): trusted backend data validated on write, unlike the untrusted file path.Tests
Runner.determineStatsModeprecedence (export-when-present, precedence over a file path, empty/no-stats → synthetic).npm run typecheckclean.FATAL: database system is in recovery mode) — 0 assertion failures, my changed symbols in 0 failure traces. Trust CI for the integration tier.Dependency / coordination
@query-doctor/core@>=0.10.4published (done) — it carriesServerApi.getProductionStats.🤖 Generated with Claude Code