From 082a91dc159b332cf20f876cbfd633108f099297 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Mon, 21 Sep 2020 22:04:50 -0400 Subject: [PATCH] use LEFT JOIN instead of IN for faster get_block_range_without_filters() --- lbry/blockchain/sync/blocks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lbry/blockchain/sync/blocks.py b/lbry/blockchain/sync/blocks.py index ca6b95fdb..b028e7ba1 100644 --- a/lbry/blockchain/sync/blocks.py +++ b/lbry/blockchain/sync/blocks.py @@ -251,8 +251,10 @@ def get_block_range_without_filters() -> Tuple[int, int]: func.coalesce(func.min(BlockTable.c.height), -1).label('start_height'), func.coalesce(func.max(BlockTable.c.height), -1).label('end_height'), ) - .select_from(BlockTable) - .where(BlockTable.c.height.notin_(select(BlockFilter.c.height))) + .select_from( + BlockTable.join(BlockFilter, BlockTable.c.height == BlockFilter.c.height, isouter=True) + ) + .where(BlockFilter.c.height == None) ) result = context().fetchone(sql) return result['start_height'], result['end_height']