QUERY PLAN
Sort (cost=136.91..136.92 rows=4 width=109)
Sort Key: scpcrd.remind_date DESC
-> Nested Loop (cost=126.97..136.87 rows=4 width=109)
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrd (cost=0.00..1.06 rows=1 width=37)
Filter: (contract_id = 1)
-> Group (cost=126.97..127.00 rows=4 width=623)
Group Key: sc.id, (sum("*SELECT* 1".amount))
-> Sort (cost=126.97..126.98 rows=4 width=36)
Sort Key: (sum("*SELECT* 1".amount))
-> Nested Loop Left Join (cost=0.00..126.93 rows=4 width=36)
Join Filter: ("*SELECT* 1".contract_id = sc.id)
-> Seq Scan on tbl_purchase_contracts sc (cost=0.00..1.07 rows=1 width=4)
Filter: (id = 1)
-> GroupAggregate (cost=0.00..125.79 rows=4 width=36)
Group Key: "*SELECT* 1".contract_id
-> Append (cost=0.00..125.68 rows=4 width=124)
-> Subquery Scan on "*SELECT* 1" (cost=0.00..31.07 rows=1 width=124)
-> Nested Loop (cost=0.00..31.06 rows=1 width=120)
Join Filter: (r.erp_payment_ticket_id = t.id)
-> Seq Scan on tbl_erp_payment_tickets t (cost=0.00..12.25 rows=1 width=52)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Seq Scan on tbl_erp_payment_ticket_settles r (cost=0.00..18.75 rows=4 width=44)
Filter: (purchase_contract_id = 1)
-> Nested Loop (cost=0.00..31.26 rows=1 width=124)
Join Filter: (r_1.erp_other_income_ticket_id = t_1.id)
-> Seq Scan on tbl_erp_other_income_ticket_purchase_contract_settles r_1 (cost=0.00..19.00 rows=4 width=44)
Filter: (purchase_contract_id = 1)
-> Materialize (cost=0.00..12.13 rows=2 width=48)
-> Seq Scan on tbl_erp_other_income_tickets t_1 (cost=0.00..12.12 rows=2 width=48)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Nested Loop (cost=0.00..32.18 rows=1 width=124)
Join Filter: (r_2.erp_cash_cost_ticket_id = t_2.id)
-> Seq Scan on tbl_erp_cash_cost_tickets t_2 (cost=0.00..12.38 rows=1 width=48)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Seq Scan on tbl_erp_cash_cost_ticket_purchase_contract_settles r_2 (cost=0.00..19.75 rows=4 width=44)
Filter: (purchase_contract_id = 1)
-> Nested Loop (cost=0.00..31.14 rows=1 width=124)
Join Filter: (r_3.erp_collect_ticket_id = t_3.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r_3 (cost=0.00..18.75 rows=4 width=44)
Filter: (purchase_contract_id = 1)
-> Materialize (cost=0.00..12.26 rows=2 width=48)
-> Seq Scan on tbl_erp_collect_tickets t_3 (cost=0.00..12.25 rows=2 width=48)
Filter: (status = ANY ('{2,5}'::integer[]))
SubPlan 1
-> Aggregate (cost=1.08..1.09 rows=1 width=32)
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrdsub (cost=0.00..1.07 rows=1 width=5)
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id))
SubPlan 2
-> Aggregate (cost=1.08..1.09 rows=1 width=32)
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrdsub_1 (cost=0.00..1.07 rows=1 width=5)
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id))