QUERY PLAN
Aggregate (cost=1291.17..1291.18 rows=1 width=8)
-> Sort (cost=1290.51..1290.62 rows=44 width=998)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=1289.09..1289.31 rows=44 width=998)
Group Key: c.id
-> Sort (cost=1289.09..1289.20 rows=44 width=16)
Sort Key: c.id
-> Hash Left Join (cost=905.21..1287.89 rows=44 width=16)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Hash Right Join (cost=903.61..1285.68 rows=44 width=20)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..376.24 rows=1535 width=4)
Filter: (object_type = 105)
-> Hash (cost=903.06..903.06 rows=44 width=20)
-> Hash Right Join (cost=522.73..903.06 rows=44 width=20)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..376.24 rows=1074 width=4)
Filter: (object_type = 106)
-> Hash (cost=522.18..522.18 rows=44 width=20)
-> Hash Right Join (cost=145.83..522.18 rows=44 width=20)
Hash Cond: (vs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..376.24 rows=29 width=4)
Filter: (object_type = 107)
-> Hash (cost=145.28..145.28 rows=44 width=20)
-> Hash Join (cost=86.03..145.28 rows=44 width=20)
Hash Cond: (c.client_id = client.id)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..55.24 rows=1524 width=24)
-> Hash (cost=85.34..85.34 rows=55 width=8)
-> Bitmap Heap Scan on tbl_clients client (cost=4.70..85.34 rows=55 width=8)
Recheck Cond: (sales_rep = 1001)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.69 rows=55 width=0)
Index Cond: (sales_rep = 1001)
-> Hash (cost=1.59..1.59 rows=1 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.59 rows=1 width=4)
Filter: (sales_id = 1001)