core: index-only counts and search positions
The sidebar's per-session counts and the search page's match positions ran
over the message heap: rows are wide (content, thinking) and the session
index has no is_display, so every counted row cost a heap fetch. A covering
index on (session_id, sequence_number) INCLUDE (is_display) turns both into
index-only scans.

The match query now numbers positions over that projection and reads content
only for the rows the trigram index returns, instead of numbering every
display row together with its content. On prod (1.3k sessions, 77k messages)
a common term across the largest sessions went from ~1.7 s to ~0.1 s, and the
summary aggregate from ~0.5 s to the index.
1 parent 3ace99d commit fa89d4babdc5890ccb20e44870fc3dd054412bd3
@Eugene Sukhodolskiy Eugene Sukhodolskiy authored 7 hours ago
Showing 5 changed files
View
docs/sessions.md
View
navi/core/sessions/ddl.py
View
navi/core/sessions/rows.py
View
tests/unit/core/test_pg_session_store.py
View
tests/unit/core/test_session_list_summaries.py