QUERY PLAN
Sort (cost=23815.93..23822.04 rows=2444 width=18)
Sort Key: c.object_type
-> HashAggregate (cost=23653.96..23678.40 rows=2444 width=18)
Group Key: c.object_type, sub.unreadcount
-> Hash Left Join (cost=18246.59..23613.67 rows=8057 width=10)
Hash Cond: ((c.object_type)::text = (sub.object_type)::text)
-> Hash Right Join (cost=7368.27..12712.48 rows=8057 width=2)
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..5238.20 rows=40383 width=8)
Filter: (remind_user_id = 1001)
-> Hash (cost=6934.50..6934.50 rows=34702 width=10)
-> Seq Scan on tbl_comments c (cost=0.00..6934.50 rows=34702 width=10)
Filter: (NOT is_system)
-> Hash (cost=10877.73..10877.73 rows=47 width=11)
-> Subquery Scan on sub (cost=10869.28..10877.73 rows=47 width=11)
-> Finalize GroupAggregate (cost=10869.28..10877.26 rows=47 width=11)
Group Key: uc_1.object_type
-> Gather Merge (cost=10869.28..10876.56 rows=47 width=11)
Workers Planned: 1
-> Partial GroupAggregate (cost=9869.27..9871.26 rows=47 width=11)
Group Key: uc_1.object_type
-> Sort (cost=9869.27..9869.78 rows=202 width=3)
Sort Key: uc_1.object_type
-> Nested Loop (cost=0.42..9861.54 rows=202 width=3)
-> Parallel Seq Scan on tbl_unread_comments uc_1 (cost=0.00..3812.59 rows=1255 width=7)
Filter: ((NOT is_read) AND (remind_user_id = 1001))
-> Index Scan using tbl_comments_pkey on tbl_comments c_1 (cost=0.42..4.82 rows=1 width=4)
Index Cond: (id = uc_1.comment_id)
Filter: (NOT is_system)