Files
beacon-server/db/planguard/sql/pending/SweepPacketSitesFronts.sql
T
MrAlders0n 94b4b40f9b planguard: plan and result regression checks, fixture tier in CI, read-only mode (#240)
* feat(planguard): read sqlc statement text and load a strict plan corpus

* fix(planguard): fail on unextracted statements, keep fragments mode-neutral

* feat(planguard): plan assertions, scoped sort exemptions and narrow retired-index verdicts

* fix(planguard): an errored run always fails

* fix(planguard): keep subplan conds off their parent scan; fail on unanalyzed budgets

* feat(planguard): read-only plan runner, reports and the run command

* fix(planguard): validate identifiers in emitted scripts; prove read-only runs

* feat(planguard): end-state corpus, planted regressions and the generated cached-plan policy

* fix(planguard): derive observer cases from data; mark legacy generic plans

* fix(planguard): bound the dense-region route resolvers; test policy refusals

* fix(planguard): re-measure the dense-region route cases; cover every policy refusal

* feat(planguard): synthetic fixture built through the migrations, checked in CI

* ci(planguard): build the fixture once; guard fixture data for identifiers

* fix(planguard): hash every fixture generator input; harden the fixture guard

* feat(planguard): snapshot diff over every column, named result classes and cursor walks

* fix(planguard): bound the relaxed diff classes; derive the cursor tie from data

* fix(planguard): refuse multi-statement text in the corpus runner

* feat: read-only server mode and an HTTP page diff between two builds

* fix(planguard): refuse escape strings and psql meta-commands in corpus text

* fix: storediff follows each build's own cursor; prove read-only gates via the log

* fix(planguard): match the PostgreSQL lexer on high-bit bytes; check every emitted line

* feat(admin): daily read-only plan check on the maintenance pool, its metric and report

* feat(planguard): daily prod check behind planguard.daily_check

* fix(planguard): cancel fresh runs at shutdown; expose a never-ran check

* ci(planguard): pin the fixture server and collation; refresh baselines

* fix(planguard): calibrate route budgets on one dataset; skip entries whose index is absent
2026-10-19 13:45:39 -04:00

38 lines
2.2 KiB
SQL

-- Copyright 2026 Beacon Contributors
-- SPDX-License-Identifier: AGPL-3.0-or-later
-- name: SweepPacketSitesFronts :one
-- maint, every 30 s; run with SET LOCAL enable_bitmapscan = off, enable_seqscan = off.
-- Read-only. Visits, through each time-ordered packet_sites index, every entry whose key was written in the last
-- @lookback (2 minutes). An index scan that reaches an entry whose heap tuple is dead to every snapshot sets the
-- entry's LP_DEAD hint; when that leaf later fills, the inserting backend deletes hinted entries instead of splitting
-- (nbtree simple deletion). Keeps the three indexes at ~2x a fresh build instead of 4-9x. Changes no row.
-- The ORDER BY ... LIMIT keeps every lateral a per-front index range scan (never flattened into a join).
-- The cap is far above any front's 2-minute volume (SEA: ~150 entries) and only bounds the gauge.
WITH site AS MATERIALIZED (
SELECT ps.iata, ps.payload_type, ps.route_type, ps.scope_id
FROM iata_codes c
CROSS JOIN LATERAL (
SELECT p.iata, p.payload_type, p.route_type, p.scope_id
FROM packet_sites p
WHERE p.iata = c.iata AND p.site_heard_at > now() - $1::interval
ORDER BY p.site_heard_at DESC LIMIT 100000) ps -- idx_packet_sites_site, Index Scan
), typ AS (
SELECT count(*) AS n
FROM (SELECT DISTINCT iata, payload_type, route_type FROM site) f
CROSS JOIN LATERAL (
SELECT 1 FROM packet_sites p
WHERE p.iata = f.iata AND p.payload_type = f.payload_type AND p.route_type = f.route_type
AND p.site_heard_at > now() - $1::interval
ORDER BY p.site_heard_at DESC LIMIT 100000) x -- idx_packet_sites_site_type, Index Only Scan
), scp AS (
SELECT count(*) AS n
FROM (SELECT DISTINCT iata, scope_id FROM site WHERE scope_id IS NOT NULL) f
CROSS JOIN LATERAL (
SELECT 1 FROM packet_sites p
WHERE p.iata = f.iata AND p.scope_id = f.scope_id AND p.scope_id IS NOT NULL
AND p.site_heard_at > now() - $1::interval
ORDER BY p.site_heard_at DESC LIMIT 100000) x -- idx_packet_sites_site_scope, Index Only Scan
)
SELECT (SELECT count(*) FROM site) AS site_live, (SELECT n FROM typ) AS type_live, (SELECT n FROM scp) AS scope_live;