QUERY PLAN
Sort (cost=439.13..439.16 rows=10 width=165)
Sort Key: scpcrd.remind_date DESC
-> Nested Loop (cost=11.03..438.96 rows=10 width=165)
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.14..8.16 rows=1 width=36)
Index Cond: (id = 1)
-> Hash Join (cost=10.89..29.38 rows=10 width=101)
Hash Cond: (scpcrd.contract_id = sc.id)
-> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrd (cost=0.00..16.70 rows=670 width=93)
-> Hash (cost=10.88..10.88 rows=1 width=16)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..10.88 rows=1 width=16)
Filter: ((from_project IS NOT NULL) AND (from_project = 1))
SubPlan 1
-> Aggregate (cost=20.05..20.07 rows=1 width=32)
-> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrdsub (cost=0.00..20.05 rows=1 width=32)
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id))
SubPlan 2
-> Aggregate (cost=20.05..20.07 rows=1 width=32)
-> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrdsub_1 (cost=0.00..20.05 rows=1 width=32)
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id))