QUERY PLAN
Limit (cost=516.43..516.43 rows=2 width=117)
-> Sort (cost=516.43..516.43 rows=2 width=117)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=516.41..516.42 rows=2 width=117)
Group Key: c.id
-> Sort (cost=516.41..516.41 rows=2 width=117)
Sort Key: c.id
-> Nested Loop Left Join (cost=121.50..516.40 rows=2 width=117)
Join Filter: (sgr.sales_id = client.sales_rep)
-> Nested Loop Left Join (cost=121.50..513.40 rows=2 width=121)
-> Nested Loop (cost=121.22..512.39 rows=2 width=121)
-> Index Only Scan using tbl_suppliers_pkey on tbl_suppliers supplier (cost=0.28..8.29 rows=1 width=4)
Index Cond: (id = 431)
-> Hash Right Join (cost=120.95..504.07 rows=2 width=121)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..376.24 rows=1835 width=4)
Filter: (object_type = 108)
-> Hash (cost=120.92..120.92 rows=2 width=121)
-> Hash Right Join (cost=88.45..120.92 rows=2 width=121)
Hash Cond: (pcr.contract_id = c.id)
-> Seq Scan on tbl_purchase_client_rels pcr (cost=0.00..27.79 rows=1779 width=8)
-> Hash (cost=88.42..88.42 rows=2 width=117)
-> Seq Scan on tbl_purchase_contracts c (cost=0.00..88.42 rows=2 width=117)
Filter: (supplier_id = 431)
-> Index Scan using tbl_clients_pkey on tbl_clients client (cost=0.28..0.51 rows=1 width=8)
Index Cond: (pcr.client_id = id)
-> Materialize (cost=0.00..1.71 rows=47 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.47 rows=47 width=4)