QUERY PLAN
GroupAggregate (cost=119.41..119.46 rows=1 width=556)
Group Key: c.id, (CASE WHEN (p.id IS NULL) THEN false ELSE true END), cc.notice_days
-> Sort (cost=119.41..119.41 rows=1 width=540)
Sort Key: (CASE WHEN (p.id IS NULL) THEN false ELSE true END), cc.notice_days
-> Nested Loop Left Join (cost=13.36..119.40 rows=1 width=540)
Join Filter: (cc.id = c.client_class)
-> Nested Loop Left Join (cost=13.36..118.31 rows=1 width=541)
Join Filter: (sl.client_id = c.id)
-> Nested Loop Left Join (cost=8.97..65.47 rows=1 width=533)
Join Filter: (p.client_id = c.id)
-> Nested Loop Left Join (cost=4.68..53.85 rows=1 width=529)
Join Filter: (arrive.client_id = c.id)
-> Index Scan using tbl_clients_pkey on tbl_clients c (cost=0.28..8.29 rows=1 width=521)
Index Cond: (id = 1661)
Filter: (NOT deleted)
-> Bitmap Heap Scan on tbl_work_logs arrive (cost=4.40..45.55 rows=1 width=12)
Recheck Cond: ((client_id IS NOT NULL) AND (client_id = 1661))
Filter: ((NOT is_draft) AND (location_in_id IS NOT NULL) AND (location_out_id IS NOT NULL) AND (scenario_id = 1))
-> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..4.40 rows=11 width=0)
Index Cond: ((client_id IS NOT NULL) AND (client_id = 1661))
-> Bitmap Heap Scan on tbl_projects p (cost=4.30..11.60 rows=1 width=8)
Recheck Cond: (client_id = 1661)
Filter: (project_status = 3)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.29 rows=2 width=0)
Index Cond: (client_id = 1661)
-> Bitmap Heap Scan on tbl_work_logs sl (cost=4.39..52.68 rows=13 width=12)
Recheck Cond: (client_id = 1661)
-> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..4.39 rows=13 width=0)
Index Cond: (client_id = 1661)
-> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=6)