QUERY PLAN
Aggregate (cost=2322.16..2322.17 rows=1 width=8)
-> Sort (cost=2321.53..2321.64 rows=42 width=1104)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2320.19..2320.40 rows=42 width=1104)
Group Key: c.id
-> Sort (cost=2320.19..2320.30 rows=42 width=16)
Sort Key: c.id
-> Nested Loop (cost=1570.72..2319.06 rows=42 width=16)
-> Hash Right Join (cost=8.31..9.96 rows=1 width=4)
Hash Cond: (sgr.sales_id = client.sales_rep)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.51 rows=51 width=4)
-> Hash (cost=8.29..8.29 rows=1 width=8)
-> Index Scan using tbl_clients_pkey on tbl_clients client (cost=0.28..8.29 rows=1 width=8)
Index Cond: (id = 48)
-> Hash Right Join (cost=1562.41..2308.68 rows=42 width=20)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..741.68 rows=1211 width=4)
Filter: (object_type = 106)
-> Hash (cost=1561.88..1561.88 rows=42 width=20)
-> Hash Right Join (cost=820.02..1561.88 rows=42 width=20)
Hash Cond: (vs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..741.68 rows=49 width=4)
Filter: (object_type = 107)
-> Hash (cost=819.49..819.49 rows=42 width=20)
-> Hash Right Join (cost=73.18..819.49 rows=42 width=20)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..741.68 rows=1768 width=4)
Filter: (object_type = 105)
-> Hash (cost=72.65..72.65 rows=42 width=24)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..72.65 rows=42 width=24)
Filter: (client_id = 48)