swh-dedup=# explain select count(distinct chunk.id) as count_chunk, sum(chunk.length) as total_size, sum(chunk.compressed_length) as total_compressed_size from chunked_content left join chunked_content_chunk on chunked_content_id = chunked_content.id left join chunk on chunk.id = chunked_content_chunk.chunk_id where method_id = 1; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ Aggregate (cost=122093664.99..122093665.00 rows=1 width=24) -> Hash Left Join (cost=50837550.73..121154640.35 rows=125203285 width=29) Hash Cond: ((chunked_content_chunk.chunk_id)::bytea = (chunk.id)::bytea) -> Hash Right Join (cost=673121.09..58595737.23 rows=125203285 width=21) Hash Cond: (chunked_content_chunk.chunked_content_id = chunked_content.id) -> Seq Scan on chunked_content_chunk (cost=0.00..33529227.32 rows=1932149632 width=25) -> Hash (cost=623208.67..623208.67 rows=3992993 width=4) -> Bitmap Heap Scan on chunked_content (cost=58786.26..623208.67 rows=3992993 width=4) Recheck Cond: (method_id = 1) -> Bitmap Index Scan on chunked_content_method_id_idx (cost=0.00..57788.01 rows=3992993 width=0) Index Cond: (method_id = 1) -> Hash (cost=23727028.84..23727028.84 rows=1367267584 width=29) -> Seq Scan on chunk (cost=0.00..23727028.84 rows=1367267584 width=29) (13 rows)