QUERY PLAN
GroupAggregate (cost=1415.94..1415.99 rows=1 width=540)
Group Key: c.id, (CASE WHEN (p.id IS NULL) THEN false ELSE true END), cc.notice_days
-> Sort (cost=1415.94..1415.94 rows=1 width=524)
Sort Key: (CASE WHEN (p.id IS NULL) THEN false ELSE true END), cc.notice_days
-> Nested Loop Left Join (cost=17.99..1415.93 rows=1 width=524)
Join Filter: (cc.id = c.client_class)
-> Nested Loop Left Join (cost=17.99..1414.84 rows=1 width=525)
Join Filter: (sl.client_id = c.id)
-> Nested Loop Left Join (cost=11.47..705.99 rows=1 width=517)
Join Filter: (p.client_id = c.id)
-> Nested Loop Left Join (cost=7.00..636.75 rows=1 width=513)
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=505)
Index Cond: (id = 518)
Filter: (NOT deleted)
-> Bitmap Heap Scan on tbl_work_logs arrive (cost=6.72..628.43 rows=2 width=12)
Recheck Cond: ((client_id IS NOT NULL) AND (client_id = 518))
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..6.72 rows=243 width=0)
Index Cond: ((client_id IS NOT NULL) AND (client_id = 518))
-> Bitmap Heap Scan on tbl_projects p (cost=4.47..69.08 rows=13 width=8)
Recheck Cond: (client_id = 518)
Filter: (project_status = 3)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.47 rows=25 width=0)
Index Cond: (client_id = 518)
-> Bitmap Heap Scan on tbl_work_logs sl (cost=6.52..705.25 rows=288 width=12)
Recheck Cond: (client_id = 518)
-> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..6.45 rows=288 width=0)
Index Cond: (client_id = 518)
-> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=6)