QUERY PLAN
Aggregate (cost=246.32..246.33 rows=1 width=8)
-> Sort (cost=245.12..245.32 rows=80 width=623)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=242.19..242.59 rows=80 width=623)
Group Key: c.id
-> Sort (cost=242.19..242.39 rows=80 width=16)
Sort Key: c.id
-> Hash Left Join (cost=159.03..239.66 rows=80 width=16)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Nested Loop Left Join (cost=156.88..236.80 rows=80 width=20)
-> Hash Right Join (cost=156.61..198.32 rows=80 width=20)
Hash Cond: (pcr.contract_id = c.id)
-> Seq Scan on tbl_purchase_client_rels pcr (cost=0.00..33.07 rows=2107 width=8)
-> Hash (cost=155.61..155.61 rows=80 width=16)
-> Hash Right Join (cost=135.76..155.61 rows=80 width=16)
Hash Cond: (pcp1.purchase_contract_id = c.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=20)
-> Seq Scan on tbl_purchase_contracts c (cost=0.00..134.76 rows=80 width=20)
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))
-> Index Scan using tbl_clients_pkey on tbl_clients client (cost=0.28..0.48 rows=1 width=8)
Index Cond: (pcr.client_id = id)
-> Hash (cost=1.51..1.51 rows=51 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.51 rows=51 width=4)