QUERY PLAN
Sort (cost=44.16..44.16 rows=1 width=134)
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=8.18..44.15 rows=1 width=134)
Hash Cond: (ccr.schedule_id = s.id)
Filter: (((s.is_public = 1) AND (s.created_by <> 5495)) OR (s.created_by = 5495) OR (ccr.user_id = 5495))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..30.40 rows=2040 width=8)
-> Hash (cost=8.16..8.16 rows=1 width=118)
-> Index Scan using tbl_schedules_client_id_idx on tbl_schedules s (cost=0.14..8.16 rows=1 width=118)
Index Cond: (client_id = 1)
Filter: ((NOT is_complete) OR (complete_at >= '2026-05-15 00:00:00+08'::timestamp with time zone))