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 <noreply@anthropic.com>
This commit is contained in:
2026-03-14 14:24:40 -04:00
parent 85a018ff6c
commit 8f852ed830

View File

@@ -24,7 +24,9 @@ CREATE TABLE IF NOT EXISTS network_events (
INDEX idx_active (resolved_at),
INDEX idx_target (target_name, target_detail),
INDEX idx_type (event_type)
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) ───────────