Skip to content

perf(db): drop redundant idx_edges_source / idx_edges_target#142

Merged
colbymchenry merged 1 commit into
mainfrom
perf/drop-narrow-edge-indexes
May 8, 2026
Merged

perf(db): drop redundant idx_edges_source / idx_edges_target#142
colbymchenry merged 1 commit into
mainfrom
perf/drop-narrow-edge-indexes

Conversation

@colbymchenry
Copy link
Copy Markdown
Owner

Summary

  • Drops two narrow edge indexes (idx_edges_source, idx_edges_target) that are fully covered by the existing (source, kind) and (target, kind) composites via SQLite's left-prefix scan.
  • Adds migration v4 (CURRENT_SCHEMA_VERSION 3 → 4) to drop them on existing databases; fresh-DB schema no longer creates them.

Salvaged from #122, which bundled the same fix with the unmerged file-based migrations refactor. This is the standalone, inline-migration version.

Why it's safe

Query shape Old plan New plan
WHERE source = ? idx_edges_source idx_edges_source_kind (left-prefix, covering)
WHERE target = ? idx_edges_target idx_edges_target_kind (left-prefix, covering)
WHERE source = ? AND kind = ? idx_edges_source_kind unchanged
WHERE target = ? AND kind = ? idx_edges_target_kind unchanged

Empirical numbers (from #122's spike on 50K-node / 250K-edge DB)

  • DB size: 34.7 MB → 27.0 MB (-22.2%)
  • Bulk insert (250K edges): 590ms → 431ms (1.37× faster)
  • source/target lookup latency: no regression

Test plan

  • npx tsc --noEmit clean
  • npm test — 416/416 pass
  • Updated schema-version expectation in foundation.test.ts and pr19-improvements.test.ts

🤖 Generated with Claude Code

Both narrow indexes are fully covered by the existing (source, kind)
and (target, kind) composites via SQLite's left-prefix scan, so
they're dead weight on every write. Empirical measurements (from the
spike script in PR #122 on a 50K-node / 250K-edge synthetic DB):

  - DB size: 34.7 MB → 27.0 MB (-22.2%)
  - Bulk insert (250K edges): 590ms → 431ms (1.37× faster)
  - source/target lookup latency: no regression

Adds migration v4 to drop both on existing databases; fresh-DB schema
no longer creates them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@colbymchenry colbymchenry merged commit a460b85 into main May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant