select _blog.id, count(_comment.id) from _comment left join _blog on _comment.path <@ _blog.path where extract (day from localtimestamp-_comment.date_publishing) < 30 group by _blog.id QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=1271138177.25..1274205098.25 rows=245483 width=16) -> Sort (cost=1271138177.25..1272159461.41 rows=408513661 width=16) Sort Key: _blog.id -> Nested Loop Left Join (cost=5.86..1177206898.28 rows=408513661 width=16) -> Seq Scan on _comment (cost=0.00..452365.30 rows=1664122 width=40) Filter: (date_part('day'::text, (('now'::text)::timestamp without time zone - date_publishing)) < 30::double precision) -> Bitmap Heap Scan on _blog (cost=5.86..704.07 rows=245 width=40) Recheck Cond: ("outer".path <@ _blog.path) -> Bitmap Index Scan on gist_idx_blog_path (cost=0.00..5.86 rows=245 width=0) Index Cond: ("outer".path <@ _blog.path) (10 rows)