Add one additional index which postgres prefers as the DB fills
authorMatt Corallo <git@bluematt.me>
Wed, 14 Sep 2022 20:12:17 +0000 (20:12 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 14 Sep 2022 20:18:30 +0000 (20:18 +0000)
If postgres decides walking the full `channel_updates_scid_dir_seen`
index and removing old `seen` values is slower than just walking
the full table (or this new index) it does so. Sadly this causes
re-sorting (usually on-disk), but there doesn't seem to be a way to
avoid this.

src/config.rs

index 3ed4be17f813dc343d28a30bbe2bce5538f540f1..92d33c1c91e88276d4c93d6d5aef8cad4c36fd08 100644 (file)
@@ -79,6 +79,7 @@ pub(crate) fn db_channel_update_table_creation_query() -> &'static str {
 
 pub(crate) fn db_index_creation_query() -> &'static str {
        "
+       CREATE INDEX IF NOT EXISTS channel_updates_seen ON channel_updates(seen, short_channel_id, direction) INCLUDE (id, blob_signed);
        CREATE INDEX IF NOT EXISTS channel_updates_scid_seen ON channel_updates(short_channel_id, seen) INCLUDE (blob_signed);
        CREATE INDEX IF NOT EXISTS channel_updates_seen_scid ON channel_updates(seen, short_channel_id);
        CREATE INDEX IF NOT EXISTS channel_updates_scid_dir_seen ON channel_updates(short_channel_id ASC, direction ASC, seen DESC) INCLUDE (id, blob_signed);