QUERY PLAN
Aggregate (cost=12927.04..12927.05 rows=1 width=8)
-> Sort (cost=12908.68..12911.74 rows=1224 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=7538.90..12845.91 rows=1224 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..5199.45 rows=39808 width=9)
Filter: (remind_user_id = 1001)
-> Hash (cost=7472.76..7472.76 rows=5291 width=16)
-> Seq Scan on tbl_comments c (cost=0.00..7472.76 rows=5291 width=16)
Filter: ((NOT is_system) AND ((object_type)::text = '18'::text))