From b8665ebd66b2d353375b37e8935e89a9a8df197a Mon Sep 17 00:00:00 2001 From: MrAlders0n Date: Thu, 16 Jul 2026 09:42:29 -0400 Subject: [PATCH] perf(db): index packets(last_heard_at) The packet list sorts by last_heard_at, so every page was a seq scan plus sort over all packets. Cheap to maintain now that presence writes are coalesced. --- db/migrations/008_packets_last_heard_index.sql | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 db/migrations/008_packets_last_heard_index.sql diff --git a/db/migrations/008_packets_last_heard_index.sql b/db/migrations/008_packets_last_heard_index.sql new file mode 100644 index 0000000..f8a4cec --- /dev/null +++ b/db/migrations/008_packets_last_heard_index.sql @@ -0,0 +1,8 @@ +-- 008_packets_last_heard_index.sql +-- +-- The packet list orders by last_heard_at but there was no index on it, so +-- every page seq-scanned and sorted all packets (~2.8s per page on a 1.5M +-- row table; 31ms with the index). Affordable to maintain now that presence +-- coalescing keeps this column from being rewritten on every observation. + +CREATE INDEX idx_packets_last_heard ON packets(last_heard_at DESC);