QUERY PLAN
Aggregate (cost=225.50..225.51 rows=1 width=8)
-> Sort (cost=224.31..224.51 rows=79 width=479)
Sort Key: s.is_complete, s.end_at DESC, s.created_at DESC
-> HashAggregate (cost=221.03..221.82 rows=79 width=479)
Group Key: s.id
-> Hash Right Join (cost=208.16..220.83 rows=79 width=21)
Hash Cond: (ccr.schedule_id = s.id)
Filter: (((s.is_public = 1) AND (s.created_by <> 5064)) OR (s.created_by = 5064) OR (ccr.user_id = 5064))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.87 rows=687 width=8)
-> Hash (cost=207.15..207.15 rows=81 width=33)
-> Bitmap Heap Scan on tbl_schedules s (cost=4.91..207.15 rows=81 width=33)
Recheck Cond: (client_id = 518)
-> Bitmap Index Scan on tbl_schedules_client_id_idx (cost=0.00..4.89 rows=81 width=0)
Index Cond: (client_id = 518)