QUERY PLAN
Aggregate (cost=224.02..224.03 rows=1 width=8)
-> Sort (cost=222.86..223.05 rows=77 width=479)
Sort Key: s.is_complete, s.end_at DESC, s.created_at DESC
-> HashAggregate (cost=219.68..220.45 rows=77 width=479)
Group Key: s.id
-> Hash Right Join (cost=206.80..219.49 rows=77 width=21)
Hash Cond: (ccr.schedule_id = s.id)
Filter: (((s.is_public = 1) AND (s.created_by <> 1000)) OR (s.created_by = 1000) OR (ccr.user_id = 1000))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.88 rows=688 width=8)
-> Hash (cost=205.81..205.81 rows=79 width=33)
-> Bitmap Heap Scan on tbl_schedules s (cost=4.90..205.81 rows=79 width=33)
Recheck Cond: (client_id = 2128)
-> Bitmap Index Scan on tbl_schedules_client_id_idx (cost=0.00..4.88 rows=79 width=0)
Index Cond: (client_id = 2128)