QUERY PLAN
Aggregate (cost=30.69..30.70 rows=1 width=32)
-> Sort (cost=30.67..30.67 rows=1 width=1158)
Sort Key: sc.signed_at DESC
-> Group (cost=30.64..30.66 rows=1 width=1158)
Group Key: sc.id, t0.erp_settle_amount
-> Sort (cost=30.64..30.65 rows=1 width=72)
Sort Key: sc.id, t0.erp_settle_amount
-> Nested Loop (cost=21.81..30.63 rows=1 width=72)
-> Hash Right Join (cost=21.68..22.47 rows=1 width=76)
Hash Cond: (t0.id = sc.id)
-> HashAggregate (cost=10.79..11.14 rows=35 width=36)
Group Key: t0.id
-> Seq Scan on tbl_sales_contracts t0 (cost=0.00..10.70 rows=35 width=36)
Filter: need_analysis
-> Hash (cost=10.88..10.88 rows=1 width=44)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..10.88 rows=1 width=44)
Filter: (need_analysis AND (client_id = 1))
-> Index Scan using tbl_clients_pkey on tbl_clients c (cost=0.14..8.16 rows=1 width=4)
Index Cond: (id = 1)
Filter: ((sales_rep = 5493) OR (sales_rep IS NULL))