QUERY PLAN
Limit (cost=1196.72..1196.72 rows=2 width=188)
-> Sort (cost=1196.72..1196.72 rows=2 width=188)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=1194.93..1196.71 rows=2 width=188)
Group Key: c.id
-> Nested Loop (cost=1194.93..1196.69 rows=2 width=180)
-> Merge Left Join (cost=1186.63..1186.75 rows=2 width=180)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=812.98..812.99 rows=2 width=180)
Sort Key: c.id
-> Hash Right Join (cost=436.03..812.97 rows=2 width=180)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..372.94 rows=1065 width=4)
Filter: (object_type = 106)
-> Hash (cost=436.01..436.01 rows=2 width=180)
-> Hash Right Join (cost=59.07..436.01 rows=2 width=180)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..372.94 rows=1522 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=373.64..373.71 rows=29 width=4)
Sort Key: vs.object_id
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..372.94 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)