QUERY PLAN
Group (cost=354.83..4499.73 rows=1 width=4)
Group Key: s.created_by
-> Nested Loop (cost=354.83..4499.73 rows=1 width=4)
Join Filter: (s.created_by = u.id)
-> Index Scan using tbl_users_pkey on tbl_users u (cost=0.14..34.61 rows=5 width=4)
Filter: (department_id = 8)
-> Materialize (cost=354.68..4464.75 rows=5 width=4)
-> Subquery Scan on s (cost=354.68..4464.73 rows=5 width=4)
-> Append (cost=354.68..4464.68 rows=5 width=65)
-> Nested Loop Left Join (cost=354.68..2937.44 rows=1 width=307)
Join Filter: (wlso.id = w.scenario_option_id)
-> Bitmap Heap Scan on tbl_work_logs w (cost=354.68..2935.56 rows=1 width=32)
Recheck Cond: (created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[]))
Filter: ((NOT is_draft) AND (((start_at >= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-09-10 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-09-10 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-09-10 23:59:59+08'::timestamp with time zone))) AND (((start_at >= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-09-10 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-09-10 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-09-10 23:59:59+08'::timestamp with time zone))))
-> Bitmap Index Scan on tbl_work_logs_created_by_idx (cost=0.00..354.68 rows=18084 width=0)
Index Cond: (created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[]))
-> Seq Scan on tbl_work_log_scenario_options wlso (cost=0.00..1.39 rows=39 width=278)
-> Result (cost=0.00..1527.23 rows=4 width=65)
-> Append (cost=0.00..1527.19 rows=4 width=65)
-> Result (cost=0.00..0.00 rows=0 width=109)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 3" (cost=0.00..1527.19 rows=3 width=65)
-> Seq Scan on tbl_calendars c (cost=0.00..1527.16 rows=3 width=78)
Filter: ((((is_public = 1) AND (created_by <> 1000)) OR (created_by = 1000)) AND (((start_at >= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-09-10 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-09-10 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-09-10 23:59:59+08'::timestamp with time zone))) AND (((start_at >= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-09-10 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-09-10 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-09-10 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-09-10 23:59:59+08'::timestamp with time zone))) AND (created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])))