QUERY PLAN
Limit (cost=467.41..467.43 rows=8 width=78)
-> Sort (cost=467.01..467.43 rows=168 width=78)
Sort Key: t.created_at DESC NULLS LAST, (('1'::text || ((r.id)::character varying)::text)) DESC
-> Nested Loop (cost=161.10..460.81 rows=168 width=78)
-> Hash Join (cost=160.82..271.03 rows=275 width=82)
Hash Cond: (r.sales_contract_id = c.id)
-> Append (cost=75.98..185.47 rows=275 width=78)
-> Hash Join (cost=75.98..118.22 rows=273 width=78)
Hash Cond: (r.erp_collect_ticket_id = t.id)
-> Seq Scan on tbl_erp_collect_ticket_settles r (cost=0.00..34.77 rows=2059 width=18)
Filter: (sales_contract_id IS NOT NULL)
-> Hash (cost=72.43..72.43 rows=284 width=28)
-> Seq Scan on tbl_erp_collect_tickets t (cost=0.00..72.43 rows=284 width=28)
Filter: ((status = ANY ('{2,5}'::integer[])) AND (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))
-> Nested Loop (cost=0.28..9.34 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.28..8.31 rows=1 width=46)
Index Cond: (id = r_1.erp_cash_cost_ticket_id)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])) AND (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))
-> Nested Loop (cost=0.28..55.17 rows=1 width=114)
-> Seq Scan on tbl_erp_payment_ticket_settles r_2 (cost=0.00..38.50 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=38)
Index Cond: (id = r_2.erp_payment_ticket_id)
Filter: (is_payment_settle AND (status = ANY ('{2,5}'::integer[])) AND (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))
-> Hash (cost=64.37..64.37 rows=1637 width=8)
-> Seq Scan on tbl_sales_contracts c (cost=0.00..64.37 rows=1637 width=8)
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..0.69 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[]))