QUERY PLAN
Sort (cost=189.69..189.70 rows=2 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=176.98..189.68 rows=2 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.89 rows=689 width=8)
-> Hash (cost=176.95..176.95 rows=2 width=182)
-> Index Scan using tbl_schedules_project_id_idx on tbl_schedules s (cost=0.29..176.95 rows=2 width=182)
Index Cond: (project_id = ANY ('{4184,4182,4183,4181,4174,4173,4172,4171,4170,4169,4168,4167,4166,4144,4161,4164,4151,4157,4155,4152,4150,4142,4158,4127,4098,4111,4096,4086,4063,4057,4052,3991,4079,4078,4014,3950,3927,3949,3751,3874}'::integer[]))
Filter: ((NOT is_complete) OR (complete_at >= '2026-06-02 00:00:00+08'::timestamp with time zone))