QUERY PLAN
Aggregate (cost=144.83..144.84 rows=1 width=160)
-> Hash Right Join (cost=136.37..144.81 rows=1 width=55)
Hash Cond: (sip.sales_invoice_id = sci.id)
-> HashAggregate (cost=88.84..93.04 rows=336 width=36)
Group Key: sip.sales_invoice_id
-> Hash Left Join (cost=61.27..84.49 rows=581 width=13)
Hash Cond: (sip.sales_invoice_id = sci_1.id)
Filter: (sci_1.cover_invoice_id IS NULL)
-> Seq Scan on tbl_sales_invoice_products sip (cost=0.00..21.64 rows=602 width=13)
Filter: need_match
-> Hash (cost=38.34..38.34 rows=1834 width=8)
-> Seq Scan on tbl_sales_contract_invoices sci_1 (cost=0.00..38.34 rows=1834 width=8)
-> Hash (cost=47.51..47.51 rows=1 width=27)
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..47.51 rows=1 width=27)
Filter: ((NOT is_draft) AND (from_date >= '2025-08-01'::date) AND (from_date <= '2025-08-31'::date))