QUERY PLAN
Limit (cost=1206.68..1206.69 rows=2 width=188)
-> Sort (cost=1206.68..1206.69 rows=2 width=188)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=1204.90..1206.67 rows=2 width=188)
Group Key: c.id
-> Nested Loop (cost=1204.90..1206.65 rows=2 width=180)
-> Merge Left Join (cost=1196.59..1196.71 rows=2 width=180)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=819.65..819.66 rows=2 width=180)
Sort Key: c.id
-> Hash Right Join (cost=439.37..819.64 rows=2 width=180)
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=439.34..439.34 rows=2 width=180)
-> Hash Right Join (cost=59.07..439.34 rows=2 width=180)
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=59.05..59.05 rows=2 width=180)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..59.05 rows=2 width=180)
Filter: (client_id = 3304)
-> 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)
-> Materialize (cost=8.31..9.92 rows=1 width=4)
-> Hash Right Join (cost=8.31..9.91 rows=1 width=4)
Hash Cond: (sgr.sales_id = client.sales_rep)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.47 rows=47 width=4)
-> Hash (cost=8.29..8.29 rows=1 width=8)
-> Index Scan using tbl_clients_pkey on tbl_clients client (cost=0.28..8.29 rows=1 width=8)
Index Cond: (id = 3304)