From 3eed2f94c1a5fb29a8fc5cca5175bd1988289a4a Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Thu, 24 Jul 2025 13:41:43 +0200 Subject: [PATCH] sqldb/sqlc: add index on graph_channels(version, id) This new index greatly improves the speed of the ListChannelsWithPoliciesPaginated query. --- sqldb/sqlc/migrations/000007_graph.down.sql | 1 + sqldb/sqlc/migrations/000007_graph.up.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/sqldb/sqlc/migrations/000007_graph.down.sql b/sqldb/sqlc/migrations/000007_graph.down.sql index da92ccf22..b23ced950 100644 --- a/sqldb/sqlc/migrations/000007_graph.down.sql +++ b/sqldb/sqlc/migrations/000007_graph.down.sql @@ -9,6 +9,7 @@ DROP INDEX IF EXISTS graph_channels_node_id_1_idx; DROP INDEX IF EXISTS graph_channels_node_id_2_idx; DROP INDEX IF EXISTS graph_channels_unique; DROP INDEX IF EXISTS graph_channels_version_outpoint_idx; +DROP INDEX IF EXISTS graph_channels_version_id_idx; DROP INDEX IF EXISTS graph_channel_features_unique; DROP INDEX IF EXISTS graph_channel_extra_types_unique; DROP INDEX IF EXISTS graph_channel_policies_unique; diff --git a/sqldb/sqlc/migrations/000007_graph.up.sql b/sqldb/sqlc/migrations/000007_graph.up.sql index c1c69058c..1cb21be78 100644 --- a/sqldb/sqlc/migrations/000007_graph.up.sql +++ b/sqldb/sqlc/migrations/000007_graph.up.sql @@ -173,6 +173,7 @@ CREATE TABLE IF NOT EXISTS graph_channels ( -- indexes on the node_id_1 and node_id_2 columns. CREATE INDEX IF NOT EXISTS graph_channels_node_id_1_idx ON graph_channels(node_id_1); CREATE INDEX IF NOT EXISTS graph_channels_node_id_2_idx ON graph_channels(node_id_2); +CREATE INDEX IF NOT EXISTS graph_channels_version_id_idx ON graph_channels(version, id); -- A channel (identified by a short channel id) can only have one active -- channel announcement per protocol version. We also order the index by