From 11516f3cc34ddb5d6809c93d593ffb53c5a421ff Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Tue, 7 Jul 2026 14:33:01 +0530 Subject: [PATCH] perf: partial index so the startup NULL-active repair skips the table scan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review finding: EXPLAIN QUERY PLAN showed the unconditional repair UPDATE doing SCAN messages (~75-135ms on 500k rows, every startup) — the existing idx_messages_session_active can't serve an active-only predicate. A partial index on (active) WHERE active IS NULL costs near-zero storage on healthy DBs (no NULL rows) and drops the 0-match repair to ~0.04ms. Lives in DEFERRED_INDEX_SQL because it references the reconciler-added column. --- hermes_state.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hermes_state.py b/hermes_state.py index 6e1300f5de4..3702623aac4 100644 --- a/hermes_state.py +++ b/hermes_state.py @@ -802,6 +802,8 @@ CREATE INDEX IF NOT EXISTS idx_compression_locks_expires ON compression_locks(ex DEFERRED_INDEX_SQL = """ CREATE INDEX IF NOT EXISTS idx_messages_session_active ON messages(session_id, active, timestamp); +CREATE INDEX IF NOT EXISTS idx_messages_active_null + ON messages(active) WHERE active IS NULL; CREATE INDEX IF NOT EXISTS idx_sessions_session_key ON sessions(session_key, started_at DESC); CREATE INDEX IF NOT EXISTS idx_sessions_gateway_peer