From 736d21f606ba3dbe0e6bc2a5c6b6265d720ed418 Mon Sep 17 00:00:00 2001 From: Yorgos Saslis Date: Thu, 17 Sep 2026 17:00:34 +0300 Subject: [PATCH] node/db: Index routing by node `sync_routing` calls `get_inventory(&from)` once per inbound inventory announcement, to work out which of a peer's previously-announced repos are no longer in its inventory: // crates/radicle-protocol/src/service.rs synced.removed.extend( self.db.routing().get_inventory(&from)? .into_iter() .filter(|rid| !included.contains(rid)), ); That is `SELECT repo FROM routing WHERE node = ?`. The table's only index is the implicit one for the primary key `(repo, node)`, whose leading column is `repo`, so the lookup cannot use it and scans instead. The index fixes that. --- crates/radicle/src/node/db.rs | 1 + crates/radicle/src/node/db/migrations/10.sql | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 crates/radicle/src/node/db/migrations/10.sql diff --git a/crates/radicle/src/node/db.rs b/crates/radicle/src/node/db.rs index d717ec6fd..5a417b75f 100644 --- a/crates/radicle/src/node/db.rs +++ b/crates/radicle/src/node/db.rs @@ -40,6 +40,7 @@ const MIGRATIONS: &[&str] = &[ include_str!("db/migrations/7.sql"), include_str!("db/migrations/8.sql"), include_str!("db/migrations/9.sql"), + include_str!("db/migrations/10.sql"), ]; #[derive(Error, Debug)] diff --git a/crates/radicle/src/node/db/migrations/10.sql b/crates/radicle/src/node/db/migrations/10.sql new file mode 100644 index 000000000..6fb00e727 --- /dev/null +++ b/crates/radicle/src/node/db/migrations/10.sql @@ -0,0 +1,5 @@ +-- `get_inventory` looks routing entries up by node alone, once per inbound +-- inventory announcement. The table's only index is the implicit one for the +-- primary key `(repo, node)`, whose leading column is `repo`, so that lookup +-- scans -- tens of thousands of rows on a seed following a busy network. +create index if not exists "routing_node" on "routing" ("node");