QUERY PLAN
Aggregate (cost=181.82..181.83 rows=1 width=8)
-> Sort (cost=171.97..173.61 rows=657 width=2812)
Sort Key: (sum(pc.total_amount)) DESC NULLS LAST
-> HashAggregate (cost=133.01..141.22 rows=657 width=2812)
Group Key: s.id
-> Hash Left Join (cost=98.42..129.72 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=92.60..92.60 rows=465 width=36)
-> Subquery Scan on pc (cost=82.14..92.60 rows=465 width=36)
-> HashAggregate (cost=82.14..87.95 rows=465 width=100)
Group Key: pc_1.supplier_id
-> Seq Scan on tbl_purchase_contracts pc_1 (cost=0.00..70.76 rows=2276 width=10)