QUERY PLAN
Hash Join (cost=346.27..498.68 rows=200 width=150)
Hash Cond: (tbl_contacts.id = contact.id)
-> Seq Scan on tbl_contacts (cost=0.00..139.84 rows=4784 width=150)
-> Hash (cost=343.77..343.77 rows=200 width=4)
-> HashAggregate (cost=339.77..341.77 rows=200 width=4)
Group Key: contact.id
-> Hash Join (cost=186.86..339.27 rows=200 width=4)
Hash Cond: (contact.id = ps.contact_id)
-> Seq Scan on tbl_contacts contact (cost=0.00..139.84 rows=4784 width=4)
-> Hash (cost=184.36..184.36 rows=200 width=4)
-> Subquery Scan on ps (cost=179.86..184.36 rows=200 width=4)
-> HashAggregate (cost=179.86..182.36 rows=200 width=68)
Group Key: pcp.contact_id
Filter: (sum(pcp.point) IS NOT NULL)
-> Hash Join (cost=158.41..178.30 rows=312 width=36)
Hash Cond: (pcp.purchase_contract_id = p.id)
-> Seq Scan on tbl_purchase_contract_contact_points pcp (cost=0.00..17.80 rows=780 width=40)
-> Hash (cost=157.41..157.41 rows=80 width=4)
-> Subquery Scan on p (cost=155.81..157.41 rows=80 width=4)
-> HashAggregate (cost=155.81..156.61 rows=80 width=591)
Group Key: pc.id
-> Hash Right Join (cost=135.76..155.61 rows=80 width=4)
Hash Cond: (pcp1.purchase_contract_id = pc.id)
-> Seq Scan on tbl_purchase_contract_contact_points pcp1 (cost=0.00..17.80 rows=780 width=8)
-> Hash (cost=134.76..134.76 rows=80 width=4)
-> Seq Scan on tbl_purchase_contracts pc (cost=0.00..134.76 rows=80 width=4)
Filter: ((NOT is_draft) AND (NOT is_verify) AND (id IS NOT NULL) AND (signed_at >= '2026-01-01'::date) AND (signed_at <= '2026-12-31'::date) AND (cost_type = 1))