QUERY PLAN
HashAggregate (cost=546.14..550.14 rows=200 width=136)
Group Key: contact.id
-> Hash Left Join (cost=390.71..543.64 rows=200 width=108)
Hash Cond: (contact.id = p.contact_id)
-> Hash Join (cost=189.42..341.83 rows=200 width=68)
Hash Cond: (contact.id = ps.contact_id)
-> Seq Scan on tbl_contacts contact (cost=0.00..139.84 rows=4784 width=4)
-> Hash (cost=186.92..186.92 rows=200 width=68)
-> Subquery Scan on ps (cost=181.42..186.92 rows=200 width=68)
-> HashAggregate (cost=181.42..184.92 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=68)
Hash Cond: (pcp.purchase_contract_id = p_1.id)
-> Seq Scan on tbl_purchase_contract_contact_points pcp (cost=0.00..17.80 rows=780 width=72)
-> Hash (cost=157.41..157.41 rows=80 width=4)
-> Subquery Scan on p_1 (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))
-> Hash (cost=198.79..198.79 rows=200 width=44)
-> Subquery Scan on p (cost=192.29..198.79 rows=200 width=44)
-> GroupAggregate (cost=192.29..196.79 rows=200 width=44)
Group Key: pcp_1.contact_id
-> Sort (cost=192.29..192.79 rows=200 width=14)
Sort Key: pcp_1.contact_id
-> Hash Left Join (cost=180.11..184.64 rows=200 width=14)
Hash Cond: (pcp_1.purchase_contract_id = p_2.id)
-> HashAggregate (cost=21.70..23.70 rows=200 width=8)
Group Key: pcp_1.contact_id, pcp_1.purchase_contract_id
-> Seq Scan on tbl_purchase_contract_contact_points pcp_1 (cost=0.00..17.80 rows=780 width=8)
-> Hash (cost=157.41..157.41 rows=80 width=10)
-> Subquery Scan on p_2 (cost=155.81..157.41 rows=80 width=10)
-> HashAggregate (cost=155.81..156.61 rows=80 width=565)
Group Key: pc_1.id
-> Hash Right Join (cost=135.76..155.61 rows=80 width=10)
Hash Cond: (pcp1_1.purchase_contract_id = pc_1.id)
-> Seq Scan on tbl_purchase_contract_contact_points pcp1_1 (cost=0.00..17.80 rows=780 width=8)
-> Hash (cost=134.76..134.76 rows=80 width=10)
-> Seq Scan on tbl_purchase_contracts pc_1 (cost=0.00..134.76 rows=80 width=10)
Filter: ((NOT is_draft) AND (NOT is_verify) AND (signed_at >= '2026-01-01'::date) AND (signed_at <= '2026-12-31'::date) AND (cost_type = 1))