QUERY PLAN
Limit (cost=2413.68..2413.71 rows=10 width=211)
-> Sort (cost=2413.68..2413.83 rows=61 width=211)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2408.72..2412.36 rows=61 width=211)
Group Key: c.id
-> Nested Loop Left Join (cost=2408.72..2411.75 rows=61 width=203)
Join Filter: (sgr.sales_id = client.sales_rep)
-> Merge Left Join (cost=2408.72..2409.20 rows=61 width=207)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=1665.67..1665.83 rows=61 width=207)
Sort Key: c.id
-> Hash Right Join (cost=915.45..1663.86 rows=61 width=207)
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=914.69..914.69 rows=61 width=207)
-> Hash Right Join (cost=168.39..914.69 rows=61 width=207)
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=167.63..167.63 rows=61 width=207)
-> Hash Join (cost=94.75..167.63 rows=61 width=207)
Hash Cond: (c.client_id = client.id)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..68.32 rows=1732 width=203)
-> Hash (cost=93.88..93.88 rows=70 width=8)
-> Bitmap Heap Scan on tbl_clients client (cost=4.82..93.88 rows=70 width=8)
Recheck Cond: (sales_rep = 1001)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.80 rows=70 width=0)
Index Cond: (sales_rep = 1001)
-> Sort (cost=743.05..743.17 rows=49 width=4)
Sort Key: vs.object_id
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..741.68 rows=49 width=4)
Filter: (object_type = 107)
-> Materialize (cost=0.00..1.64 rows=1 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.64 rows=1 width=4)
Filter: (sales_id = 1001)