Skip to content

Commit d849ec5

Browse files
evansenterclaude
andcommitted
perf: Add tool_id index for 77x faster error queries
get_error_details() was taking 25s on 160K events due to self-join on tool_id without an index. Migration v7 adds idx_events_tool_id, reducing query time to 0.3s. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 440e3d0 commit d849ec5

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎src/session_analytics/storage.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class BusEvent:
166166
DEFAULT_DB_PATH = Path.home() / ".claude" / "contrib" / "analytics" / "data.db"
167167

168168
# Schema version for migrations
169-
SCHEMA_VERSION = 6
169+
SCHEMA_VERSION = 7
170170

171171
# Migration functions: dict of version -> (migration_name, migration_func)
172172
# Each migration upgrades FROM version-1 TO version
@@ -379,6 +379,17 @@ def migrate_v6(conn):
379379
conn.execute("CREATE INDEX IF NOT EXISTS idx_bus_events_repo ON bus_events(repo)")
380380

381381

382+
@migration(7, "add_tool_id_index")
383+
def migrate_v7(conn):
384+
"""Add index on tool_id for faster self-joins.
385+
386+
The query_error_details() function joins events to itself on tool_id
387+
to correlate tool_result errors with their tool_use parameters.
388+
Without this index, queries took ~25s on 160K events.
389+
"""
390+
conn.execute("CREATE INDEX IF NOT EXISTS idx_events_tool_id ON events(tool_id)")
391+
392+
382393
class SQLiteStorage:
383394
"""SQLite-backed storage for session analytics."""
384395

0 commit comments

Comments
 (0)