QUERY PLAN
Aggregate (cost=145.92..145.93 rows=1 width=160)
-> Hash Right Join (cost=137.17..145.88 rows=2 width=55)
Hash Cond: (sip.sales_invoice_id = sci.id)
-> HashAggregate (cost=89.47..93.80 rows=347 width=36)
Group Key: sip.sales_invoice_id
-> Hash Left Join (cost=61.51..84.97 rows=599 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.83 rows=621 width=13)
Filter: need_match
-> Hash (cost=38.45..38.45 rows=1845 width=8)
-> Seq Scan on tbl_sales_contract_invoices sci_1 (cost=0.00..38.45 rows=1845 width=8)
-> Hash (cost=47.67..47.67 rows=2 width=27)
-> Seq Scan on tbl_sales_contract_invoices sci (cost=0.00..47.67 rows=2 width=27)
Filter: ((NOT is_draft) AND (from_date >= '2025-08-01'::date) AND (from_date <= '2025-08-31'::date))