Skip to content

Optimize channel_updates and node_announcements queries, drop unused indexes#106

Open
TheBlueMatt wants to merge 4 commits intolightningdevkit:mainfrom
TheBlueMatt:main
Open

Optimize channel_updates and node_announcements queries, drop unused indexes#106
TheBlueMatt wants to merge 4 commits intolightningdevkit:mainfrom
TheBlueMatt:main

Conversation

@TheBlueMatt
Copy link
Contributor

Rewrite the "oldest bidirectional update" query to use two explicit
LATERAL joins (one per direction, each LIMIT 1) instead of DISTINCT ON
(direction), which scanned ~4000 rows per scid through the index.

Rewrite the node_announcements reference query and channel_updates
reference query to use LATERAL joins instead of DISTINCT ON / subquery
patterns, forcing efficient index usage instead of sequential scans.

Drop four unused/redundant indexes (schema 15 -> 17):
- channel_updates_scid_dir_seen_desc_with_id (unused, backward scan on _asc used instead)
- channel_updates_scid_asc_timestamp_desc (unused by any query)
- channel_updates_seen (redundant with channel_updates_seen_scid)
- node_announcements_seen_pubkey (unused, replaced by _pubkey_seen_desc)
- node_announcements_pubkey_timestamp_desc (unused by any query)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Speeds up queries pretty well. I'm sure to an SQL person these conversions are obvious but I of course don't know SQL.

TheBlueMatt and others added 3 commits March 3, 2026 02:13
…indexes

Rewrite the "oldest bidirectional update" query to use two explicit
LATERAL joins (one per direction, each LIMIT 1) instead of DISTINCT ON
(direction), which scanned ~4000 rows per scid through the index.

Rewrite the node_announcements reference query and channel_updates
reference query to use LATERAL joins instead of DISTINCT ON / subquery
patterns, forcing efficient index usage instead of sequential scans.

Drop four unused/redundant indexes (schema 15 -> 17):
- channel_updates_scid_dir_seen_desc_with_id (unused, backward scan on _asc used instead)
- channel_updates_scid_asc_timestamp_desc (unused by any query)
- channel_updates_seen (redundant with channel_updates_seen_scid)
- node_announcements_seen_pubkey (unused, replaced by _pubkey_seen_desc)
- node_announcements_pubkey_timestamp_desc (unused by any query)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Mar 3, 2026

I've assigned @jkczyz as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@ldk-reviews-bot ldk-reviews-bot requested a review from jkczyz March 3, 2026 14:11
@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 2nd Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 3rd Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 4th Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 5th Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@ldk-reviews-bot
Copy link

🔔 6th Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants