QUERY PLAN
Aggregate (cost=2356.96..2356.97 rows=1 width=8)
-> Hash Left Join (cost=2161.75..2355.65 rows=524 width=0)
Hash Cond: (c.id = sub_c.id)
Filter: ((((date_part('epoch'::text, (CURRENT_TIMESTAMP - max(sl.end_at))) / '86400'::double precision)) > ((cc.notice_days - 1))::double precision) OR (((date_part('epoch'::text, (CURRENT_TIMESTAMP - max(sl.end_at))) / '86400'::double precision)) IS NULL))
-> Hash Left Join (cost=1.09..190.88 rows=1557 width=6)
Hash Cond: (c.client_class = cc.id)
-> Seq Scan on tbl_clients c (cost=0.00..183.14 rows=1557 width=8)
Filter: ((NOT deleted) AND (sales_rep = 1001))
-> Hash (cost=1.04..1.04 rows=4 width=6)
-> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=6)
-> Hash (cost=2141.19..2141.19 rows=1557 width=12)
-> HashAggregate (cost=2094.48..2125.62 rows=1557 width=12)
Group Key: sub_c.id
-> Hash Right Join (cost=202.60..1954.89 rows=27918 width=12)
Hash Cond: (sl.client_id = sub_c.id)
-> Seq Scan on tbl_work_logs sl (cost=0.00..1661.24 rows=34624 width=12)
-> Hash (cost=183.14..183.14 rows=1557 width=4)
-> Seq Scan on tbl_clients sub_c (cost=0.00..183.14 rows=1557 width=4)
Filter: ((NOT deleted) AND (sales_rep = 1001))