QUERY PLAN
Sort (cost=117.45..117.46 rows=1 width=198)
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.end_at DESC
-> Hash Right Join (cost=104.77..117.44 rows=1 width=198)
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))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.87 rows=687 width=8)
-> Hash (cost=104.75..104.75 rows=1 width=182)
-> Index Scan using tbl_schedules_project_id_idx on tbl_schedules s (cost=0.29..104.75 rows=1 width=182)
Index Cond: (project_id = ANY ('{3957,4005,3976,4002,3972,4034,4037,4026,4007,3986,4041,4031,4030,4029,4020,4017,4001,3997,3996,3994}'::integer[]))
Filter: ((NOT is_complete) OR (complete_at >= '2025-12-04 00:00:00+08'::timestamp with time zone))