QUERY PLAN
Aggregate (cost=2413.82..2413.83 rows=1 width=8)
-> Sort (cost=2412.91..2413.06 rows=61 width=1104)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2410.79..2411.10 rows=61 width=1104)
Group Key: c.id
-> Sort (cost=2410.79..2410.95 rows=61 width=16)
Sort Key: c.id
-> Hash Left Join (cost=1659.73..2408.98 rows=61 width=16)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Hash Right Join (cost=1658.08..2406.50 rows=61 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=1657.32..1657.32 rows=61 width=20)
-> Hash Right Join (cost=911.02..1657.32 rows=61 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=910.26..910.26 rows=61 width=20)
-> Hash Right Join (cost=168.39..910.26 rows=61 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=167.63..167.63 rows=61 width=20)
-> Hash Join (cost=94.75..167.63 rows=61 width=20)
Hash Cond: (c.client_id = client.id)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..68.32 rows=1732 width=24)
-> 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)
-> Hash (cost=1.64..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)