QUERY PLAN
Aggregate (cost=1286.50..1286.51 rows=1 width=8)
-> Sort (cost=1285.91..1286.01 rows=39 width=998)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=1284.69..1284.88 rows=39 width=998)
Group Key: c.id
-> Sort (cost=1284.69..1284.78 rows=39 width=16)
Sort Key: c.id
-> Hash Left Join (cost=901.06..1283.66 rows=39 width=16)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Hash Right Join (cost=899.46..1281.52 rows=39 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=898.97..898.97 rows=39 width=20)
-> Hash Right Join (cost=518.65..898.97 rows=39 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=518.17..518.17 rows=39 width=20)
-> Hash Right Join (cost=141.81..518.17 rows=39 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=141.32..141.32 rows=39 width=20)
-> Hash Join (cost=82.07..141.32 rows=39 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=81.47..81.47 rows=48 width=8)
-> Bitmap Heap Scan on tbl_clients client (cost=4.65..81.47 rows=48 width=8)
Recheck Cond: (sales_rep = 5329)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.64 rows=48 width=0)
Index Cond: (sales_rep = 5329)
-> 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 = 5329)