QUERY PLAN
Limit (cost=157.93..157.98 rows=20 width=284)
-> Sort (cost=157.93..158.38 rows=181 width=284)
Sort Key: r.updated_at DESC
-> HashAggregate (cost=151.30..153.11 rows=181 width=284)
Group Key: r.id
-> Hash Right Join (cost=102.97..150.85 rows=181 width=284)
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=101.03..101.03 rows=155 width=284)
-> Hash Right Join (cost=78.77..101.03 rows=155 width=284)
Hash Cond: (rvr.erp_sales_order_id = r.id)
Filter: ((r.created_by = 1004) OR (rvr.user_id = 1004) OR (r.created_by = 1004))
-> 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=284)
-> Seq Scan on tbl_erp_sales_orders r (cost=0.00..59.28 rows=1559 width=284)
Filter: ((status <> 0) OR ((status = 0) AND (created_by = 1004)))