QUERY PLAN
Aggregate (cost=322.56..322.57 rows=1 width=8)
-> Sort (cost=321.06..321.31 rows=100 width=495)
Sort Key: s.set_top_at DESC NULLS LAST, (CASE WHEN s.is_complete THEN 3 WHEN ((NOT s.is_complete) AND (s.end_at <= now())) THEN 2 ELSE 1 END), (CASE WHEN s.is_complete THEN s.complete_at ELSE NULL::timestamp with time zone END) DESC, (CASE WHEN (NOT s.is_complete) THEN s.end_at ELSE NULL::timestamp with time zone END), s.created_at DESC
-> Group (cost=316.74..317.74 rows=100 width=495)
Group Key: s.id
-> Sort (cost=316.74..316.99 rows=100 width=37)
Sort Key: s.id
-> Hash Right Join (cost=301.28..313.42 rows=100 width=37)
Hash Cond: (ccr.schedule_id = s.id)
Filter: ((((s.is_public = 1) AND (s.created_by <> 1001)) OR (s.created_by = 1001) OR (ccr.user_id = 1001)) AND ((s.created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1017,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5296,5300,5311,5329,5332,5360,5388,5404,5420,5440,5445,5446}'::integer[])) OR (ccr.user_id = 1001)))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.45 rows=645 width=8)
-> Hash (cost=299.41..299.41 rows=149 width=49)
-> Bitmap Heap Scan on tbl_schedules s (cost=5.44..299.41 rows=149 width=49)
Recheck Cond: (created_by = 1001)
-> Bitmap Index Scan on tbl_schedules_created_by_idx (cost=0.00..5.40 rows=149 width=0)
Index Cond: (created_by = 1001)