QUERY PLAN
Subquery Scan on sub (cost=233.98..265.63 rows=5 width=292)
Filter: (sub.id = 2)
-> WindowAgg (cost=233.98..252.44 rows=1055 width=292)
-> Sort (cost=233.98..236.61 rows=1055 width=284)
Sort Key: sub_1.created_at DESC
-> Subquery Scan on sub_1 (cost=159.90..181.00 rows=1055 width=284)
-> HashAggregate (cost=159.90..170.45 rows=1055 width=284)
Group Key: r.id
-> Hash Right Join (cost=100.65..157.26 rows=1055 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=89.37..89.37 rows=902 width=284)
-> Hash Right Join (cost=67.08..89.37 rows=902 width=284)
Hash Cond: (rvr.erp_sales_order_id = r.id)
Filter: ((r.created_by = 1001) OR (rvr.user_id = 1001) OR (r.created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1017,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])))
-> Seq Scan on tbl_erp_sales_order_verify_rels rvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=47.59..47.59 rows=1559 width=284)
-> Seq Scan on tbl_erp_sales_orders r (cost=0.00..47.59 rows=1559 width=284)