QUERY PLAN
Limit (cost=127.12..127.17 rows=20 width=206)
-> Sort (cost=127.12..127.35 rows=91 width=206)
Sort Key: (CASE WHEN ((sub.verify_status = 0) OR (sub.stop_verify_status = 0) OR (sub.cancel_verify_status = 0)) THEN 1 ELSE 2 END), sub.created_at DESC
-> Result (cost=0.00..124.70 rows=91 width=206)
-> Append (cost=0.00..123.11 rows=91 width=202)
-> Subquery Scan on sub (cost=0.00..0.04 rows=1 width=156)
-> HashAggregate (cost=0.00..0.03 rows=1 width=164)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=81)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 2" (cost=118.73..121.99 rows=65 width=188)
-> HashAggregate (cost=118.73..121.34 rows=65 width=200)
Group Key: r.id, rvr.status, rsvr.status, rcvr.status
-> Hash Left Join (cost=25.56..118.08 rows=65 width=121)
Hash Cond: (r.id = rsvr.erp_purchase_order_id)
Filter: ((CASE WHEN (1 = r.verify_type) THEN rvr.status ELSE CASE WHEN (r.next_verify_user = 5064) THEN 0 ELSE CASE WHEN (rvr.status = 0) THEN NULL::integer ELSE rvr.status END END END = 1) OR (CASE WHEN (1 = r.verify_type) THEN rsvr.status ELSE CASE WHEN (r.next_stop_verify_user = 5064) THEN 0 ELSE CASE WHEN (rsvr.status = 0) THEN NULL::integer ELSE rsvr.status END END END = 1) OR (CASE WHEN (1 = r.verify_type) THEN rcvr.status ELSE CASE WHEN (r.next_cancel_verify_user = 5064) THEN 0 ELSE CASE WHEN (rcvr.status = 0) THEN NULL::integer ELSE rcvr.status END END END = 1) OR (CASE WHEN (1 = r.verify_type) THEN rvr.status ELSE CASE WHEN (r.next_verify_user = 5064) THEN 0 ELSE CASE WHEN (rvr.status = 0) THEN NULL::integer ELSE rvr.status END END END = 2) OR (CASE WHEN (1 = r.verify_type) THEN rsvr.status ELSE CASE WHEN (r.next_stop_verify_user = 5064) THEN 0 ELSE CASE WHEN (rsvr.status = 0) THEN NULL::integer ELSE rsvr.status END END END = 2) OR (CASE WHEN (1 = r.verify_type) THEN rcvr.status ELSE CASE WHEN (r.next_cancel_verify_user = 5064) THEN 0 ELSE CASE WHEN (rcvr.status = 0) THEN NULL::integer ELSE rcvr.status END END END = 2))
-> Hash Left Join (cost=24.48..108.66 rows=2206 width=117)
Hash Cond: (r.id = rcvr.erp_purchase_order_id)
-> Hash Left Join (cost=2.29..78.14 rows=2206 width=113)
Hash Cond: (r.id = rvr.erp_purchase_order_id)
-> Seq Scan on tbl_erp_purchase_orders r (cost=0.00..67.58 rows=2206 width=109)
Filter: (status <> 0)
-> Hash (cost=2.28..2.28 rows=1 width=8)
-> Seq Scan on tbl_erp_purchase_order_verify_rels rvr (cost=0.00..2.28 rows=1 width=8)
Filter: (user_id = 5064)
-> Hash (cost=22.12..22.12 rows=5 width=8)
-> Seq Scan on tbl_erp_purchase_order_cancel_verify_rels rcvr (cost=0.00..22.12 rows=5 width=8)
Filter: (user_id = 5064)
-> Hash (cost=1.07..1.07 rows=1 width=8)
-> Seq Scan on tbl_erp_purchase_order_stop_verify_rels rsvr (cost=0.00..1.07 rows=1 width=8)
Filter: (user_id = 5064)
-> Subquery Scan on "*SELECT* 3" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=222)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 4" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=218)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 5" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=218)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 6" (cost=0.00..0.05 rows=1 width=197)
-> HashAggregate (cost=0.00..0.04 rows=1 width=209)
Group Key: id, status, status, status
-> Result (cost=0.00..0.00 rows=0 width=130)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 7" (cost=0.00..0.04 rows=1 width=185)
-> HashAggregate (cost=0.00..0.03 rows=1 width=193)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=110)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 8" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=222)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 9" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=226)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 10" (cost=0.00..0.04 rows=1 width=176)
-> HashAggregate (cost=0.00..0.03 rows=1 width=184)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=105)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 11" (cost=0.00..0.04 rows=1 width=133)
-> HashAggregate (cost=0.00..0.03 rows=1 width=141)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=102)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 12" (cost=0.00..0.04 rows=1 width=141)
-> HashAggregate (cost=0.00..0.03 rows=1 width=149)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=111)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 13" (cost=0.00..0.04 rows=1 width=161)
-> HashAggregate (cost=0.00..0.03 rows=1 width=169)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=126)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 14" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=266)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 15" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=226)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 16" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=218)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 17" (cost=0.00..0.04 rows=1 width=149)
-> HashAggregate (cost=0.00..0.03 rows=1 width=157)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=111)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 18" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=259)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 19" (cost=0.00..0.04 rows=1 width=134)
-> HashAggregate (cost=0.00..0.03 rows=1 width=142)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=103)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 20" (cost=0.00..0.04 rows=1 width=154)
-> HashAggregate (cost=0.00..0.03 rows=1 width=162)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=123)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 21" (cost=0.00..0.05 rows=1 width=297)
-> HashAggregate (cost=0.00..0.04 rows=1 width=309)
Group Key: id, status, status, status
-> Result (cost=0.00..0.00 rows=0 width=230)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 22" (cost=0.00..0.04 rows=1 width=151)
-> HashAggregate (cost=0.00..0.03 rows=1 width=159)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=105)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 23" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=251)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 24" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=251)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 25" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=251)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 26" (cost=0.00..0.04 rows=1 width=297)
-> HashAggregate (cost=0.00..0.03 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=251)
One-Time Filter: false
-> Subquery Scan on "*SELECT* 27" (cost=0.00..0.05 rows=1 width=297)
-> HashAggregate (cost=0.00..0.04 rows=1 width=305)
Group Key: id, status, status
-> Result (cost=0.00..0.00 rows=0 width=195)
One-Time Filter: false