Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/codegraph-core/src/db/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,17 @@ const MIGRATIONS: &[Migration] = &[
ALTER TABLE deleted_export_advisories ADD COLUMN consumer_kind TEXT;
"#,
},
Migration {
// dataflow.call_edge_id (added in v18, `REFERENCES edges(id)`) was never
// given its own index — every DELETE FROM edges pays an O(dataflow-rows)
// scan under better-sqlite3, which defaults `PRAGMA foreign_keys = ON`
// (this native/rusqlite connection never sets that pragma, so native
// never paid this cost — WASM-only exposure, see issue #1948).
version: 23,
up: r#"
CREATE INDEX IF NOT EXISTS idx_dataflow_call_edge ON dataflow(call_edge_id);
"#,
},
];

// ── napi types ──────────────────────────────────────────────────────────
Expand Down
17 changes: 17 additions & 0 deletions src/db/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,23 @@ export const MIGRATIONS: Migration[] = [
ALTER TABLE deleted_export_advisories ADD COLUMN consumer_kind TEXT;
`,
},
{
// dataflow.call_edge_id (added in v18, `REFERENCES edges(id)`) was never
// given its own index — every DELETE FROM edges pays an O(dataflow-rows)
// scan under better-sqlite3, which defaults `PRAGMA foreign_keys = ON`
// (rusqlite/native never sets this pragma, so native never paid this
// cost — this is WASM-only exposure, matching issue #1948's report).
// Confirmed via EXPLAIN QUERY PLAN: without this index, deleting a
// single file's edges triggers `SCAN dataflow` for both the explicit
// `dataflowByCallEdge` cleanup query (build-stmts.ts) and SQLite's own
// automatic FK-constraint check; with it, both become an indexed SEARCH.
// Measured on this repo's own ~19.8K-node/~41.8K-edge graph: a 1-file
// incremental purge dropped from 62ms to 1.47ms (97.6% reduction).
version: 23,
up: `
CREATE INDEX IF NOT EXISTS idx_dataflow_call_edge ON dataflow(call_edge_id);
`,
},
];

interface PragmaColumnInfo {
Expand Down
Loading