QUERY PLAN
Aggregate (cost=2304.23..2304.24 rows=1 width=8)
-> Sort (cost=2304.20..2304.21 rows=2 width=1102)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2303.99..2304.19 rows=2 width=1102)
Group Key: c.id
-> Merge Left Join (cost=2303.99..2304.19 rows=2 width=16)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=1565.64..1565.65 rows=2 width=16)
Sort Key: c.id
-> Nested Loop (cost=822.61..1565.63 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 = 982)
-> Hash Right Join (cost=814.31..1555.65 rows=2 width=20)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..736.79 rows=1213 width=4)
Filter: (object_type = 106)
-> Hash (cost=814.28..814.28 rows=2 width=20)
-> Hash Right Join (cost=72.85..814.28 rows=2 width=20)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..736.79 rows=1769 width=4)
Filter: (object_type = 105)
-> Hash (cost=72.83..72.83 rows=2 width=24)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..72.83 rows=2 width=24)
Filter: (client_id = 982)
-> Sort (cost=738.34..738.48 rows=54 width=4)
Sort Key: vs.object_id
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..736.79 rows=54 width=4)
Filter: (object_type = 107)