QUERY PLAN
Limit (cost=178.51..178.56 rows=20 width=211)
-> Sort (cost=178.46..178.67 rows=85 width=211)
Sort Key: c.signed_at DESC, c.created_at DESC
-> Group (cost=174.90..175.77 rows=85 width=211)
Group Key: c.id
-> Merge Left Join (cost=174.90..175.35 rows=85 width=179)
Merge Cond: (c.id = pcp1.purchase_contract_id)
-> Sort (cost=173.88..174.10 rows=85 width=179)
Sort Key: c.id
-> Hash Left Join (cost=91.32..171.16 rows=85 width=179)
Hash Cond: (client.sales_rep = sgr.sales_id)
-> Nested Loop Left Join (cost=89.17..168.25 rows=85 width=183)
-> Hash Right Join (cost=88.89..127.56 rows=85 width=183)
Hash Cond: (pcr.contract_id = c.id)
-> Seq Scan on tbl_purchase_client_rels pcr (cost=0.00..33.11 rows=2111 width=8)
-> Hash (cost=87.83..87.83 rows=85 width=179)
-> Seq Scan on tbl_purchase_contracts c (cost=0.00..87.83 rows=85 width=179)
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)
-> Sort (cost=1.02..1.02 rows=1 width=8)
Sort Key: pcp1.purchase_contract_id
-> Seq Scan on tbl_purchase_contract_contact_points pcp1 (cost=0.00..1.01 rows=1 width=8)