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.
This commit is contained in:
2 files changed
+16
-2
No files matched your search
@@ -2653,7 +2653,7 @@ const isPublicV1Node = `-- name: IsPublicV1Node :one
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM graph_channels c
|
||||
JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
|
||||
JOIN graph_nodes n ON n.id = c.node_id_1
|
||||
-- NOTE: we hard-code the version here since the clauses
|
||||
-- here that determine if a node is public is specific
|
||||
-- to the V1 gossip protocol. In V1, a node is public
|
||||
@@ -2665,6 +2665,13 @@ SELECT EXISTS (
|
||||
WHERE c.version = 1
|
||||
AND c.bitcoin_1_signature IS NOT NULL
|
||||
AND n.pub_key = $1
|
||||
UNION ALL
|
||||
SELECT 1
|
||||
FROM graph_channels c
|
||||
JOIN graph_nodes n ON n.id = c.node_id_2
|
||||
WHERE c.version = 1
|
||||
AND c.bitcoin_1_signature IS NOT NULL
|
||||
AND n.pub_key = $1
|
||||
)
|
||||
`
|
||||
|
||||
|
||||
Reference in new issue
Block a user