QUERY PLAN
Subquery Scan on sub (cost=497.51..581.04 rows=13 width=164)
Filter: (sub.id = 2756)
-> WindowAgg (cost=497.51..548.91 rows=2570 width=164)
-> Sort (cost=497.51..503.94 rows=2570 width=156)
Sort Key: sub_1.from_date DESC NULLS LAST, sub_1.created_at DESC NULLS LAST
-> Subquery Scan on sub_1 (cost=300.55..351.95 rows=2570 width=156)
-> HashAggregate (cost=300.55..326.25 rows=2570 width=156)
Group Key: pci.id
-> Hash Right Join (cost=164.33..293.01 rows=3018 width=156)
Hash Cond: (pcpp.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_products pcpp (cost=0.00..87.18 rows=3018 width=4)
-> Hash (cost=132.21..132.21 rows=2570 width=156)
-> Hash Right Join (cost=92.83..132.21 rows=2570 width=156)
Hash Cond: (pip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_projects pip (cost=0.00..33.68 rows=2168 width=8)
-> Hash (cost=60.70..60.70 rows=2570 width=156)
-> Seq Scan on tbl_purchase_contract_invoices pci (cost=0.00..60.70 rows=2570 width=156)
Filter: (cover_invoice_id IS NULL)