--- id: add-partial-indexes name: Add Partial Indexes and Call Graph Index Improvements status: completed depends_on: ["add-missing-indexes-identity", "add-missing-indexes-observability", "add-missing-indexes-sessions"] scope: narrow risk: low impact: component level: implementation --- ## Description Four related index/constraint improvements across different domains: 1. **S02**: Add partial indexes for common access patterns — active API keys (`WHERE revoked_at IS NULL AND enabled = true`), connected spokes (`WHERE status = 'connected'`), non-archived sessions, active tasks (`WHERE status IN ('pending', 'in-progress', 'blocked')`). 2. **S04**: Add `accounts.displayName` index for user search/autocomplete UIs. Without it, user search requires full table scans. 3. **S17**: Add `call_graph_nodes.startedAt` index alongside or instead of `createdAt` for p99 latency analysis queries. 4. **S18**: Add unique constraint on `call_graph_edges(sourceId, targetId, edgeType)` to prevent duplicate edges from retries/reconnections. ## Acceptance Criteria - [ ] Partial indexes defined in `table-reference.md` for: active API keys, connected spokes, non-archived sessions, active tasks - [ ] `displayName` index added to accounts table in `identity.md` and `table-reference.md` - [ ] `startedAt` index added to call_graph_nodes in `call-graph.md` and `table-reference.md` - [ ] Unique constraint on `(sourceId, targetId, edgeType)` added to call_graph_edges in `call-graph.md` and `table-reference.md` - [ ] All indexes documented with WHERE clauses/purpose in per-domain docs ## References - docs/reviews/storage-architecture-review-2026-04-21.md#S02 - docs/reviews/storage-architecture-review-2026-04-21.md#S04 - docs/reviews/storage-architecture-review-2026-04-21.md#S17 - docs/reviews/storage-architecture-review-2026-04-21.md#S18 - docs/architecture/storage/table-reference.md - docs/architecture/storage/identity.md - docs/architecture/storage/call-graph.md ## Notes > To be filled by implementation agent ## Summary > To be filled on completion