QUERY PLAN
Aggregate (cost=11.10..11.11 rows=1 width=8)
-> Sort (cost=11.02..11.04 rows=5 width=307)
Sort Key: (CASE WHEN (r.status = ANY ('{1,5}'::integer[])) THEN 0 ELSE 1 END), r.created_at DESC
-> Group (cost=10.93..10.97 rows=5 width=307)
Group Key: r.id
-> Sort (cost=10.93..10.94 rows=5 width=14)
Sort Key: r.id
-> Hash Right Join (cost=9.42..10.87 rows=5 width=14)
Hash Cond: (crvr.punch_leave_id = r.id)
-> Seq Scan on tbl_punch_leave_cancel_verify_rels crvr (cost=0.00..1.32 rows=32 width=4)
-> Hash (cost=9.36..9.36 rows=5 width=14)
-> Hash Right Join (cost=5.15..9.36 rows=5 width=14)
Hash Cond: (rvr.punch_leave_id = r.id)
-> Seq Scan on tbl_punch_leave_verify_rels rvr (cost=0.00..3.74 rows=174 width=4)
-> Hash (cost=5.09..5.09 rows=5 width=18)
-> Seq Scan on tbl_punch_leaves r (cost=0.00..5.09 rows=5 width=18)
Filter: (created_by = 1001)