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.
This commit is contained in:
Yorgos Saslis
2026-10-08 12:21:20 +02:00
committed by Lorenz Leutgeb
parent 2f930e3561
commit 736d21f606
2 changed files with 6 additions and 0 deletions
+1
View File
@@ -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)]
@@ -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");