QUERY PLAN
Aggregate (cost=818.55..818.56 rows=1 width=8)
-> Sort (cost=817.65..817.80 rows=60 width=373)
Sort Key: (min(CASE WHEN (1 = r.verify_type) THEN CASE WHEN (rvr.status = 0) THEN 1 WHEN (rsvr.status = 0) THEN 2 ELSE 4 END ELSE CASE WHEN ((rvr.status = 0) AND (r.next_verify_user = 1011)) THEN 1 WHEN ((rsvr.status = 0) AND (r.next_stop_verify_user = 1011)) THEN 2 ELSE 4 END END)), r.created_at DESC
-> GroupAggregate (cost=813.78..815.88 rows=60 width=373)
Group Key: r.id
-> Sort (cost=813.78..813.93 rows=60 width=30)
Sort Key: r.id
-> Hash Left Join (cost=157.36..812.00 rows=60 width=30)
Hash Cond: (r.id = epop.erp_purchase_order_id)
-> Nested Loop Left Join (cost=154.90..808.92 rows=60 width=30)
Join Filter: (rvr.erp_purchase_order_id = r.id)
-> Hash Right Join (cost=154.90..805.18 rows=60 width=30)
Hash Cond: (cs.object_id = c.id)
-> Seq Scan on tbl_attachement_relationships cs (cost=0.00..642.56 rows=2022 width=4)
Filter: (object_type = 108)
-> Hash (cost=154.15..154.15 rows=60 width=34)
-> Hash Right Join (cost=81.33..154.15 rows=60 width=34)
Hash Cond: (c.id = r.purchase_contract_id)
-> Seq Scan on tbl_purchase_contracts c (cost=0.00..64.52 rows=2052 width=4)
-> Hash (cost=80.58..80.58 rows=60 width=34)
-> Hash Left Join (cost=2.10..80.58 rows=60 width=34)
Hash Cond: (r.id = rvr.erp_purchase_order_id)
Filter: ((r.created_by = 1011) OR (rvr.user_id = 1011) OR (r.created_by = ANY ('{5030,5351,5026,5203,5025,5072,5105,1004,5299,1001,5037,5446,1027,5045,5087,5094,5123,1008,1029,5048,5043,1025,1003,5208,5305,5078,1015,5449,5358,1023,5064,1026,5089,5027,1007,5258,5135,5076,5071,5209,1028,5083,5081,5033,5440,5229,5104,5359,5412,5393,5409,5062,5360,5247,5015,5023,5126,5124,1022,5022,5311,5248,5128,1000,5333,1006,1014,5093,5297,5249,5095,5082,1012,5070,5096,5420,5063,5102,5028,5259,5445,5448,5298,5075,5388,5230,5073,5404,1021,1030,5069,5066,5079,1020,5252,5364,5309,5411,5301,5049,5419,5044,1018,5088,5031,1013,5074,5413,5125,5101,5024,5300,1016,5293,5250,5047,5029,5304,5296,1005,1017,5050,1019,5080,5032,5085,5332,1011,1011,5065,1002,5086,5294,5357,5329,1010,5356,5016,5295,1009,5302,5303}'::integer[])))
-> Seq Scan on tbl_erp_purchase_orders r (cost=0.00..77.86 rows=63 width=30)
Filter: ((NOT inventory_status) AND (NOT is_done) AND (status = 2) AND ((status <> 0) OR ((status = 0) AND (created_by = 1011))))
-> Hash (cost=1.49..1.49 rows=49 width=12)
-> Seq Scan on tbl_erp_purchase_order_verify_rels rvr (cost=0.00..1.49 rows=49 width=12)
-> Materialize (cost=0.00..1.04 rows=3 width=4)
-> Seq Scan on tbl_erp_purchase_order_stop_verify_rels rsvr (cost=0.00..1.03 rows=3 width=4)
-> Hash (cost=1.65..1.65 rows=65 width=8)
-> Seq Scan on tbl_erp_purchase_order_products epop (cost=0.00..1.65 rows=65 width=8)