QUERY PLAN
GroupAggregate (cost=569.06..569.14 rows=3 width=42)
Group Key: sub.new_status
-> Sort (cost=569.06..569.07 rows=5 width=7)
Sort Key: sub.new_status
-> Subquery Scan on sub (cost=472.99..569.00 rows=5 width=7)
Filter: ((sub.new_status = ANY ('{1,2}'::integer[])) AND (sub.rn = 1))
-> WindowAgg (cost=472.99..527.85 rows=2743 width=27)
-> Sort (cost=472.99..479.85 rows=2743 width=19)
Sort Key: l.project_id, l.created_at DESC
-> Hash Join (cost=217.10..316.35 rows=2743 width=19)
Hash Cond: (l.project_id = p.id)
-> Seq Scan on tbl_project_status_logs l (cost=0.00..92.03 rows=2743 width=14)
Filter: ((created_at < '2025-07-01 00:00:00+08'::timestamp with time zone) AND (new_status > 0))
-> Hash (cost=177.60..177.60 rows=3160 width=9)
-> Seq Scan on tbl_projects p (cost=0.00..177.60 rows=3160 width=9)