QUERY PLAN
Aggregate (cost=956.41..956.42 rows=1 width=32)
-> Sort (cost=953.57..954.04 rows=189 width=106)
Sort Key: "*SELECT* 1".created_at DESC NULLS LAST, "*SELECT* 1".id DESC
-> Nested Loop (cost=158.48..946.42 rows=189 width=106)
-> Hash Join (cost=158.20..733.78 rows=316 width=58)
Hash Cond: ("*SELECT* 1".contract_id = c.id)
-> Append (cost=73.61..648.35 rows=316 width=58)
-> Subquery Scan on "*SELECT* 1" (cost=73.61..115.91 rows=219 width=50)
-> Hash Join (cost=73.61..113.72 rows=219 width=98)
Hash Cond: (r.erp_collect_ticket_id = t.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..33.18 rows=2011 width=18)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=70.86..70.86 rows=220 width=12)
-> Seq Scan on tbl_erp_collect_tickets t (cost=0.00..70.86 rows=220 width=12)
Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-12-31 00:00:00+08'::timestamp with time zone) AND (status = ANY ('{2,5,1}'::integer[])))
-> Subquery Scan on "*SELECT* 2" (cost=459.09..480.60 rows=96 width=76)
-> Hash Join (cost=459.09..479.64 rows=96 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=44)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=447.51..447.51 rows=926 width=12)
-> Seq Scan on tbl_erp_cash_cost_tickets t_1 (cost=0.00..447.51 rows=926 width=12)
Filter: ((created_at >= '2025-01-01 00:00:00+08'::timestamp with time zone) AND (created_at <= '2025-12-31 00:00:00+08'::timestamp with time zone) AND (status = ANY ('{2,5,1}'::integer[])))
-> Subquery Scan on "*SELECT* 3" (cost=0.28..51.84 rows=1 width=76)
-> Nested Loop (cost=0.28..51.83 rows=1 width=124)
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..35.14 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.31 rows=1 width=12)
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 <= '2025-12-31 00:00:00+08'::timestamp with time zone) AND (status = ANY ('{2,5,1}'::integer[])))
-> Hash (cost=63.71..63.71 rows=1671 width=8)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..63.71 rows=1671 width=8)
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..0.67 rows=1 width=4)
Index Cond: ((id = c.from_project) AND (id IS NOT NULL))
Filter: (created_by = ANY ('{1001,1004,1005,1013,5087,5295,5300,5311,5329,5332,5420,5448,5449}'::integer[]))