QUERY PLAN
Limit (cost=239.09..239.14 rows=20 width=147)
-> Sort (cost=239.09..241.69 rows=1042 width=147)
Sort Key: pci.from_date DESC NULLS LAST, pci.created_at DESC NULLS LAST
-> HashAggregate (cost=200.94..211.36 rows=1042 width=147)
Group Key: pci.id
-> Hash Right Join (cost=119.56..198.33 rows=1042 width=147)
Hash Cond: (pcpp.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_products pcpp (cost=0.00..61.13 rows=2113 width=4)
-> Hash (cost=106.54..106.54 rows=1042 width=147)
-> Hash Right Join (cost=70.35..106.54 rows=1042 width=147)
Hash Cond: (pip.purchase_invoice_id = pci.id)
-> Seq Scan on tbl_purchase_invoice_projects pip (cost=0.00..30.94 rows=1994 width=8)
-> Hash (cost=57.33..57.33 rows=1042 width=147)
-> Seq Scan on tbl_purchase_contract_invoices pci (cost=0.00..57.33 rows=1042 width=147)
Filter: ((cover_invoice_id IS NULL) AND ((from_date >= '2024-08-01'::date) OR (NOT is_draft)))