foo=# explain analyze select count(*) from c where tab_id = 2; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=2014181.55..2014181.56 rows=1 width=0) (actual time=524.034..524.035 rows=1 loops=1) -> Hash Join (cost=2316.92..2014180.53 rows=407 width=0) (actual time=436.223..524.026 rows=1 loops=1) Hash Cond: (item.id = folder.id) -> Hash Join (cost=2311.61..2013055.97 rows=81398 width=1313) (actual time=51.783..508.441 rows=81398 loops=1) Hash Cond: (perms.owner_id = "user".id) -> Hash Join (cost=2310.45..5678.39 rows=81398 width=1281) (actual time=50.485..204.430 rows=81398 loops=1) Hash Cond: (perms.item_id = item.id) -> Seq Scan on perms (cost=0.00..1332.98 rows=81398 width=17) (actual time=0.041..37.544 rows=81398 loops=1) Filter: (NOT deleted) -> Hash (cost=1292.98..1292.98 rows=81398 width=1272) (actual time=50.389..50.389 rows=81398 loops=1) -> Seq Scan on item (cost=0.00..1292.98 rows=81398 width=1272) (actual time=0.038..22.298 rows=81398 loops=1) -> Hash (cost=1.07..1.07 rows=7 width=40) (actual time=0.017..0.017 rows=7 loops=1) -> Seq Scan on "user" (cost=0.00..1.07 rows=7 width=40) (actual time=0.013..0.014 rows=7 loops=1) SubPlan 1 -> Aggregate (cost=24.39..24.40 rows=1 width=0) (never executed) -> Seq Scan on comments (cost=0.00..24.38 rows=3 width=0) (never executed) Filter: (read AND (item_id = $0)) -> Hash (cost=5.29..5.29 rows=1 width=16) (actual time=0.157..0.157 rows=1 loops=1) -> Nested Loop (cost=0.00..5.29 rows=1 width=16) (actual time=0.152..0.154 rows=1 loops=1) -> Seq Scan on collection (cost=0.00..1.01 rows=1 width=8) (actual time=0.023..0.024 rows=1 loops=1) Filter: (tab_id = 2) -> Index Scan using folder_pkey on folder (cost=0.00..4.27 rows=1 width=8) (actual time=0.125..0.126 rows=1 loops=1) Index Cond: (folder.id = collection.id) Total runtime: 525.447 ms (24 rows)