QUERY PLAN
Subquery Scan on sub (cost=123.62..130.09 rows=1 width=379)
Filter: (sub.id = 1)
-> WindowAgg (cost=123.62..127.60 rows=199 width=379)
-> Sort (cost=123.62..124.12 rows=199 width=371)
Sort Key: sub_1.need_verify_sort, sub_1.created_at DESC
-> Subquery Scan on sub_1 (cost=112.04..116.02 rows=199 width=371)
-> HashAggregate (cost=112.04..114.03 rows=199 width=371)
Group Key: r.id
-> Hash Right Join (cost=69.67..98.88 rows=585 width=375)
Hash Cond: (rsvr.erp_sales_outbound_id = r.id)
-> Seq Scan on tbl_erp_sales_outbound_stop_verify_rels rsvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=68.16..68.16 rows=121 width=371)
-> Hash Right Join (cost=52.27..68.16 rows=121 width=371)
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=51.38..51.38 rows=71 width=371)
-> Hash Left Join (cost=26.44..51.38 rows=71 width=371)
Hash Cond: (r.client_id = client.id)
Filter: ((client.sales_rep = 5495) OR (r.created_by = 5495) OR (rvr.user_id = 5495) OR (r.created_by = ANY ('{5493,5495,5495}'::integer[])))
-> Hash Right Join (cost=15.99..38.29 rows=965 width=375)
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=12)
-> Hash (cost=13.50..13.50 rows=199 width=367)
-> Seq Scan on tbl_erp_sales_outbounds r (cost=0.00..13.50 rows=199 width=367)
Filter: ((status <> 0) OR ((status = 0) AND (created_by = 5495)))
-> Hash (cost=10.20..10.20 rows=20 width=8)
-> Seq Scan on tbl_clients client (cost=0.00..10.20 rows=20 width=8)