QUERY PLAN
Unique (cost=1852.10..1852.82 rows=58 width=24)
-> Sort (cost=1852.10..1852.24 rows=58 width=24)
Sort Key: c.id, c.client_class, c.created_at, ((date_part('epoch'::text, (CURRENT_TIMESTAMP - max(sl.end_at))) / '86400'::double precision))
-> HashAggregate (cost=1849.24..1850.40 rows=58 width=24)
Group Key: c.id
-> Hash Right Join (cost=87.76..1844.03 rows=1042 width=24)
Hash Cond: (sl.client_id = c.id)
-> Seq Scan on tbl_work_logs sl (cost=0.00..1665.01 rows=34701 width=12)
-> Hash (cost=87.03..87.03 rows=58 width=16)
-> Bitmap Heap Scan on tbl_clients c (cost=4.73..87.03 rows=58 width=16)
Recheck Cond: (sales_rep = 1001)
Filter: (NOT deleted)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.71 rows=58 width=0)
Index Cond: (sales_rep = 1001)