QUERY PLAN
Sort (cost=124.35..124.36 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=111.61..124.34 rows=1 width=198)
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.91 rows=691 width=8)
-> Hash (cost=111.60..111.60 rows=1 width=182)
-> Index Scan using tbl_schedules_project_id_idx on tbl_schedules s (cost=0.29..111.60 rows=1 width=182)
Index Cond: (project_id = ANY ('{2939,3915,3914,3888,3864,3937,3939,3921,3931,3232,3461,3695,3778,3832,3849,3868,3923,3927,3938,3907}'::integer[]))
Filter: ((NOT is_complete) OR (complete_at >= '2025-07-29 00:00:00+08'::timestamp with time zone))