QUERY PLAN
Aggregate (cost=190.10..190.11 rows=1 width=8)
-> Sort (cost=189.35..189.48 rows=50 width=362)
Sort Key: r.created_at DESC
-> Group (cost=187.69..187.94 rows=50 width=362)
Group Key: r.id
-> Sort (cost=187.69..187.82 rows=50 width=12)
Sort Key: r.id
-> Hash Right Join (cost=171.09..186.28 rows=50 width=12)
Hash Cond: (epop.erp_sales_outbound_id = r.id)
-> Seq Scan on tbl_erp_sales_outbound_products epop (cost=0.00..13.40 rows=340 width=8)
-> Hash (cost=170.72..170.72 rows=30 width=12)
-> Hash Left Join (cost=145.88..170.72 rows=30 width=12)
Hash Cond: (r.client_id = client.id)
Filter: ((client.sales_rep = 1004) OR (r.created_by = 1004) OR (rvr.user_id = 1004) OR (r.created_by = 1004))
-> Hash Right Join (cost=15.99..38.29 rows=965 width=24)
Hash Cond: (rvr.erp_sales_outbound_id = r.id)
-> Seq Scan on tbl_erp_sales_outbound_verify_rels rvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=13.50..13.50 rows=199 width=20)
-> Seq Scan on tbl_erp_sales_outbounds r (cost=0.00..13.50 rows=199 width=20)
Filter: ((status <> 0) OR ((status = 0) AND (created_by = 1004)))
-> Hash (cost=105.51..105.51 rows=1951 width=8)
-> Seq Scan on tbl_clients client (cost=0.00..105.51 rows=1951 width=8)