use LEFT JOIN instead of IN for faster get_block_range_without_filters()

This commit is contained in:
Lex Berezhny 2020-09-21 22:04:50 -04:00
parent d10a88c79b
commit 082a91dc15

View file

@ -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.min(BlockTable.c.height), -1).label('start_height'),
func.coalesce(func.max(BlockTable.c.height), -1).label('end_height'), func.coalesce(func.max(BlockTable.c.height), -1).label('end_height'),
) )
.select_from(BlockTable) .select_from(
.where(BlockTable.c.height.notin_(select(BlockFilter.c.height))) BlockTable.join(BlockFilter, BlockTable.c.height == BlockFilter.c.height, isouter=True)
)
.where(BlockFilter.c.height == None)
) )
result = context().fetchone(sql) result = context().fetchone(sql)
return result['start_height'], result['end_height'] return result['start_height'], result['end_height']