perf: Add tool_id index for 77x faster error queries#64
Conversation
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>
Code ReviewSummaryThis PR adds a migration (v7) to create an index on Issues FoundCriticalNone Important
Suggestions
VerdictREQUEST_CHANGES - The index must be added to Automated review by Claude Code |
Address reviewer feedback: schema elements must be in both migrations AND _init_db() to ensure identical schemas for fresh vs migrated DBs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code ReviewSummaryThis PR adds migration v7 to create an index on Issues FoundCriticalNone ImportantNone Suggestions
def test_index_on_tool_id(self, storage):
"""Verify that idx_events_tool_id index exists."""
rows = storage.execute_query("PRAGMA index_list(events)")
indexes = {row[1] for row in rows}
assert "idx_events_tool_id" in indexesVerdictREQUEST_CHANGES - Minor suggestion for test coverage consistency. Automated review by Claude Code |
Address reviewer suggestion for test coverage consistency. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code ReviewSummaryThis PR adds migration v7 to create an index on Issues FoundCriticalNone ImportantNone SuggestionsNone VerdictAPPROVE - Code looks good, no issues found. The migration is well-documented, the index is correctly added to both Automated review by Claude Code |
Summary
tool_idcolumnget_error_details()query time from 25s to 0.3s (77x faster)Problem
The
query_error_details()function self-joins the events table:Without an index on
tool_id, SQLite was scanning 160K rows. The query plan showed:SCAN e2 USING INDEX idx_events_toolAUTOMATIC PARTIAL COVERING INDEXSolution
Migration v7 adds
idx_events_tool_id:Test plan
make restartRelated: #63 (comprehensive API benchmarking)
🤖 Generated with Claude Code