QUERY PLAN
Aggregate (cost=172.68..172.69 rows=1 width=8)
-> Sort (cost=163.14..164.73 rows=636 width=2812)
Sort Key: (sum(pc.total_amount)) DESC NULLS LAST
-> HashAggregate (cost=125.57..133.52 rows=636 width=2812)
Group Key: s.id
-> Hash Left Join (cost=91.35..122.39 rows=636 width=36)
Hash Cond: (s.id = pc.supplier_id)
-> Seq Scan on tbl_suppliers s (cost=0.00..29.36 rows=636 width=4)
-> Hash (cost=85.81..85.81 rows=443 width=36)
-> Subquery Scan on pc (cost=75.85..85.81 rows=443 width=36)
-> HashAggregate (cost=75.85..81.38 rows=443 width=100)
Group Key: pc_1.supplier_id
-> Seq Scan on tbl_purchase_contracts pc_1 (cost=0.00..65.23 rows=2123 width=10)