QUERY PLAN
Aggregate (cost=328.59..328.60 rows=1 width=32)
-> Hash Semi Join (cost=222.12..328.47 rows=48 width=7)
Hash Cond: ("*SELECT* 1".contract_id = t.id)
-> Append (cost=68.12..173.72 rows=82 width=11)
-> Subquery Scan on "*SELECT* 1" (cost=68.12..109.11 rows=80 width=10)
-> Hash Join (cost=68.12..108.31 rows=80 width=106)
Hash Cond: (r.erp_collect_ticket_id = t_1.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..34.77 rows=2059 width=14)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=67.09..67.09 rows=83 width=4)
-> Seq Scan on tbl_erp_collect_tickets t_1 (cost=0.00..67.09 rows=83 width=4)
Filter: ((bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Subquery Scan on "*SELECT* 2" (cost=0.28..9.36 rows=1 width=36)
-> Nested Loop (cost=0.28..9.35 rows=1 width=132)
-> Seq Scan on tbl_erp_cash_cost_ticket_sales_contract_settles r_1 (cost=0.00..1.01 rows=1 width=40)
Filter: (sales_contract_id IS NOT NULL)
-> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets t_2 (cost=0.28..8.31 rows=1 width=4)
Index Cond: (id = r_1.erp_cash_cost_ticket_id)
Filter: (is_payment_settle AND (bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Subquery Scan on "*SELECT* 3" (cost=0.28..55.25 rows=1 width=36)
-> Nested Loop (cost=0.28..55.24 rows=1 width=132)
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..38.50 rows=2 width=14)
Filter: (sales_contract_id IS NOT NULL)
-> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets t_3 (cost=0.28..8.30 rows=1 width=4)
Index Cond: (id = r_2.erp_payment_ticket_id)
Filter: (is_payment_settle AND (bank_settle_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 2))
-> Hash (cost=153.40..153.40 rows=48 width=4)
-> Hash Anti Join (cost=84.33..153.40 rows=48 width=4)
Hash Cond: (t.id = cancel.sales_contract_id)
-> Seq Scan on tbl_sales_contracts t (cost=0.00..68.46 rows=48 width=4)
Filter: (build_by_project AND (created_at >= '2025-08-08 14:34:58+08'::timestamp with time zone))
-> Hash (cost=84.32..84.32 rows=1 width=4)
-> Subquery Scan on cancel (cost=84.29..84.32 rows=1 width=4)
-> GroupAggregate (cost=84.29..84.31 rows=1 width=12)
Group Key: t_4.sales_contract_id
-> Sort (cost=84.29..84.30 rows=1 width=4)
Sort Key: t_4.sales_contract_id
-> Seq Scan on tbl_erp_sales_orders t_4 (cost=0.00..84.28 rows=1 width=4)
Filter: ((cancel_at >= '2025-08-08 14:34:58+08'::timestamp with time zone) AND (cancel_at <= '2025-12-31 23:59:59+08'::timestamp with time zone) AND (status = 8))