From 6aa29333790a542b2004f532d15686fdfa4a01cc Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 20 Jun 2025 14:47:57 +0200 Subject: [PATCH] sqldb: add index on node & chan policy last_update columns So that we can have efficient lookups during the "*UpdatesInHorizon" calls. --- sqldb/sqlc/migrations/000007_graph.down.sql | 2 ++ sqldb/sqlc/migrations/000007_graph.up.sql | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sqldb/sqlc/migrations/000007_graph.down.sql b/sqldb/sqlc/migrations/000007_graph.down.sql index 5b42a3a9b..0990705ef 100644 --- a/sqldb/sqlc/migrations/000007_graph.down.sql +++ b/sqldb/sqlc/migrations/000007_graph.down.sql @@ -3,6 +3,7 @@ DROP INDEX IF EXISTS nodes_unique; DROP INDEX IF EXISTS node_extra_types_unique; DROP INDEX IF EXISTS node_features_unique; DROP INDEX IF EXISTS node_addresses_unique; +DROP INDEX IF EXISTS node_last_update_idx; DROP INDEX IF EXISTS source_nodes_unique; DROP INDEX IF EXISTS channels_node_id_1_idx; DROP INDEX IF EXISTS channels_node_id_2_idx; @@ -12,6 +13,7 @@ DROP INDEX IF EXISTS channel_features_unique; DROP INDEX IF EXISTS channel_extra_types_unique; DROP INDEX IF EXISTS channel_policies_unique; DROP INDEX IF EXISTS channel_policy_extra_types_unique; +DROP INDEX IF EXISTS channel_policy_last_update_idx; -- Drop tables in order of reverse dependencies. DROP TABLE IF EXISTS channel_policy_extra_types; diff --git a/sqldb/sqlc/migrations/000007_graph.up.sql b/sqldb/sqlc/migrations/000007_graph.up.sql index b52dd4508..0d179f1d3 100644 --- a/sqldb/sqlc/migrations/000007_graph.up.sql +++ b/sqldb/sqlc/migrations/000007_graph.up.sql @@ -37,6 +37,7 @@ CREATE TABLE IF NOT EXISTS nodes ( CREATE UNIQUE INDEX IF NOT EXISTS nodes_unique ON nodes ( pub_key, version ); +CREATE INDEX IF NOT EXISTS node_last_update_idx ON nodes(last_update); -- node_extra_types stores any extra TLV fields covered by a node announcement that -- we do not have an explicit column for in the nodes table. @@ -273,6 +274,7 @@ CREATE TABLE IF NOT EXISTS channel_policies ( CREATE UNIQUE INDEX IF NOT EXISTS channel_policies_unique ON channel_policies ( channel_id, node_id, version ); +CREATE INDEX IF NOT EXISTS channel_policy_last_update_idx ON channel_policies(last_update); -- channel_policy_extra_types stores any extra TLV fields covered by a channel -- update that we do not have an explicit column for in the channel_policies