QUERY PLAN
Limit (cost=169.72..169.77 rows=20 width=38)
-> Sort (cost=169.72..169.82 rows=41 width=38)
Sort Key: scp.created_at DESC NULLS LAST, scp.id DESC
-> Nested Loop (cost=74.57..168.63 rows=41 width=38)
-> Hash Join (cost=74.29..118.63 rows=72 width=42)
Hash Cond: (scp.contract_id = c.id)
-> Seq Scan on tbl_sales_contract_payments scp (cost=0.00..44.16 rows=72 width=38)
Filter: ((collected_date >= '2025-01-01'::date) AND (collected_date <= '2025-12-31'::date))
-> Hash (cost=55.24..55.24 rows=1524 width=8)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..55.24 rows=1524 width=8)
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..0.69 rows=1 width=4)
Index Cond: ((id = c.from_project) AND (id IS NOT NULL))
Filter: (created_by = ANY ('{1001,1004,1005,1013,5087,5295,5300,5311,5329,5332,5420}'::integer[]))