QUERY PLAN
Limit (cost=2354.31..2354.32 rows=6 width=211)
-> Sort (cost=2354.31..2354.32 rows=6 width=211)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=2352.22..2354.23 rows=6 width=211)
Group Key: c.id
-> Nested Loop (cost=2352.22..2354.17 rows=6 width=203)
-> Merge Left Join (cost=2343.91..2344.13 rows=6 width=203)
Merge Cond: (c.id = vs.object_id)
-> Sort (cost=1605.57..1605.58 rows=6 width=203)
Sort Key: c.id
-> Hash Right Join (cost=864.14..1605.49 rows=6 width=203)
Hash Cond: (rs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships rs (cost=0.00..736.79 rows=1213 width=4)
Filter: (object_type = 106)
-> Hash (cost=864.07..864.07 rows=6 width=203)
-> Hash Right Join (cost=122.64..864.07 rows=6 width=203)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..736.79 rows=1769 width=4)
Filter: (object_type = 105)
-> Hash (cost=122.56..122.56 rows=6 width=203)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..122.56 rows=6 width=203)
Filter: (client_id = 982)
-> Sort (cost=738.34..738.48 rows=54 width=4)
Sort Key: vs.object_id
-> Seq Scan on tbl_attachement_relationships vs (cost=0.00..736.79 rows=54 width=4)
Filter: (object_type = 107)
-> Materialize (cost=8.31..9.97 rows=1 width=4)
-> Hash Right Join (cost=8.31..9.96 rows=1 width=4)
Hash Cond: (sgr.sales_id = client.sales_rep)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.51 rows=51 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 = 982)