QUERY PLAN
Aggregate (cost=128.95..128.96 rows=1 width=8)
-> Sort (cost=128.93..128.93 rows=1 width=479)
Sort Key: s.is_complete, s.end_at DESC, s.created_at DESC
-> Group (cost=128.91..128.92 rows=1 width=479)
Group Key: s.id
-> Sort (cost=128.91..128.92 rows=1 width=21)
Sort Key: s.id
-> Nested Loop (cost=108.66..128.90 rows=1 width=21)
-> Hash Right Join (cost=108.66..120.81 rows=1 width=25)
Hash Cond: (ccr.schedule_id = s.id)
Filter: ((((s.is_public = 1) AND (s.created_by <> 1000)) OR (s.created_by = 1000) OR (ccr.user_id = 1000)) AND ((s.created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1017,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5296,5300,5311,5329,5332,5360,5388,5404,5420,5440,5445,5446}'::integer[])) OR (ccr.user_id = 1000)))
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.45 rows=645 width=8)
-> Hash (cost=108.65..108.65 rows=1 width=33)
-> Bitmap Heap Scan on tbl_schedules s (cost=4.54..108.65 rows=1 width=33)
Recheck Cond: (created_by = 5016)
Filter: ((NOT is_complete) AND ((end_at >= '2025-07-02 11:04:09+08'::timestamp with time zone) OR (end_at IS NULL)))
-> Bitmap Index Scan on tbl_schedules_created_by_idx (cost=0.00..4.54 rows=34 width=0)
Index Cond: (created_by = 5016)
-> Seq Scan on tbl_users u (cost=0.00..8.09 rows=1 width=4)
Filter: ((id = 5016) AND (department_id = 10))