QUERY PLAN
Limit (cost=1653.26..1653.31 rows=20 width=605)
-> Sort (cost=1653.26..1654.79 rows=610 width=605)
Sort Key: (sum(pc.total_amount)) DESC NULLS LAST
-> HashAggregate (cost=1614.16..1637.03 rows=610 width=605)
Group Key: s.id
-> Hash Left Join (cost=1565.97..1598.91 rows=610 width=493)
Hash Cond: (s.id = pcr2.supplier_id)
-> Hash Left Join (cost=1167.66..1198.98 rows=610 width=485)
Hash Cond: (s.id = pcr.supplier_id)
-> Hash Left Join (cost=769.34..799.06 rows=610 width=477)
Hash Cond: (s.id = pc.supplier_id)
-> Seq Scan on tbl_suppliers s (cost=0.00..28.10 rows=610 width=381)
-> Hash (cost=764.11..764.11 rows=419 width=100)
-> Subquery Scan on pc (cost=752.58..764.11 rows=419 width=100)
-> HashAggregate (cost=752.58..759.92 rows=419 width=100)
Group Key: pc_1.supplier_id
-> Hash Left Join (cost=515.88..732.51 rows=2007 width=74)
Hash Cond: (pc_1.id = pci.contract_id)
-> Hash Left Join (cost=387.22..598.57 rows=2007 width=46)
Hash Cond: (pc_1.id = pcp.contract_id)
-> Seq Scan on tbl_purchase_contracts pc_1 (cost=0.00..206.07 rows=2007 width=14)
-> Hash (cost=384.72..384.72 rows=200 width=36)
-> Subquery Scan on pcp (cost=380.22..384.72 rows=200 width=36)
-> HashAggregate (cost=380.22..382.72 rows=200 width=36)
Group Key: "*SELECT* 1".contract_id
-> Append (cost=86.92..359.90 rows=4064 width=23)
-> Subquery Scan on "*SELECT* 1" (cost=86.92..147.40 rows=2054 width=10)
-> Hash Join (cost=86.92..126.86 rows=2054 width=98)
Hash Cond: (r.erp_payment_ticket_id = t.id)
-> Seq Scan on tbl_erp_payment_ticket_settles r (cost=0.00..34.54 rows=2054 width=14)
-> Hash (cost=61.24..61.24 rows=2054 width=4)
-> Seq Scan on tbl_erp_payment_tickets t (cost=0.00..61.24 rows=2054 width=4)
Filter: (status = ANY ('{2,5,1}'::integer[]))
-> Subquery Scan on "*SELECT* 2" (cost=12.79..32.80 rows=12 width=36)
-> Hash Join (cost=12.79..32.68 rows=12 width=124)
Hash Cond: (r_1.erp_other_income_ticket_id = t_1.id)
-> Seq Scan on tbl_erp_other_income_ticket_purchase_contract_settles r_1 (cost=0.00..17.80 rows=780 width=40)
-> Hash (cost=12.75..12.75 rows=3 width=4)
-> Seq Scan on tbl_erp_other_income_tickets t_1 (cost=0.00..12.75 rows=3 width=4)
Filter: (status = ANY ('{2,5,1}'::integer[]))
-> Subquery Scan on "*SELECT* 3" (cost=12.65..32.66 rows=12 width=36)
-> Hash Join (cost=12.65..32.54 rows=12 width=124)
Hash Cond: (r_2.erp_cash_cost_ticket_id = t_2.id)
-> Seq Scan on tbl_erp_cash_cost_ticket_purchase_contract_settles r_2 (cost=0.00..17.80 rows=780 width=40)
-> Hash (cost=12.61..12.61 rows=3 width=4)
-> Seq Scan on tbl_erp_cash_cost_tickets t_2 (cost=0.00..12.61 rows=3 width=4)
Filter: (status = ANY ('{2,5,1}'::integer[]))
-> Subquery Scan on "*SELECT* 4" (cost=84.13..147.04 rows=1986 width=36)
-> Hash Join (cost=84.13..127.18 rows=1986 width=124)
Hash Cond: (r_3.erp_collect_ticket_id = t_3.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r_3 (cost=0.00..32.86 rows=1986 width=14)
-> Hash (cost=59.31..59.31 rows=1986 width=4)
-> Seq Scan on tbl_erp_collect_tickets t_3 (cost=0.00..59.31 rows=1986 width=4)
Filter: (status = ANY ('{2,5,1}'::integer[]))
-> Hash (cost=104.52..104.52 rows=1931 width=36)
-> Subquery Scan on pci (cost=61.08..104.52 rows=1931 width=36)
-> HashAggregate (cost=61.08..85.21 rows=1931 width=36)
Group Key: tbl_purchase_contract_invoices.contract_id
-> Seq Scan on tbl_purchase_contract_invoices (cost=0.00..50.05 rows=2205 width=10)
-> Hash (cost=393.08..393.08 rows=419 width=12)
-> Subquery Scan on pcr (cost=370.37..393.08 rows=419 width=12)
-> GroupAggregate (cost=370.37..388.89 rows=419 width=12)
Group Key: pc_2.supplier_id
-> Sort (cost=370.37..375.15 rows=1910 width=8)
Sort Key: pc_2.supplier_id
-> Hash Left Join (cost=231.16..266.28 rows=1910 width=8)
Hash Cond: (pcr_1.contract_id = pc_2.id)
-> Seq Scan on tbl_purchase_client_rels pcr_1 (cost=0.00..30.10 rows=1910 width=8)
-> Hash (cost=206.07..206.07 rows=2007 width=8)
-> Seq Scan on tbl_purchase_contracts pc_2 (cost=0.00..206.07 rows=2007 width=8)
-> Hash (cost=393.08..393.08 rows=419 width=12)
-> Subquery Scan on pcr2 (cost=370.37..393.08 rows=419 width=12)
-> GroupAggregate (cost=370.37..388.89 rows=419 width=12)
Group Key: pc_3.supplier_id
-> Sort (cost=370.37..375.15 rows=1910 width=8)
Sort Key: pc_3.supplier_id
-> Hash Left Join (cost=231.16..266.28 rows=1910 width=8)
Hash Cond: (pcr_2.contract_id = pc_3.id)
-> Seq Scan on tbl_purchase_client_rels pcr_2 (cost=0.00..30.10 rows=1910 width=8)
-> Hash (cost=206.07..206.07 rows=2007 width=8)
-> Seq Scan on tbl_purchase_contracts pc_3 (cost=0.00..206.07 rows=2007 width=8)