QUERY PLAN
Aggregate (cost=2088.77..2088.78 rows=1 width=8)
-> Sort (cost=2088.24..2088.33 rows=35 width=1067)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2087.17..2087.34 rows=35 width=1067)
Group Key: c.id
-> Sort (cost=2087.17..2087.26 rows=35 width=16)
Sort Key: c.id
-> Hash Left Join (cost=1436.95..2086.27 rows=35 width=16)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Hash Right Join (cost=1435.33..2084.16 rows=35 width=20)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..642.56 rows=1655 width=4)
Filter: (object_type = 105)
-> Hash (cost=1434.89..1434.89 rows=35 width=20)
-> Hash Right Join (cost=787.98..1434.89 rows=35 width=20)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..642.56 rows=1146 width=4)
Filter: (object_type = 106)
-> Hash (cost=787.54..787.54 rows=35 width=20)
-> Hash Right Join (cost=144.81..787.54 rows=35 width=20)
Hash Cond: (vs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..642.56 rows=43 width=4)
Filter: (object_type = 107)
-> Hash (cost=144.37..144.37 rows=35 width=20)
-> Hash Join (cost=76.26..144.37 rows=35 width=20)
Hash Cond: (c.client_id = client.id)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..63.71 rows=1671 width=24)
-> Hash (cost=75.76..75.76 rows=40 width=8)
-> Bitmap Heap Scan on tbl_clients client (cost=4.59..75.76 rows=40 width=8)
Recheck Cond: (sales_rep = 5087)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.58 rows=40 width=0)
Index Cond: (sales_rep = 5087)
-> Hash (cost=1.61..1.61 rows=1 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.61 rows=1 width=4)
Filter: (sales_id = 5087)