QUERY PLAN
Aggregate (cost=21650.08..21650.09 rows=1 width=8)
-> Sort (cost=21136.36..21221.98 rows=34248 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=8740.39..14573.85 rows=34248 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..4564.96 rows=35002 width=9)
Filter: (remind_user_id = 1001)
-> Hash (cost=6074.50..6074.50 rows=153351 width=16)
-> Seq Scan on tbl_comments c (cost=0.00..6074.50 rows=153351 width=16)
Filter: is_system