QUERY PLAN
Aggregate (cost=624.20..624.21 rows=1 width=32)
-> Nested Loop (cost=190.61..624.12 rows=30 width=6)
-> Hash Join (cost=190.33..425.02 rows=191 width=10)
Hash Cond: (c.id = "*SELECT* 1".contract_id)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..226.84 rows=1584 width=14)
-> Hash (cost=187.95..187.95 rows=191 width=4)
-> Append (cost=71.56..187.95 rows=191 width=4)
-> Subquery Scan on "*SELECT* 1" (cost=71.56..111.50 rows=186 width=4)
-> Hash Join (cost=71.56..109.64 rows=186 width=124)
Hash Cond: (r.erp_collect_ticket_id = t.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..32.86 rows=1985 width=8)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=69.24..69.24 rows=186 width=4)
-> Seq Scan on tbl_erp_collect_tickets t (cost=0.00..69.24 rows=186 width=4)
Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at < '2026-01-01 00:00:00'::timestamp without time zone) AND (status = ANY ('{2,5,1}'::integer[])))
-> Subquery Scan on "*SELECT* 2" (cost=13.57..33.50 rows=4 width=4)
-> Hash Join (cost=13.57..33.46 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.80 rows=776 width=8)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=13.56..13.56 rows=1 width=4)
-> Seq Scan on tbl_erp_cash_cost_tickets t_1 (cost=0.00..13.56 rows=1 width=4)
Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at < '2026-01-01 00:00:00'::timestamp without time zone) AND (status = ANY ('{2,5,1}'::integer[])))
-> Subquery Scan on "*SELECT* 3" (cost=0.28..42.95 rows=1 width=4)
-> Nested Loop (cost=0.28..42.94 rows=1 width=124)
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..34.54 rows=1 width=8)
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.31 rows=1 width=4)
Index Cond: (id = r_2.erp_payment_ticket_id)
Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at < '2026-01-01 00:00:00'::timestamp without time zone) AND (status = ANY ('{2,5,1}'::integer[])))
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..1.04 rows=1 width=4)
Index Cond: (id = c.from_project)
Filter: ((project_status = 3) AND (created_by = ANY ('{1004,1005,1013,5087}'::integer[])))