feat(remote): re-dump production statistics on a daily floor - #198
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: "019fa558-4f0f-749a-ba4c-c3b66a738f07" }) · view run · docs
Closes #3671. Shape Drift and Size Drift watch structure and row counts. Neither sees a database whose tables and sizes hold steady while the distribution of its data moves: histograms, most-common-value lists and correlation all age with the values rather than the count. A floor bounds how wrong those can get. The check rides the same schema poll as drift, so no new schedule. A push from either trigger updates the timestamp, so drift and the floor can't dump twice in quick succession. Never fires before a first push. With no baseline there is nothing to compare against, and dumping on a timer for an analyzer that has never pushed would publish statistics for a database the server may not expect. ADR 0007 §2 places this backstop as a cron in Site. It sits in the analyzer instead: the server has no way to ask an analyzer to refresh, so the Site-side version needs a new ClientApi method, an implementation, and a cron, where this needs a timestamp. Worth amending the ADR if the Site placement is preferred. Co-Authored-By: Claude <noreply@anthropic.com>
820944a to
cffc60f
Compare
Review of the daily floor found it never fires for the analyzers it targets. `lastStatsPushAt` is written only by `applyStatistics`, and the sync path reaches the optimizer directly instead, so a seeded analyzer leaves it undefined and `isPastRefreshFloor` short-circuits forever. Only a drift-triggered dump ever armed it, which is the case the floor exists to cover when drift does not fire. It also re-armed nothing across restarts. Seeding now sets the timestamp. It is dated from the seed rather than the snapshot's capture time, which the RPC doesn't carry, so the floor fires 24h after connect rather than immediately. A failing dump also retried on every 60s poll, because the timestamp only advances on success. A statement_timeout on a large pg_statistic read would run DUMP_STATS_SQL ~1440 times a day. Failures now back off for 15 minutes. Renamed `refreshStatsIfDrifted` to `refreshStatsIfStale`, since it has had two triggers since the floor landed. Co-Authored-By: Claude <noreply@anthropic.com>
|
Review found the floor never fires for the analyzers it targets. Fixed in
Seeding now arms it, dated from the seed rather than the snapshot's capture time, which Also fixed: a failing dump retried on every 60s poll, since the timestamp only advances on success. A Two findings left for a follow-up, both pre-existing and wider than this PR:
|
Closes Query-Doctor/Site#3671.
Goal
Bound how stale a snapshot's column statistics can get when neither drift signal fires.
What
Before, a snapshot refreshed only on Shape Drift or Size Drift. A database whose tables and sizes hold steady never re-dumped, however old its statistics got.
After, a connected analyzer re-dumps at least once every 24 hours.
How
isPastRefreshFloorinstats-drift.tsis the decision, kept pure and beside the drift signals.Remoterecords when it last pushed, and the existing schema-poll check now fires on drift or the floor. No new schedule.Two properties worth noting:
Departure from the ADR
ADR 0007 §2 specifies this backstop as a cron in Site. It sits in the analyzer here. The server currently has no way to ask an analyzer to refresh, so the Site-side version needs a new
ClientApimethod, an analyzer implementation, and a cron, where this needs one timestamp. If the Site placement is preferred, amend the ADR rather than leaving the two out of step.Tests
Five cases in
stats-drift.test.ts: never before a first push, not while recent, true at exactly a day, true well past, and a custom floor honoured in both directions.