QUERY PLAN
Aggregate (cost=126.20..126.21 rows=1 width=8)
-> Sort (cost=125.70..125.79 rows=33 width=479)
Sort Key: s.is_complete, s.end_at DESC, s.created_at DESC
-> Group (cost=124.71..124.87 rows=33 width=479)
Group Key: s.id
-> Sort (cost=124.71..124.79 rows=33 width=21)
Sort Key: s.id
-> Hash Right Join (cost=111.73..123.87 rows=33 width=21)
Hash Cond: (ccr.schedule_id = s.id)
Filter: (((s.is_public = 1) AND (s.created_by <> 1004)) OR (s.created_by = 1004) OR (ccr.user_id = 1004))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.45 rows=645 width=8)
-> Hash (cost=111.29..111.29 rows=35 width=33)
-> Bitmap Heap Scan on tbl_schedules s (cost=4.56..111.29 rows=35 width=33)
Recheck Cond: (client_id = 2094)
-> Bitmap Index Scan on tbl_schedules_client_id_idx (cost=0.00..4.55 rows=35 width=0)
Index Cond: (client_id = 2094)