QUERY PLAN
Sort (cost=115.72..115.73 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=103.02..115.71 rows=1 width=198)
Hash Cond: (ccr.schedule_id = s.id)
Filter: (((s.is_public = 1) AND (s.created_by <> 5250)) OR (s.created_by = 5250) OR (ccr.user_id = 5250))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.88 rows=688 width=8)
-> Hash (cost=103.01..103.01 rows=1 width=182)
-> Index Scan using tbl_schedules_project_id_idx on tbl_schedules s (cost=0.29..103.01 rows=1 width=182)
Index Cond: (project_id = ANY ('{4024,4174,4002,4144,4099,4151,4081,4154,4130,4124,4121,4103,4119,4037,3993,3992,3986,3580,4094,4111}'::integer[]))
Filter: ((NOT is_complete) OR (complete_at >= '2026-05-19 00:00:00+08'::timestamp with time zone))