QUERY PLAN
Limit (cost=1207.12..1207.14 rows=7 width=188)
-> Sort (cost=1207.12..1207.14 rows=7 width=188)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=1205.11..1207.02 rows=7 width=188)
Group Key: c.id
-> Nested Loop (cost=1205.11..1206.95 rows=7 width=180)
-> Merge Left Join (cost=1196.81..1196.95 rows=7 width=180)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=819.87..819.88 rows=7 width=180)
Sort Key: c.id
-> Hash Right Join (cost=439.49..819.77 rows=7 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.40..439.40 rows=7 width=180)
-> Hash Right Join (cost=59.14..439.40 rows=7 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=7 width=180)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..59.05 rows=7 width=180)
Filter: (client_id = 2094)
-> 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 = 2094)