QUERY PLAN
Limit (cost=42.28..42.33 rows=20 width=258)
-> Sort (cost=42.28..42.40 rows=50 width=258)
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 = 1001)) THEN 1 WHEN ((rsvr.status = 0) AND (r.next_stop_verify_user = 1001)) THEN 2 ELSE 4 END END)), r.created_at DESC
-> HashAggregate (cost=40.45..40.95 rows=50 width=258)
Group Key: r.id
-> Hash Right Join (cost=15.75..39.32 rows=50 width=262)
Hash Cond: (rsvr.erp_purchase_inbound_id = r.id)
-> Seq Scan on tbl_erp_purchase_inbound_stop_verify_rels rsvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=15.68..15.68 rows=5 width=258)
-> Hash Right Join (cost=9.10..15.68 rows=5 width=258)
Hash Cond: (rvr.erp_purchase_inbound_id = r.id)
Filter: ((r.created_by = 1001) OR (rvr.user_id = 1001) OR (r.created_by = ANY ('{1000,1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1011,1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,1022,1023,1025,1026,1027,1028,1029,1030,5015,5016,5022,5023,5024,5025,5026,5027,5028,5029,5030,5031,5032,5033,5037,5043,5044,5045,5047,5048,5049,5050,5062,5063,5064,5065,5066,5069,5070,5071,5072,5073,5074,5075,5076,5078,5079,5080,5081,5082,5083,5085,5086,5087,5088,5089,5093,5094,5095,5096,5101,5102,5104,5105,5123,5124,5125,5126,5128,5135,5203,5208,5209,5229,5230,5247,5248,5249,5250,5252,5258,5259,5293,5294,5295,5296,5297,5298,5299,5300,5301,5302,5303,5304,5305,5309,5311,5329,5332,5333,5351,5356,5357,5358,5359,5360,5364,5388,5393,5404,5409,5411,5412,5413,5419,5420,5440,5445,5446,5448,5449}'::integer[])))
-> Seq Scan on tbl_erp_purchase_inbound_verify_rels rvr (cost=0.00..4.64 rows=264 width=12)
-> Hash (cost=9.07..9.07 rows=2 width=254)
-> Nested Loop (cost=8.42..9.07 rows=2 width=254)
-> Unique (cost=8.28..8.29 rows=2 width=4)
-> Sort (cost=8.28..8.28 rows=2 width=4)
Sort Key: tbl_erp_inventory_products.erp_purchase_inbound_id
-> Nested Loop (cost=7.71..8.27 rows=2 width=4)
-> Unique (cost=7.56..7.57 rows=2 width=4)
-> Sort (cost=7.56..7.57 rows=2 width=4)
Sort Key: tbl_erp_sales_outbound_spent_products.erp_inventory_product_id
-> Hash Join (cost=3.85..7.55 rows=2 width=4)
Hash Cond: (tbl_erp_sales_outbound_spent_products.erp_sales_outbound_id = tbl_erp_sales_outbounds.id)
-> Seq Scan on tbl_erp_sales_outbound_spent_products (cost=0.00..3.33 rows=133 width=8)
-> Hash (cost=3.84..3.84 rows=1 width=4)
-> Seq Scan on tbl_erp_sales_outbounds (cost=0.00..3.84 rows=1 width=4)
Filter: (erp_sales_order_id = 1620)
-> Index Scan using tbl_erp_inventory_products_pkey on tbl_erp_inventory_products (cost=0.14..0.35 rows=1 width=8)
Index Cond: (id = tbl_erp_sales_outbound_spent_products.erp_inventory_product_id)
-> Index Scan using tbl_erp_purchase_inbounds_pkey on tbl_erp_purchase_inbounds r (cost=0.14..0.38 rows=1 width=254)
Index Cond: (id = tbl_erp_inventory_products.erp_purchase_inbound_id)
Filter: ((status <> 0) OR ((status = 0) AND (created_by = 1001)))