From 8f852ed8308ece5b2f3d29eb29f8f359c3d1c3f4 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sat, 14 Mar 2026 14:24:40 -0400 Subject: [PATCH] Add compound DB indexes for hot query paths network_events: idx_event_lookup (event_type, target_name, target_detail, resolved_at) - Covers the upsert_event SELECT which runs every cycle per monitored entity - Replaces three separate single-column index scans with one covering lookup suppression_rules: idx_sup_lookup (active, target_type, target_name, target_detail) - Covers is_suppressed() queries (now redundant for runtime due to in-memory check_suppressed, but ensures fast get_active_suppressions() loading per cycle) Both indexes created on live DB (MariaDB LXC 149). Co-Authored-By: Claude Sonnet 4.6 --- schema.sql | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/schema.sql b/schema.sql index d663361..6248a98 100644 --- a/schema.sql +++ b/schema.sql @@ -22,9 +22,11 @@ CREATE TABLE IF NOT EXISTS network_events ( consecutive_failures INT NOT NULL DEFAULT 1, ticket_id VARCHAR(20) NULL, - INDEX idx_active (resolved_at), - INDEX idx_target (target_name, target_detail), - INDEX idx_type (event_type) + INDEX idx_active (resolved_at), + INDEX idx_target (target_name, target_detail), + INDEX idx_type (event_type), + -- Compound index for hot upsert_event lookup: event_type+target+resolved_at + INDEX idx_event_lookup (event_type, target_name, target_detail, resolved_at) ) ENGINE=InnoDB; -- ── Suppression rules ───────────────────────────────────────────────── @@ -39,7 +41,9 @@ CREATE TABLE IF NOT EXISTS suppression_rules ( expires_at TIMESTAMP NULL, -- NULL = manual (never auto-expires) active BOOLEAN NOT NULL DEFAULT TRUE, - INDEX idx_active_exp (active, expires_at) + INDEX idx_active_exp (active, expires_at), + -- For suppression lookup by type+name + INDEX idx_sup_lookup (active, target_type, target_name, target_detail) ) ENGINE=InnoDB; -- ── Monitor state (key/value store for snapshot + baseline) ───────────