QUERY PLAN
Aggregate (cost=255.12..255.13 rows=1 width=8)
-> Sort (cost=255.09..255.10 rows=2 width=674)
Sort Key: p.bargain_date DESC, p.created_at DESC
-> Nested Loop (cost=169.24..255.08 rows=2 width=674)
-> Hash Join (cost=168.96..182.56 rows=55 width=4)
Hash Cond: ((min(subpsl.id)) = minpsl.id)
-> HashAggregate (cost=91.42..97.43 rows=601 width=12)
Group Key: subpsl.project_id
Filter: ((min(subpsl.id) IS NOT NULL) AND (max(subpsl.id) IS NOT NULL))
-> Seq Scan on tbl_project_status_logs subpsl (cost=0.00..82.79 rows=690 width=8)
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))
-> Hash (cost=73.16..73.16 rows=350 width=4)
-> Seq Scan on tbl_project_status_logs minpsl (cost=0.00..73.16 rows=350 width=4)
Filter: ((old_status IS NULL) AND (new_status = '3'::smallint))
-> Index Scan using tbl_projects_pkey on tbl_projects p (cost=0.28..1.32 rows=1 width=16)
Index Cond: (id = subpsl.project_id)
Filter: (created_by = 1001)