QUERY PLAN
Aggregate (cost=393.01..393.02 rows=1 width=32)
-> Nested Loop (cost=123.32..393.01 rows=1 width=32)
-> Nested Loop (cost=123.04..385.69 rows=11 width=36)
-> Subquery Scan on sub (cost=122.76..306.44 rows=11 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=122.76..274.19 rows=2150 width=124)
-> Subquery Scan on "*SELECT* 1" (cost=122.76..207.20 rows=2147 width=83)
-> Hash Join (cost=122.76..180.36 rows=2147 width=79)
Hash Cond: (r.erp_collect_ticket_id = t.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..35.83 rows=2154 width=18)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=95.42..95.42 rows=2187 width=37)
-> Seq Scan on tbl_erp_collect_tickets t (cost=0.00..95.42 rows=2187 width=37)
Filter: (status = ANY ('{2,5}'::integer[]))
-> Nested Loop (cost=0.29..9.32 rows=1 width=122)
-> Seq Scan on tbl_erp_cash_cost_ticket_sales_contract_settles r_1 (cost=0.00..1.01 rows=1 width=44)
Filter: (sales_contract_id IS NOT NULL)
-> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets t_1 (cost=0.29..8.30 rows=1 width=46)
Index Cond: (id = r_1.erp_cash_cost_ticket_id)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Nested Loop (cost=0.28..57.64 rows=2 width=116)
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..41.01 rows=2 width=18)
Filter: (sales_contract_id IS NOT NULL)
-> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets t_2 (cost=0.28..8.30 rows=1 width=40)
Index Cond: (id = r_2.erp_payment_ticket_id)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])))
-> Index Scan using tbl_sales_contracts_pkey on tbl_sales_contracts c (cost=0.28..7.20 rows=1 width=8)
Index Cond: (id = sub.contract_id)
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..0.66 rows=1 width=4)
Index Cond: (id = c.from_project)
Filter: ((created_by = 1001) AND (project_status = 3))