QUERY PLAN
Subquery Scan on sub (cost=172.94..173.84 rows=1 width=360)
Filter: (sub.id = 1)
-> WindowAgg (cost=172.94..173.47 rows=30 width=360)
-> Sort (cost=172.94..173.02 rows=30 width=352)
Sort Key: sub_1.updated_at DESC
-> Subquery Scan on sub_1 (cost=171.76..172.21 rows=30 width=352)
-> Group (cost=171.76..171.91 rows=30 width=352)
Group Key: r.id
-> Sort (cost=171.76..171.83 rows=30 width=352)
Sort Key: r.id
-> Hash Left Join (cost=146.19..171.02 rows=30 width=352)
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=16.29..38.59 rows=965 width=356)
Hash Cond: (rvr.erp_sales_return_id = r.id)
-> Seq Scan on tbl_erp_sales_return_verify_rels rvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=13.68..13.68 rows=209 width=352)
-> Seq Scan on tbl_erp_sales_returns r (cost=0.00..13.68 rows=209 width=352)
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)