QUERY PLAN
Aggregate (cost=299.14..299.15 rows=1 width=8)
-> Sort (cost=296.02..296.54 rows=208 width=413)
Sort Key: r.updated_at DESC
-> HashAggregate (cost=285.93..288.01 rows=208 width=413)
Group Key: r.id
-> Hash Right Join (cost=237.26..285.41 rows=208 width=12)
Hash Cond: (epop.erp_sales_order_id = r.id)
-> Seq Scan on tbl_erp_sales_order_products epop (cost=0.00..39.23 rows=1823 width=8)
-> Hash (cost=235.04..235.04 rows=178 width=12)
-> Hash Left Join (cost=208.67..235.04 rows=178 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=78.77..101.03 rows=1559 width=24)
Hash Cond: (rvr.erp_sales_order_id = r.id)
-> Seq Scan on tbl_erp_sales_order_verify_rels rvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=59.28..59.28 rows=1559 width=20)
-> Seq Scan on tbl_erp_sales_orders r (cost=0.00..59.28 rows=1559 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)