QUERY PLAN
Aggregate (cost=104.65..104.66 rows=1 width=32)
-> Nested Loop (cost=12.56..104.64 rows=1 width=32)
-> Nested Loop (cost=12.42..103.08 rows=1 width=36)
-> Subquery Scan on sub (cost=12.28..94.70 rows=1 width=36)
Filter: ((sub.collected_date >= '2026-01-01 00:00:00+08'::timestamp with time zone) AND (sub.collected_date < '2027-01-01 00:00:00'::timestamp without time zone))
-> Append (cost=12.28..94.46 rows=16 width=124)
-> Subquery Scan on "*SELECT* 1" (cost=12.28..31.30 rows=8 width=124)
-> Hash Join (cost=12.28..31.20 rows=8 width=120)
Hash Cond: (r.erp_collect_ticket_id = t.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..17.00 rows=696 width=44)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=12.25..12.25 rows=2 width=52)
-> Seq Scan on tbl_erp_collect_tickets t (cost=0.00..12.25 rows=2 width=52)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Hash Join (cost=12.39..31.92 rows=4 width=124)
Hash Cond: (r_1.erp_cash_cost_ticket_id = t_1.id)
-> Seq Scan on tbl_erp_cash_cost_ticket_sales_contract_settles r_1 (cost=0.00..17.50 rows=746 width=44)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=12.38..12.38 rows=1 width=48)
-> Seq Scan on tbl_erp_cash_cost_tickets t_1 (cost=0.00..12.38 rows=1 width=48)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Hash Join (cost=12.26..31.16 rows=4 width=124)
Hash Cond: (r_2.erp_payment_ticket_id = t_2.id)
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..17.00 rows=696 width=44)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=12.25..12.25 rows=1 width=48)
-> Seq Scan on tbl_erp_payment_tickets t_2 (cost=0.00..12.25 rows=1 width=48)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts c (cost=0.14..8.16 rows=1 width=8)
Index Cond: (id = sub.contract_id)
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.14..0.85 rows=1 width=4)
Index Cond: (id = c.from_project)
Filter: ((created_by = ANY ('{5493,5493}'::integer[])) AND (project_status = 3))