QUERY PLAN
Aggregate (cost=2308.53..2308.54 rows=1 width=8)
-> Sort (cost=2308.50..2308.50 rows=2 width=1104)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2308.30..2308.49 rows=2 width=1104)
Group Key: c.id
-> Merge Left Join (cost=2308.30..2308.48 rows=2 width=16)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=1568.57..1568.57 rows=2 width=16)
Sort Key: c.id
-> Nested Loop (cost=823.99..1568.56 rows=2 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 = 3459)
-> Hash Right Join (cost=815.68..1558.57 rows=2 width=20)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..738.36 rows=1205 width=4)
Filter: (object_type = 106)
-> Hash (cost=815.66..815.66 rows=2 width=20)
-> Hash Right Join (cost=72.68..815.66 rows=2 width=20)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..738.36 rows=1760 width=4)
Filter: (object_type = 105)
-> Hash (cost=72.65..72.65 rows=2 width=24)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..72.65 rows=2 width=24)
Filter: (client_id = 3459)
-> Sort (cost=739.74..739.86 rows=49 width=4)
Sort Key: vs.object_id
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..738.36 rows=49 width=4)
Filter: (object_type = 107)