QUERY PLAN
Sort (cost=1851.40..1851.41 rows=3 width=65)
Sort Key: w.start_at
-> Nested Loop (cost=99.75..1851.38 rows=3 width=65)
-> Seq Scan on tbl_users u (cost=0.00..8.12 rows=1 width=4)
Filter: ((id = 1000) AND (department_id = 10))
-> Append (cost=99.75..1843.21 rows=3 width=65)
-> Nested Loop Left Join (cost=99.75..269.57 rows=1 width=307)
Join Filter: (wlso.id = w.scenario_option_id)
-> Bitmap Heap Scan on tbl_work_logs w (cost=99.75..267.69 rows=1 width=32)
Recheck Cond: ((created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1017,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])) AND (created_by = 1000))
Filter: ((NOT is_draft) AND (((start_at >= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-08-05 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-08-05 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-08-05 23:59:59+08'::timestamp with time zone))) AND (((start_at >= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-08-05 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-08-05 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-08-05 23:59:59+08'::timestamp with time zone))))
-> Bitmap Index Scan on tbl_work_logs_created_by_idx (cost=0.00..99.75 rows=48 width=0)
Index Cond: ((created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1017,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])) AND (created_by = 1000))
-> Seq Scan on tbl_work_log_scenario_options wlso (cost=0.00..1.39 rows=39 width=278)
-> Result (cost=0.00..1573.62 rows=2 width=65)
-> Append (cost=0.00..1573.60 rows=2 width=65)
-> Result (cost=0.00..0.00 rows=0 width=109)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 3" (cost=0.00..1573.60 rows=1 width=65)
-> Seq Scan on tbl_calendars c (cost=0.00..1573.59 rows=1 width=78)
Filter: ((created_by = 1000) AND (((is_public = 1) AND (created_by <> 1000)) OR (created_by = 1000)) AND (((start_at >= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-08-05 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-08-05 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-08-05 23:59:59+08'::timestamp with time zone))) AND (((start_at >= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at < '2025-08-05 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 00:00:00+08'::timestamp with time zone) AND (end_at > '2025-08-05 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2025-08-05 23:59:59+08'::timestamp with time zone) AND (end_at > '2025-08-05 23:59:59+08'::timestamp with time zone))) AND (created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1017,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])))