QUERY PLAN
Sort (cost=131.32..131.33 rows=1 width=77)
Sort Key: scpcrd.remind_date DESC
-> Nested Loop (cost=59.34..131.31 rows=1 width=77)
-> Hash Join (cost=59.06..78.89 rows=1 width=41)
Hash Cond: (scpcrd.contract_id = sc.id)
-> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrd (cost=0.00..17.36 rows=936 width=33)
-> Hash (cost=59.05..59.05 rows=1 width=16)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..59.05 rows=1 width=16)
Filter: ((from_project IS NOT NULL) AND (from_project = 3811))
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..8.30 rows=1 width=8)
Index Cond: (id = 3811)
SubPlan 1
-> Aggregate (cost=22.05..22.06 rows=1 width=32)
-> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrdsub (cost=0.00..22.04 rows=1 width=6)
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id))
SubPlan 2
-> Aggregate (cost=22.05..22.06 rows=1 width=32)
-> Seq Scan on tbl_sales_contract_payment_collection_remind_dates scpcrdsub_1 (cost=0.00..22.04 rows=1 width=6)
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id))