QUERY PLAN
GroupAggregate (cost=177.71..178.82 rows=4 width=556)
Group Key: c.id, cc.id
-> Sort (cost=177.71..177.75 rows=17 width=564)
Sort Key: c.id, cc.id
-> Nested Loop Left Join (cost=9.24..177.36 rows=17 width=564)
-> Nested Loop Left Join (cost=4.77..86.10 rows=1 width=556)
Join Filter: (cc.id = c.client_class)
-> Nested Loop Left Join (cost=4.77..85.01 rows=1 width=510)
-> Index Scan using tbl_clients_pkey on tbl_clients c (cost=0.28..7.63 rows=1 width=502)
Index Cond: (id IS NULL)
Filter: (NOT deleted)
-> Bitmap Heap Scan on tbl_work_logs arrive (cost=4.49..77.37 rows=1 width=12)
Recheck Cond: ((client_id = c.id) AND (client_id IS NOT NULL))
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.49 rows=20 width=0)
Index Cond: ((client_id = c.id) AND (client_id IS NOT NULL))
-> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=46)
-> Bitmap Heap Scan on tbl_work_logs sl (cost=4.48..91.02 rows=24 width=12)
Recheck Cond: (client_id = c.id)
-> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..4.47 rows=24 width=0)
Index Cond: (client_id = c.id)