QUERY PLAN
Aggregate (cost=23099.43..23099.44 rows=1 width=8)
-> Sort (cost=22541.49..22634.48 rows=37196 width=248)
Sort Key: (CASE WHEN ((c.created_by = 1001) OR uc.is_read) THEN true ELSE false END), c.created_at DESC
-> Hash Right Join (cost=9227.80..15391.78 rows=37196 width=248)
Hash Cond: (uc.comment_id = c.id)
Filter: ((uc.remind_user_id = 1001) OR (c.created_by = 1001))
-> Seq Scan on tbl_unread_comments uc (cost=0.00..4812.54 rows=37127 width=9)
Filter: (remind_user_id = 1001)
-> Hash (cost=6392.31..6392.31 rows=163079 width=16)
-> Seq Scan on tbl_comments c (cost=0.00..6392.31 rows=163079 width=16)
Filter: is_system