| Append (cost=1943.07..2490.77 rows=3 width=318) |
| -> Subquery Scan on "*SELECT* 1" (cost=1943.07..1943.13 rows=1 width=318) |
| -> Unique (cost=1943.07..1943.12 rows=1 width=358) |
| -> Sort (cost=1943.07..1943.08 rows=1 width=358) |
| Sort Key: a.client_id, ((a.end_at - a.start_at)), a.created_by, a.start_at, a.end_at, a.created_at, a.location_id, (CASE WHEN (a.location_in_id IS NOT NULL) THEN lin.geolocation[0] ELSE lout.geolocation[0] END), (CASE WHEN (a.location_in_id IS NOT NULL) THEN lin.geolocation[1] ELSE lout.geolocation[1] END), (CASE WHEN (p.id IS NULL) THEN false ELSE true END), c.name, ct.name, cc.name, sales.name, lin.address, a.indistance, d.name, u.name, meta.meta_value |
| -> Group (cost=1943.03..1943.06 rows=1 width=358) |
| Group Key: a.id, lin.id, lout.id, p.id, ct.id, sales.id, cc.id, d.id, u.id, c.id, meta.meta_value |
| -> Sort (cost=1943.03..1943.03 rows=1 width=357) |
| Sort Key: a.id, lin.id, lout.id, p.id, ct.id, sales.id, cc.id, d.id, u.id, c.id, meta.meta_value |
| -> Nested Loop Left Join (cost=1.13..1943.02 rows=1 width=357) |
| Join Filter: (meta.user_id = u.id) |
| -> Nested Loop Left Join (cost=1.13..1938.49 rows=1 width=286) |
| Join Filter: (c.sales_rep = sales.id) |
| -> Nested Loop Left Join (cost=1.13..1929.25 rows=1 width=277) |
| Join Filter: (ct.id = c.client_type) |
| -> Nested Loop Left Join (cost=1.13..1928.12 rows=1 width=253) |
| Join Filter: (cc.id = c.client_class) |
| -> Nested Loop Left Join (cost=1.13..1927.03 rows=1 width=240) |
| -> Nested Loop Left Join (cost=0.85..1926.35 rows=1 width=236) |
| -> Nested Loop Left Join (cost=0.57..1918.05 rows=1 width=179) |
| Join Filter: (u.department_id = d.id) |
| -> Nested Loop Left Join (cost=0.57..1916.85 rows=1 width=169) |
| Join Filter: (a.created_by = u.id) |
| -> Nested Loop Left Join (cost=0.57..1907.61 rows=1 width=152) |
| -> Nested Loop Left Join (cost=0.29..1899.30 rows=1 width=136) |
| -> Seq Scan on tbl_work_logs a (cost=0.00..1890.99 rows=1 width=56) |
| Filter: ((client_id IS NOT NULL) AND ((location_in_id IS NOT NULL) OR (location_out_id IS NOT NULL)) AND (location_in_id IS NOT NULL) AND (location_out_id IS NULL) AND (start_at >= '2026-06-29 00:00:00+08'::timestamp with time zone) AND (start_at <= '2026-06-29 23:59:59+08'::timestamp with time zone)) |
| -> Index Scan using tbl_location_pkey on tbl_location lin (cost=0.29..8.30 rows=1 width=80) |
| Index Cond: (a.location_in_id = id) |
| -> Index Scan using tbl_location_pkey on tbl_location lout (cost=0.29..8.30 rows=1 width=20) |
| Index Cond: (a.location_out_id = id) |
| -> Seq Scan on tbl_users u (cost=0.00..7.44 rows=144 width=17) |
| -> Seq Scan on tbl_departments d (cost=0.00..1.09 rows=9 width=14) |
| -> Index Scan using tbl_clients_pkey on tbl_clients c (cost=0.28..8.29 rows=1 width=57) |
| Index Cond: (id = a.client_id) |
| -> Index Scan using tbl_projects_client_id_idx on tbl_projects p (cost=0.28..0.65 rows=2 width=8) |
| Index Cond: (client_id = c.id) |
| Filter: (project_status = 3) |
| -> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=17) |
| -> Seq Scan on tbl_client_types ct (cost=0.00..1.06 rows=6 width=28) |
| -> Seq Scan on tbl_users sales (cost=0.00..7.44 rows=144 width=13) |
| -> Seq Scan on tbl_user_meta meta (cost=0.00..3.26 rows=101 width=75) |
| Filter: ((meta_key)::text = 'avatar'::text) |
| -> Subquery Scan on "*SELECT* 2" (cost=133.31..133.37 rows=1 width=318) |
| -> Unique (cost=133.31..133.36 rows=1 width=358) |
| -> Sort (cost=133.31..133.31 rows=1 width=358) |
| Sort Key: a_1.client_id, ((a_1.end_at - a_1.start_at)), a_1.created_by, a_1.start_at, a_1.end_at, a_1.created_at, a_1.location_id, (CASE WHEN (a_1.location_in_id IS NOT NULL) THEN lin_1.geolocation[0] ELSE lout_1.geolocation[0] END), (CASE WHEN (a_1.location_in_id IS NOT NULL) THEN lin_1.geolocation[1] ELSE lout_1.geolocation[1] END), (CASE WHEN (p_1.id IS NULL) THEN false ELSE true END), c_1.name, ct_1.name, cc_1.name, sales_1.name, lin_1.address, a_1.indistance, d_1.name, u_1.name, meta_1.meta_value |
| -> Group (cost=133.26..133.30 rows=1 width=358) |
| Group Key: a_1.id, lin_1.id, lout_1.id, p_1.id, ct_1.id, sales_1.id, cc_1.id, d_1.id, u_1.id, c_1.id, meta_1.meta_value |
| -> Sort (cost=133.26..133.27 rows=1 width=357) |
| Sort Key: a_1.id, lin_1.id, lout_1.id, p_1.id, ct_1.id, sales_1.id, cc_1.id, d_1.id, u_1.id, c_1.id, meta_1.meta_value |
| -> Nested Loop Left Join (cost=1.70..133.25 rows=1 width=357) |
| -> Nested Loop Left Join (cost=1.56..132.98 rows=1 width=286) |
| -> Nested Loop Left Join (cost=1.41..132.80 rows=1 width=277) |
| Join Filter: (ct_1.id = c_1.client_type) |
| -> Nested Loop Left Join (cost=1.41..131.66 rows=1 width=253) |
| -> Nested Loop Left Join (cost=1.13..123.23 rows=1 width=226) |
| Join Filter: (cc_1.id = c_1.client_class) |
| -> Nested Loop Left Join (cost=1.13..122.14 rows=1 width=213) |
| -> Nested Loop Left Join (cost=0.85..121.47 rows=1 width=209) |
| -> Nested Loop Left Join (cost=0.57..113.17 rows=1 width=152) |
| -> Nested Loop Left Join (cost=0.29..104.86 rows=1 width=136) |
| -> Seq Scan on tbl_pre_sales a_1 (cost=0.00..96.56 rows=1 width=56) |
| Filter: ((client_id IS NOT NULL) AND ((location_in_id IS NOT NULL) OR (location_out_id IS NOT NULL)) AND (location_in_id IS NOT NULL) AND (location_out_id IS NULL) AND (start_at >= '2026-06-29 00:00:00+08'::timestamp with time zone) AND (start_at <= '2026-06-29 23:59:59+08'::timestamp with time zone)) |
| -> Index Scan using tbl_location_pkey on tbl_location lin_1 (cost=0.29..8.30 rows=1 width=80) |
| Index Cond: (a_1.location_in_id = id) |
| -> Index Scan using tbl_location_pkey on tbl_location lout_1 (cost=0.29..8.30 rows=1 width=20) |
| Index Cond: (a_1.location_out_id = id) |
| -> Index Scan using tbl_clients_pkey on tbl_clients c_1 (cost=0.28..8.29 rows=1 width=57) |
| Index Cond: (id = a_1.client_id) |
| -> Index Scan using tbl_projects_client_id_idx on tbl_projects p_1 (cost=0.28..0.65 rows=2 width=8) |
| Index Cond: (client_id = c_1.id) |
| Filter: (project_status = 3) |
| -> Seq Scan on tbl_client_classes cc_1 (cost=0.00..1.04 rows=4 width=17) |
| -> Nested Loop Left Join (cost=0.28..8.42 rows=1 width=27) |
| -> Index Scan using tbl_users_pkey on tbl_users u_1 (cost=0.14..8.16 rows=1 width=17) |
| Index Cond: (a_1.created_by = id) |
| -> Index Scan using tbl_departments_pkey on tbl_departments d_1 (cost=0.14..0.24 rows=1 width=14) |
| Index Cond: (u_1.department_id = id) |
| -> Seq Scan on tbl_client_types ct_1 (cost=0.00..1.06 rows=6 width=28) |
| -> Index Scan using tbl_users_pkey on tbl_users sales_1 (cost=0.14..0.18 rows=1 width=13) |
| Index Cond: (c_1.sales_rep = id) |
| -> Index Scan using tbl_user_meta_pkey on tbl_user_meta meta_1 (cost=0.14..0.27 rows=1 width=75) |
| Index Cond: ((user_id = u_1.id) AND ((meta_key)::text = 'avatar'::text)) |
| -> Subquery Scan on "*SELECT* 3" (cost=414.20..414.26 rows=1 width=318) |
| -> Unique (cost=414.20..414.25 rows=1 width=358) |
| -> Sort (cost=414.20..414.21 rows=1 width=358) |
| Sort Key: a_2.client_id, ((a_2.left_at - a_2.arrived_at)), a_2.created_by, a_2.arrived_at, a_2.left_at, a_2.created_at, a_2.location_id, (CASE WHEN (a_2.location_in_id IS NOT NULL) THEN lin_2.geolocation[0] ELSE lout_2.geolocation[0] END), (CASE WHEN (a_2.location_in_id IS NOT NULL) THEN lin_2.geolocation[1] ELSE lout_2.geolocation[1] END), (CASE WHEN (p_2.id IS NULL) THEN false ELSE true END), c_2.name, ct_2.name, cc_2.name, sales_2.name, lin_2.address, a_2.indistance, d_2.name, u_2.name, meta_2.meta_value |
| -> Group (cost=414.16..414.19 rows=1 width=358) |
| Group Key: a_2.id, lin_2.id, lout_2.id, p_2.id, ct_2.id, sales_2.id, cc_2.id, d_2.id, u_2.id, c_2.id, meta_2.meta_value |
| -> Sort (cost=414.16..414.16 rows=1 width=357) |
| Sort Key: a_2.id, lin_2.id, lout_2.id, p_2.id, ct_2.id, sales_2.id, cc_2.id, d_2.id, u_2.id, c_2.id, meta_2.meta_value |
| -> Nested Loop Left Join (cost=1.42..414.15 rows=1 width=357) |
| -> Nested Loop Left Join (cost=1.28..413.87 rows=1 width=286) |
| -> Nested Loop Left Join (cost=1.13..413.69 rows=1 width=277) |
| Join Filter: (ct_2.id = c_2.client_type) |
| -> Nested Loop Left Join (cost=1.13..412.56 rows=1 width=253) |
| Join Filter: (cc_2.id = c_2.client_class) |
| -> Nested Loop Left Join (cost=1.13..411.47 rows=1 width=240) |
| -> Nested Loop Left Join (cost=0.85..410.79 rows=1 width=236) |
| -> Nested Loop Left Join (cost=0.57..402.49 rows=1 width=179) |
| Join Filter: (u_2.department_id = d_2.id) |
| -> Nested Loop Left Join (cost=0.57..401.29 rows=1 width=169) |
| Join Filter: (a_2.created_by = u_2.id) |
| -> Nested Loop Left Join (cost=0.57..392.05 rows=1 width=152) |
| -> Nested Loop Left Join (cost=0.29..383.74 rows=1 width=136) |
| -> Seq Scan on tbl_implement_records a_2 (cost=0.00..375.44 rows=1 width=56) |
| Filter: ((client_id IS NOT NULL) AND ((location_in_id IS NOT NULL) OR (location_out_id IS NOT NULL)) AND (location_in_id IS NOT NULL) AND (location_out_id IS NULL) AND (arrived_at >= '2026-06-29 00:00:00+08'::timestamp with time zone) AND (arrived_at <= '2026-06-29 23:59:59+08'::timestamp with time zone)) |
| -> Index Scan using tbl_location_pkey on tbl_location lin_2 (cost=0.29..8.30 rows=1 width=80) |
| Index Cond: (a_2.location_in_id = id) |
| -> Index Scan using tbl_location_pkey on tbl_location lout_2 (cost=0.29..8.30 rows=1 width=20) |
| Index Cond: (a_2.location_out_id = id) |
| -> Seq Scan on tbl_users u_2 (cost=0.00..7.44 rows=144 width=17) |
| -> Seq Scan on tbl_departments d_2 (cost=0.00..1.09 rows=9 width=14) |
| -> Index Scan using tbl_clients_pkey on tbl_clients c_2 (cost=0.28..8.29 rows=1 width=57) |
| Index Cond: (id = a_2.client_id) |
| -> Index Scan using tbl_projects_client_id_idx on tbl_projects p_2 (cost=0.28..0.65 rows=2 width=8) |
| Index Cond: (client_id = c_2.id) |
| Filter: (project_status = 3) |
| -> Seq Scan on tbl_client_classes cc_2 (cost=0.00..1.04 rows=4 width=17) |
| -> Seq Scan on tbl_client_types ct_2 (cost=0.00..1.06 rows=6 width=28) |
| -> Index Scan using tbl_users_pkey on tbl_users sales_2 (cost=0.14..0.18 rows=1 width=13) |
| Index Cond: (c_2.sales_rep = id) |
| -> Index Scan using tbl_user_meta_pkey on tbl_user_meta meta_2 (cost=0.14..0.27 rows=1 width=75) |
| Index Cond: ((user_id = u_2.id) AND ((meta_key)::text = 'avatar'::text)) |