QUERY PLAN
Limit (cost=1420.03..1420.06 rows=10 width=188)
-> Sort (cost=1420.03..1421.87 rows=737 width=188)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=1392.92..1404.11 rows=737 width=188)
Group Key: c.id
-> Merge Left Join (cost=1392.92..1396.74 rows=737 width=180)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=1015.98..1017.82 rows=737 width=180)
Sort Key: c.id
-> Hash Left Join (cost=590.91..980.88 rows=737 width=180)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Hash Right Join (cost=588.85..972.25 rows=737 width=184)
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=579.64..579.64 rows=737 width=184)
-> Hash Right Join (cost=198.39..579.64 rows=737 width=184)
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=189.18..189.18 rows=737 width=184)
-> Hash Left Join (cost=129.93..189.18 rows=737 width=184)
Hash Cond: (c.client_id = client.id)
Filter: (client.sales_rep IS NULL)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..55.24 rows=1524 width=180)
-> Hash (cost=106.08..106.08 rows=1908 width=8)
-> Seq Scan on tbl_clients client (cost=0.00..106.08 rows=1908 width=8)
-> Hash (cost=1.47..1.47 rows=47 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.47 rows=47 width=4)
-> Sort (cost=376.94..377.01 rows=29 width=4)
Sort Key: vs.object_id
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..376.24 rows=29 width=4)
Filter: (object_type = 107)