QUERY PLAN
Limit (cost=2220.20..2220.23 rows=10 width=539)
-> Sort (cost=2220.18..2244.69 rows=9806 width=539)
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=43.59..1959.24 rows=9806 width=539)
Group Key: s.id
-> Merge Left Join (cost=43.59..1885.70 rows=9806 width=519)
Merge Cond: (s.id = ccr.schedule_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,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5446,5461,5476}'::integer[])) OR (ccr.user_id = 1001)))
-> Index Scan using tbl_schedules_pkey on tbl_schedules s (cost=0.29..1764.87 rows=15184 width=519)
-> Sort (cost=43.31..45.03 rows=688 width=8)
Sort Key: ccr.schedule_id
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.88 rows=688 width=8)