QUERY PLAN
Aggregate (cost=48.42..48.43 rows=1 width=8)
-> Sort (cost=48.36..48.37 rows=4 width=211)
Sort Key: (CASE WHEN (r.status = ANY ('{1,5}'::integer[])) THEN 0 ELSE 1 END), r.created_at DESC
-> HashAggregate (cost=48.27..48.32 rows=4 width=211)
Group Key: r.id
-> Hash Right Join (cost=3.27..43.17 rows=2040 width=14)
Hash Cond: (rccr.punch_overtime_id = r.id)
Filter: ((r.created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5446,5461,5476}'::integer[])) OR (rccr.user_id = 1000) OR (rvr.user_id = 1000))
-> Seq Scan on tbl_punch_overtime_carbon_copy_rels rccr (cost=0.00..30.40 rows=2040 width=8)
-> Hash (cost=3.22..3.22 rows=4 width=22)
-> Nested Loop Left Join (cost=1.09..3.22 rows=4 width=22)
Join Filter: (crvr.punch_overtime_id = r.id)
-> Hash Right Join (cost=1.09..2.15 rows=4 width=22)
Hash Cond: (rvr.punch_overtime_id = r.id)
-> Seq Scan on tbl_punch_overtime_verify_rels rvr (cost=0.00..1.04 rows=4 width=8)
-> Hash (cost=1.04..1.04 rows=4 width=18)
-> Seq Scan on tbl_punch_overtimes r (cost=0.00..1.04 rows=4 width=18)
-> Materialize (cost=0.00..1.01 rows=1 width=4)
-> Seq Scan on tbl_punch_overtime_cancel_verify_rels crvr (cost=0.00..1.01 rows=1 width=4)