QUERY PLAN
Limit (cost=2123.86..2123.89 rows=10 width=207)
-> Sort (cost=2123.86..2123.90 rows=14 width=207)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2121.43..2123.59 rows=14 width=207)
Group Key: c.id
-> Nested Loop (cost=2121.43..2123.45 rows=14 width=199)
-> Merge Left Join (cost=2113.13..2113.35 rows=14 width=199)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=1433.91..1433.95 rows=14 width=199)
Sort Key: c.id
-> Hash Right Join (cost=751.25..1433.65 rows=14 width=199)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..678.01 rows=1164 width=4)
Filter: (object_type = 106)
-> Hash (cost=751.07..751.07 rows=14 width=199)
-> Hash Right Join (cost=68.64..751.07 rows=14 width=199)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..678.01 rows=1685 width=4)
Filter: (object_type = 105)
-> Hash (cost=68.46..68.46 rows=14 width=199)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..68.46 rows=14 width=199)
Filter: (client_id = 518)
-> Sort (cost=679.21..679.32 rows=44 width=4)
Sort Key: vs.object_id
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..678.01 rows=44 width=4)
Filter: (object_type = 107)
-> Materialize (cost=8.31..9.93 rows=1 width=4)
-> Hash Right Join (cost=8.31..9.93 rows=1 width=4)
Hash Cond: (sgr.sales_id = client.sales_rep)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.49 rows=49 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 = 518)