QUERY PLAN
Sort (cost=378.18..378.20 rows=7 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=365.36..378.08 rows=7 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.88 rows=688 width=8)
-> Hash (cost=365.27..365.27 rows=7 width=182)
-> Index Scan using tbl_schedules_project_id_idx on tbl_schedules s (cost=0.29..365.27 rows=7 width=182)
Index Cond: (project_id = ANY ('{4175,4174,4173,4172,4171,4170,4169,4168,4167,4166,4164,4161,4158,4157,4155,4152,4151,4150,4144,4142,4127,4111,4098,4096,4086,4079,4078,4063,4057,4052,4014,3991,3950,3949,3927,3899,3886,3874,3872,3857,3855,3816,3813,3786,3767,3764,3760,3752,3751,3744,3723,3714,3686,3679,3661,3660,3653,3652,3644,3633,3623,3599,3591,3590,3589,3577,3576,3568,3552,3544,3515,3514,3513,3503,3467,3458,3441,3424,3372,3371,3318,3300,3281,3276,3274,3269,3265,3263,3251,3246,3235,3225,3216,3209,3208,3201,3195,3157,3148,3073,3027,3019,2939,2907,2893,2759,2695,2684,2530,2508,2507,2504,2459,2458,2422,2080,2079,1983,1963,1938,1929,1925,1791,1460,1240,1111,1018,986,983,887,884,883,861,778,764,88}'::integer[]))
Filter: ((NOT is_complete) OR (complete_at >= '2026-05-21 00:00:00+08'::timestamp with time zone))