QUERY PLAN
Sort (cost=7.24..7.26 rows=7 width=21)
Sort Key: c.object_type
-> HashAggregate (cost=7.07..7.14 rows=7 width=21)
Group Key: c.object_type, sub.unreadcount
-> Hash Left Join (cost=5.23..6.89 rows=37 width=13)
Hash Cond: ((c.object_type)::text = (sub.object_type)::text)
-> Hash Right Join (cost=2.06..3.55 rows=37 width=5)
Hash Cond: (uc.comment_id = c.id)
Filter: ((uc.remind_user_id = 5495) OR (c.created_by = 5495))
-> Seq Scan on tbl_unread_comments uc (cost=0.00..1.45 rows=19 width=8)
Filter: (remind_user_id = 5495)
-> Hash (cost=1.48..1.48 rows=46 width=13)
-> Seq Scan on tbl_comments c (cost=0.00..1.48 rows=46 width=13)
Filter: is_system
-> Hash (cost=3.16..3.16 rows=1 width=13)
-> Subquery Scan on sub (cost=3.13..3.16 rows=1 width=13)
-> GroupAggregate (cost=3.13..3.15 rows=1 width=13)
Group Key: uc_1.object_type
-> Sort (cost=3.13..3.14 rows=1 width=5)
Sort Key: uc_1.object_type
-> Hash Join (cost=1.46..3.12 rows=1 width=5)
Hash Cond: (c_1.id = uc_1.comment_id)
-> Seq Scan on tbl_comments c_1 (cost=0.00..1.48 rows=46 width=4)
Filter: is_system
-> Hash (cost=1.45..1.45 rows=1 width=9)
-> Seq Scan on tbl_unread_comments uc_1 (cost=0.00..1.45 rows=1 width=9)
Filter: ((NOT is_read) AND (remind_user_id = 5495))