perf: Add composite index on dependencies(depends_on_id, type)

The hierarchical blocking query recursively joins on dependencies with
a type filter. Without a composite index, SQLite must scan all
dependencies for a given depends_on_id and filter by type afterward.

With 10k+ issues and many dependencies per issue, this could cause
noticeable slowdowns in ready work calculations.

Changes:
- Added idx_dependencies_depends_on_type composite index to schema
- Added automatic migration for existing databases
- Index creation is silent and requires no user intervention

The recursive CTE now efficiently seeks (depends_on_id, type) pairs
directly instead of post-filtering.

Resolves: bd-59

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-10-14 13:02:22 -07:00
parent f6a75415a5
commit 1dd3109489
2 changed files with 36 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ CREATE TABLE IF NOT EXISTS dependencies (
CREATE INDEX IF NOT EXISTS idx_dependencies_issue ON dependencies(issue_id);
CREATE INDEX IF NOT EXISTS idx_dependencies_depends_on ON dependencies(depends_on_id);
CREATE INDEX IF NOT EXISTS idx_dependencies_depends_on_type ON dependencies(depends_on_id, type);
-- Labels table
CREATE TABLE IF NOT EXISTS labels (