QUERY PLAN
Aggregate (cost=1262.49..1262.50 rows=1 width=8)
-> Sort (cost=1262.45..1262.46 rows=3 width=65)
Sort Key: start_at
-> Nested Loop (cost=0.00..1262.43 rows=3 width=65)
-> Seq Scan on tbl_users u (cost=0.00..8.16 rows=1 width=4)
Filter: ((id = 1015) AND (department_id = 2))
-> Append (cost=0.00..1254.21 rows=3 width=65)
-> Result (cost=0.00..0.00 rows=0 width=49)
One-Time Filter: false
-> Result (cost=0.00..1254.21 rows=2 width=65)
-> Append (cost=0.00..1254.19 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..1254.19 rows=1 width=65)
-> Seq Scan on tbl_calendars c (cost=0.00..1254.18 rows=1 width=77)
Filter: ((created_by = 1015) AND (created_by = ANY ('{1015,1015,1023,1022,5248}'::integer[])) AND (((is_public = 1) AND (created_by <> 1015)) OR (created_by = 1015)) AND (((start_at >= '2026-07-15 00:00:00+08'::timestamp with time zone) AND (end_at < '2026-07-15 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2026-07-15 00:00:00+08'::timestamp with time zone) AND (end_at > '2026-07-15 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2026-07-15 23:59:59+08'::timestamp with time zone) AND (end_at > '2026-07-15 23:59:59+08'::timestamp with time zone))) AND (((start_at >= '2026-07-15 00:00:00+08'::timestamp with time zone) AND (end_at < '2026-07-15 23:59:59+08'::timestamp with time zone)) OR ((start_at <= '2026-07-15 00:00:00+08'::timestamp with time zone) AND (end_at > '2026-07-15 00:00:00+08'::timestamp with time zone)) OR ((start_at <= '2026-07-15 23:59:59+08'::timestamp with time zone) AND (end_at > '2026-07-15 23:59:59+08'::timestamp with time zone))))