QUERY PLAN
Aggregate (cost=228.76..228.77 rows=1 width=8)
-> Sort (cost=218.91..220.55 rows=657 width=2812)
Sort Key: (sum(pc.total_amount)) DESC NULLS LAST
-> HashAggregate (cost=179.95..188.16 rows=657 width=2812)
Group Key: s.id
-> Hash Left Join (cost=145.36..176.66 rows=657 width=36)
Hash Cond: (s.id = pc.supplier_id)
-> Seq Scan on tbl_suppliers s (cost=0.00..29.57 rows=657 width=4)
-> Hash (cost=139.54..139.54 rows=465 width=36)
-> Subquery Scan on pc (cost=129.08..139.54 rows=465 width=36)
-> HashAggregate (cost=129.08..134.89 rows=465 width=100)
Group Key: pc_1.supplier_id
-> Seq Scan on tbl_purchase_contracts pc_1 (cost=0.00..117.72 rows=2272 width=10)