Skip to content

Commit e1ad5fd

Browse files
committed
graph: use UNION for isPublicNode query
In this commit we updated the IsPublicV1Node query to use UNION instead of OR, since sqlite struggles to efficiently use multiple indexes in a single query involving OR conditions across different columns. We use UNION ALL since the query doesn't care about duplicates.
1 parent 0a2e025 commit e1ad5fd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

sqldb/sqlc/graph.sql.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/queries/graph.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ LIMIT $3;
5656
SELECT EXISTS (
5757
SELECT 1
5858
FROM graph_channels c
59-
JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
59+
JOIN graph_nodes n ON n.id = c.node_id_1
6060
-- NOTE: we hard-code the version here since the clauses
6161
-- here that determine if a node is public is specific
6262
-- to the V1 gossip protocol. In V1, a node is public
@@ -68,6 +68,13 @@ SELECT EXISTS (
6868
WHERE c.version = 1
6969
AND c.bitcoin_1_signature IS NOT NULL
7070
AND n.pub_key = $1
71+
UNION ALL
72+
SELECT 1
73+
FROM graph_channels c
74+
JOIN graph_nodes n ON n.id = c.node_id_2
75+
WHERE c.version = 1
76+
AND c.bitcoin_1_signature IS NOT NULL
77+
AND n.pub_key = $1
7178
);
7279

7380
-- name: DeleteUnconnectedNodes :many

0 commit comments

Comments
 (0)