From: Matt Corallo Date: Tue, 13 Sep 2022 15:48:31 +0000 (+0000) Subject: Drop unused columns from SELECT queries X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=f34b558ce34b979f6313f1152defffebdecad0c1;p=rapid-gossip-sync-server Drop unused columns from SELECT queries --- diff --git a/src/lookup.rs b/src/lookup.rs index 0da340d..b48b375 100644 --- a/src/lookup.rs +++ b/src/lookup.rs @@ -79,7 +79,7 @@ pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, networ println!("Obtaining corresponding database entries"); // get all the channel announcements that are currently in the network graph - let announcement_rows = client.query("SELECT short_channel_id, announcement_signed, seen FROM channel_announcements WHERE short_channel_id = any($1) ORDER BY short_channel_id ASC", &[&channel_ids]).await.unwrap(); + let announcement_rows = client.query("SELECT announcement_signed, seen FROM channel_announcements WHERE short_channel_id = any($1) ORDER BY short_channel_id ASC", &[&channel_ids]).await.unwrap(); for current_announcement_row in announcement_rows { let blob: Vec = current_announcement_row.get("announcement_signed"); @@ -101,7 +101,7 @@ pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaSet, networ // here is where the channels whose first update in either direction occurred after // `last_seen_timestamp` are added to the selection - let unannounced_rows = client.query("SELECT short_channel_id, blob_signed, seen FROM (SELECT DISTINCT ON (short_channel_id) short_channel_id, blob_signed, seen FROM channel_updates ORDER BY short_channel_id ASC, seen ASC) AS first_seens WHERE first_seens.seen >= $1", &[&last_sync_timestamp_object]).await.unwrap(); + let unannounced_rows = client.query("SELECT blob_signed, seen FROM (SELECT DISTINCT ON (short_channel_id) short_channel_id, blob_signed, seen FROM channel_updates ORDER BY short_channel_id ASC, seen ASC) AS first_seens WHERE first_seens.seen >= $1", &[&last_sync_timestamp_object]).await.unwrap(); for current_row in unannounced_rows { let blob: Vec = current_row.get("blob_signed"); @@ -123,7 +123,7 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, client: &Cli // get the latest channel update in each direction prior to last_sync_timestamp, provided // there was an update in either direction that happened after the last sync (to avoid // collecting too many reference updates) - let reference_rows = client.query("SELECT DISTINCT ON (short_channel_id, direction) id, short_channel_id, direction, blob_signed FROM channel_updates WHERE seen < $1 AND short_channel_id IN (SELECT short_channel_id FROM channel_updates WHERE seen >= $1 GROUP BY short_channel_id) ORDER BY short_channel_id ASC, direction ASC, seen DESC", &[&last_sync_timestamp_object]).await.unwrap(); + let reference_rows = client.query("SELECT DISTINCT ON (short_channel_id, direction) id, direction, blob_signed FROM channel_updates WHERE seen < $1 AND short_channel_id IN (SELECT short_channel_id FROM channel_updates WHERE seen >= $1 GROUP BY short_channel_id) ORDER BY short_channel_id ASC, direction ASC, seen DESC", &[&last_sync_timestamp_object]).await.unwrap(); println!("Fetched reference rows ({}): {:?}", reference_rows.len(), start.elapsed()); @@ -161,7 +161,7 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, client: &Cli intermediate_update_prefix = "DISTINCT ON (short_channel_id, direction)"; } - let query_string = format!("SELECT {} id, short_channel_id, direction, blob_signed, seen FROM channel_updates WHERE seen >= $1 ORDER BY short_channel_id ASC, direction ASC, seen DESC", intermediate_update_prefix); + let query_string = format!("SELECT {} id, direction, blob_signed, seen FROM channel_updates WHERE seen >= $1 ORDER BY short_channel_id ASC, direction ASC, seen DESC", intermediate_update_prefix); let intermediate_updates = client.query(&query_string, &[&last_sync_timestamp_object]).await.unwrap(); println!("Fetched intermediate rows ({}): {:?}", intermediate_updates.len(), start.elapsed());