mirror of
https://github.com/MeshCore-Beacon/beacon-server.git
synced 2026-12-06 05:04:31 +00:00
* feat(db): packet_sites table and indexes * feat(ingest): keep each packet's site row in the observation insert * feat(db): packet_sites backfill, reconcile and audit * feat(db): region packet pages from packet_sites when trusted, with an exact page cursor * feat(db): packet_sites front sweeper with plan and liveness metrics * feat: boot repair, reconcile, audit, sweep and first-time verification for packet_sites * fix(db): read no site range when no packet was first heard in the window * fix(db): read the window guard's maxima through indexes * test(planguard): packet_sites statements active, data-derived cases, diff and storediff * docs(api): pageCursor applies to region packet pages * fix(db): drop packet_sites trust again after the unsited fallback write * fix(db): the packet_sites audit refills a pair at its newest hearing * fix(db): bounded region reads fill the page within the request, else today's statement answers * fix(planguard): tie_cut needs both pages at the limit and members of other identities * fix: packet_sites sweep without JIT, one verification VACUUM, read-only checks to the newest id * docs(api): cursor and pageCursor on region pages served without nextPageCursor * test: drop local baselines of entries the copy skips; plain race schedule names * test(planguard): storediff walks of the bounded region shapes; local baselines after the overlay rebuild * fix(db): drop message-site trust again after the unseeded insert * fix(db): a region page cursor's fallback to today's statement continues from its exact position
42 lines
2.8 KiB
SQL
42 lines
2.8 KiB
SQL
-- Copyright 2026 Beacon Contributors
|
|
-- SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
-- Fixture step 80: ANALYZE samples 300 x the largest statistics target of a table's columns, at random, so on a
|
|
-- table above 60,000 rows two builds would get different statistics and could plan differently. One column per
|
|
-- such table that no statement filters, joins or sorts on gets a target large enough to cover the table, so
|
|
-- ANALYZE reads every row; every other column keeps default_statistics_target = 200, and its statistics come out
|
|
-- the same on every build.
|
|
ALTER TABLE known_routes ALTER COLUMN path_key SET STATISTICS 10000;
|
|
-- The reference copy's known_routes.iata statistics list every region it holds as a most common value, so a
|
|
-- region they miss (a new one, or one loaded after ANALYZE) is estimated at one row. 200 entries cannot hold the
|
|
-- fixture's 400-odd regions; 1000 can, which keeps that behaviour.
|
|
ALTER TABLE known_routes ALTER COLUMN iata SET STATISTICS 1000;
|
|
ALTER TABLE packets ALTER COLUMN raw_payload SET STATISTICS 10000;
|
|
ALTER TABLE packet_observations ALTER COLUMN airtime_ms SET STATISTICS 10000;
|
|
-- Every packet_sites column is read by some statement; route_type has four values, so a full sample leaves its
|
|
-- statistics as they would be anyway.
|
|
ALTER TABLE packet_sites ALTER COLUMN route_type SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_iata_observations ALTER COLUMN observation_count SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_packet_sets ALTER COLUMN packets SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_observer_identity ALTER COLUMN display_name SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_paths ALTER COLUMN receptions SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_signal ALTER COLUMN rssi_sum SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_advert_hearings ALTER COLUMN name SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_advert_sets ALTER COLUMN direct_packets SET STATISTICS 10000;
|
|
ALTER TABLE analytics_hourly_scope_sets ALTER COLUMN packets SET STATISTICS 10000;
|
|
|
|
-- Fail the build when a table outgrows that: more than 3,000,000 rows (10000 x 300), or above 60,000 rows with
|
|
-- no such column.
|
|
DO $$
|
|
DECLARE r record;
|
|
BEGIN
|
|
FOR r IN SELECT c.relname, (xpath('/row/n/text()', query_to_xml(format('SELECT count(*) AS n FROM public.%I', c.relname), false, true, '')))[1]::text::bigint AS n,
|
|
(SELECT max(a.attstattarget) FROM pg_attribute a WHERE a.attrelid = c.oid AND a.attnum > 0 AND NOT a.attisdropped) AS tgt
|
|
FROM pg_class c WHERE c.relnamespace = 'public'::regnamespace AND c.relkind = 'r' LOOP
|
|
IF r.n > 300 * greatest(r.tgt, 200) THEN
|
|
RAISE EXCEPTION 'fixture: % holds % rows, more than ANALYZE reads at its largest statistics target %; give it a full-sample column in 80_statistics.sql',
|
|
r.relname, r.n, greatest(r.tgt, 200);
|
|
END IF;
|
|
END LOOP;
|
|
END $$;
|