QUERY PLAN
Unique (cost=1776.19..1776.63 rows=35 width=24)
-> Sort (cost=1776.19..1776.28 rows=35 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=1774.59..1775.29 rows=35 width=24)
Group Key: c.id
-> Hash Right Join (cost=72.57..1771.51 rows=617 width=24)
Hash Cond: (sl.client_id = c.id)
-> Seq Scan on tbl_work_logs sl (cost=0.00..1610.45 rows=33645 width=12)
-> Hash (cost=72.14..72.14 rows=35 width=16)
-> Bitmap Heap Scan on tbl_clients c (cost=4.55..72.14 rows=35 width=16)
Recheck Cond: (sales_rep = 5300)
Filter: (NOT deleted)
-> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.54 rows=35 width=0)
Index Cond: (sales_rep = 5300)