QUERY PLAN
Aggregate (cost=12593.35..12593.36 rows=1 width=8)
-> Sort (cost=12586.35..12587.52 rows=467 width=248)
Sort Key: (CASE WHEN ((c.created_by = 1000) OR uc.is_read) THEN true ELSE false END), c.created_at DESC
-> Hash Right Join (cost=7734.14..12565.64 rows=467 width=248)
Hash Cond: (uc.comment_id = c.id)
Filter: ((uc.remind_user_id = 1000) OR (c.created_by = 1000))
-> Seq Scan on tbl_unread_comments uc (cost=0.00..4171.06 rows=485 width=9)
Filter: (remind_user_id = 1000)
-> Hash (cost=5414.84..5414.84 rows=133384 width=16)
-> Seq Scan on tbl_comments c (cost=0.00..5414.84 rows=133384 width=16)
Filter: is_system