[性能问题描述]
[11:50:18] -------------------------------------------------------------
CODE:N1150184
Error:11_-2_0_-2146232060
SQL: drop table if exists #tabStr0;
drop table if exists #tabStr1;declare @CheckOrderCodeStr0 varchar(max)= '126137,126327',@CheckOrderCodeStr1 varchar(max)= '2015362,2040025,2042668,2067114,2069424,2069425,2074437,2087199,2094296,2097806,2104872,2109126,2115577,2120736,2130342,2133890,2134274,2134913,2135312,2135313,2135987,2143211,2145521,2153722,2156791,2161311,2165261,2165262,2167680,2168017,2173649,2179986,2181067,2183234,2187592,2191155,2194373,2194374,2195424,2195425,2196681,2198010,2198644,2198993,2201676,2226967,2227724,2230453,2230497,2230655,2231553,2232256,2233089,2233965,2235113,2235210,2235356,2235384,2235724,2235928,2236170,2236613,2236632,2236667,2236682,2236730,2236734,2236784,2236835,2236938,2237006,2237104,2237335,2238015,2238198,2238199,2238272,2238414,2238643,2238644,2238688,2238789,2238819,2238939,2238991,2239177,2239250,2239277,2239278,2239279,2239280,2239420,2239452,2239543,2239891,2239904,2239905,2240013,2240074,2240076,2240484,2240573,2241050,2241268,2241437,2241442,2241477,2241490,2241739,2241772,2241818,2242006,2242166,2242167,2242183,2242399,2242493,2242657,2242667,2242670,2242671,2242752,2242757,2242763,2242822,2242889,2242903,2242923,2242924,2242963,2242964,2242970,2242999,2243004,2243005,2243041,2243044,2243110,2243131,2243134,2243386,2243387,2243507,2243546,2243638,2243660,2243791,2243879,2244241,2244481,2244482,2244789,2244799,2244859,2244860,2244861,2245020,2245069,2245259,2245591,2245649,2245846,2245868,2246258,2246293,2246428,2246498,2246499,2247129,2247169,2247586,2247597,2247651,2247659,2247726,2247763,2248053,2248609,2248865,2248894,2248900,2248928,2248959,2249190,2249322,2249471,2249635,2249834,2250182,2250223,2250237,2250578,2250708,2251033,2251048,2251106,2251137,2251138,2251402,2251458,2251521,2251732,2251736,2251764,2251814,2251815,2251827,2251937,2251979,2251980,2252102,2252146,2252151,2252211,2252212,2252213,2252293,2252478,2252548,2252603,2252639,2252714,2252824,2253005,2253022,2253023,2253567,2253575,2253678,2253694,2253915,2253973,2254052,2254144,2254242';create table #tabStr0(id int);
insert into #tabStr0
exec proc_string_split @CheckOrderCodeStr0,',';
create index idx_id on #tabStr0(id);
create table #tabStr1(id int);
insert into #tabStr1
exec proc_string_split @CheckOrderCodeStr1,',';
create index idx_id on #tabStr1(id);
SELECT * FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY RemovalOrderCode asc) AS [PageIndex] ,* FROM ( SELECT DISTINCT
0 AS Source,
os.OrderSourceName,
isnull(os.SourceStatus,0) SourceStatus,
dp.DepartmentName,
rocrsi.ID,
rocr.OrderSourceID,
rocr.RemovalOrderType,
rocr.RemovalOrderCode,
rocrsi.MNSKU,
rocrsi.FNSKU,
rocrsi.SKU,
rocrsi.SellableQuantity,
rocrsi.UnsellableQuantity,
rocrsi.CostDestroyed,
rocrsi.DestroyedAdminName,
rocrsi.JobNo,
rocrsi.Remark,
ISNULL(arod.RequestedQuantity, 0) AS RequestedQuantity,
ISNULL(arod.CancelledQuantity, 0) AS CancelledQuantity,
ISNULL(arod.DisposedQuantity, 0) AS DisposedQuantity,
ISNULL(arod.ShippedQuantity, 0) AS ShippedQuantity,
ISNULL(arod.InProcessQuantity, 0) AS InProcessQuantity,
arod.Disposition,
ISNULL(rfih.[inv-age-0-to-90-days], 0) AS InvAge0To90Days,
ISNULL(rfih.[inv-age-91-to-180-days], 0) AS InvAge91To180Days,
ISNULL(rfih.[inv-age-181-to-270-days], 0) AS InvAge181To270Days,
ISNULL(rfih.[inv-age-271-to-365-days], 0) AS InvAge271To365Days,
ISNULL(rfih.[inv-age-365-plus-days], 0) AS InvAge365PlusDays,
ISNULL(rrd.ReceivedQty, 0) AS ReceivedQty,
'' AS Carrier,
'' AS TrackingNumber,
ISNULL(rocrsi.DestructionReason,'') AS DestroyedReason,
ISNULL(( CASE WHEN pro.LastBuyPrice > 0 THEN pro.LastBuyPrice
ELSE pro.LastSupplierPrice
END ), 0) * (arod.DisposedQuantity + arod.ShippedQuantity) AS TotalProcessedPurchasePrice,
ISNULL(( CASE WHEN pro.LastBuyPrice > 0 THEN pro.LastBuyPrice
ELSE pro.LastSupplierPrice
END ), 0) * (rocrsi.SellableQuantity + rocrsi.UnsellableQuantity) AS TotalPurchasePrice,
ISNULL(( CASE WHEN pro.LastBuyPrice > 0 THEN pro.LastBuyPrice
ELSE pro.LastSupplierPrice
END ), 0) * (rocrsi.SellableQuantity + rocrsi.UnsellableQuantity) * (ISNULL(rocrsi.CostDestroyed, 0)/100) AS DestroyAllocatedAmount,
pro.ImageUrl,
pro.ProductNameCN,
isnull( wh.WareHouseName,'') OverseaWareHouseName,pro.ProductProperty
FROM RB_RemovalOrderCreateRecordSkuItems rocrsi (NOLOCK)
LEFT JOIN RB_RemovalOrderCreateRecord rocr (NOLOCK)
ON rocrsi.CustomerID = rocr.CustomerID
AND rocrsi.RecordID = rocr.ID
LEFT JOIN RB_Product pro (NOLOCK)
ON rocrsi.CustomerID = pro.CustomerID
AND rocrsi.SKU = pro.SKU
LEFT JOIN RB_Amazon_Removal_Order_Detail arod with (NOLOCK)
ON rocr.CustomerID = arod.CustomerID
AND rocr.OrderSourceID = arod.OrderSourceID
AND rocr.RemovalOrderCode = arod.OrderID
AND rocrsi.MNSKU = arod.SKU
AND rocrsi.FNSKU = arod.FnSKU
LEFT JOIN RB_Removeorder_ReceiveDetail rrd with (NOLOCK)
ON arod.OrderID = rrd.OrderID
AND arod.OrderSourceID = rrd.OrderSourceID
AND arod.CustomerID = rrd.CustomerID
AND arod.SKU = rrd.SellerSKU
AND arod.FnSKU = rrd.FNSKU
LEFT JOIN RB_FBA_INVENTORY_PLANNING_DATA rfih with (NOLOCK)
ON rocr.CustomerID = rfih.CustomerID
AND rocr.OrderSourceID = rfih.OrderSourceID
AND rocrsi.MNSKU = rfih.sku
AND rocrsi.FNSKU = rfih.fnsku
AND convert(date,rocr.AddTime) = convert(date,rfih.[snapshot-date])
LEFT JOIN RB_OrderSource (NOLOCK) os
ON os.CustomerID = rocr.CustomerID
AND os.ID = rocr.OrderSourceID
LEFT JOIN RB_RemovalOrder_BusinessExpand robe (NOLOCK)
ON robe.CustomerID = rocr.CustomerID
AND robe.OrderSourceID = rocr.OrderSourceID
AND robe.RemovalOrderCode = rocr.RemovalOrderCode
LEFT JOIN RB_RemovalOrder_SkuItem_AuditSatusExtend (NOLOCK) rsase
ON rsase.CustomerID = rocrsi.CustomerID
AND rsase.ReportID = rocrsi.ID
LEFT JOIN RB_Admin (NOLOCK) ra
ON rocrsi.CustomerID = ra.CustomerID
AND rocrsi.DestroyedAdminID = ra.ID
LEFT JOIN RB_Department (nolock) dp
ON ra.CustomerID = dp.CustomerID
AND ra.DepartmentID = dp.ID
left join RB_WareHouse (nolock) wh
on rocr.CustomerID = wh.CustomerID
and rocr.OverseaWareHouseId = wh.ID INNER JOIN #tabStr0 t0 on t0.id = rocrsi.ID WHERE rocrsi.CustomerID = @CustomerID AND rsase.AuditSatus = 2 and exists(select 1
from RB_OrderSource_SaleAdmin osa (NOLOCK)
where osa.OrderSourceID = os.ID
and osa.CustomerID = 1
and osa.AdminID = 3748
) union all SELECT DISTINCT
1 AS Source,
os.OrderSourceName,
isnull(os.SourceStatus,0) SourceStatus,
dp.DepartmentName,
arod.ID,
arod.OrderSourceID,
arod.OrderType AS RemovalOrderType,
arod.OrderID AS RemovalOrderCode,
arod.SKU AS MNSKU,
arod.FnSKU AS FNSKU,
pro.SKU AS SKU,
0 AS SellableQuantity,
0 AS UnsellableQuantity,
ISNULL(arod.CostDestroyed, 0) AS CostDestroyed,
arod.DestroyedAdminName AS DestroyedAdminName,
arod.JobNo AS JobNo,
arod.Remark AS Remark,
ISNULL(arod.RequestedQuantity, 0) AS RequestedQuantity,
ISNULL(arod.CancelledQuantity, 0) AS CancelledQuantity,
ISNULL(arod.DisposedQuantity, 0) AS DisposedQuantity,
ISNULL(arod.ShippedQuantity, 0) AS ShippedQuantity,
ISNULL(arod.InProcessQuantity, 0) AS InProcessQuantity,
arod.Disposition,
ISNULL(rfih.[inv-age-0-to-90-days], 0) AS InvAge0To90Days,
ISNULL(rfih.[inv-age-91-to-180-days], 0) AS InvAge91To180Days,
ISNULL(rfih.[inv-age-181-to-270-days], 0) AS InvAge181To270Days,
ISNULL(rfih.[inv-age-271-to-365-days], 0) AS InvAge271To365Days,
ISNULL(rfih.[inv-age-365-plus-days], 0) AS InvAge365PlusDays,
ISNULL(rrd.ReceivedQty, 0) AS ReceivedQty,
'' AS Carrier,
'' AS TrackingNumber,
arod.DestructionReason AS DestroyedReason,
ISNULL(( CASE WHEN pro.LastBuyPrice > 0 THEN pro.LastBuyPrice
ELSE pro.LastSupplierPrice
END ), 0) * (arod.DisposedQuantity + arod.ShippedQuantity) AS TotalProcessedPurchasePrice,
ISNULL(( CASE WHEN pro.LastBuyPrice > 0 THEN pro.LastBuyPrice
ELSE pro.LastSupplierPrice
END ), 0) * (arod.RequestedQuantity) AS TotalPurchasePrice,
ISNULL(( CASE WHEN pro.LastBuyPrice > 0 THEN pro.LastBuyPrice
ELSE pro.LastSupplierPrice
END ), 0) * (arod.RequestedQuantity)* (ISNULL(arod.CostDestroyed, 0)/100) AS DestroyAllocatedAmount,
pro.ImageUrl,
pro.ProductNameCN,
ISNULL(wh.WareHouseName,'') as OverseaWareHouseName,pro.ProductProperty
FROM RB_Amazon_Removal_Order_Detail arod with (NOLOCK)
LEFT JOIN RB_Removeorder_ReceiveDetail rrd with (NOLOCK)
ON arod.OrderID = rrd.OrderID
AND arod.OrderSourceID = rrd.OrderSourceID
AND arod.CustomerID = rrd.CustomerID
AND arod.SKU = rrd.SellerSKU
AND arod.FnSKU = rrd.FNSKU
LEFT JOIN RB_FBA_INVENTORY_PLANNING_DATA rfih with (NOLOCK)
ON arod.OrderSourceID = rfih.OrderSourceID
AND arod.CustomerID = rfih.CustomerID
AND arod.SKU = rfih.sku
AND arod.FnSKU = rfih.fnsku
AND convert(date,arod.AddTime) = convert(date,rfih.[snapshot-date])
LEFT JOIN RB_RemovalOrder_BusinessExpand robe (NOLOCK)
ON robe.CustomerID = arod.CustomerID
AND robe.OrderSourceID = arod.OrderSourceID
AND robe.RemovalOrderCode = arod.OrderID
LEFT JOIN RB_OrderSource (nolock) os
ON os.CustomerID = arod.CustomerID
AND os.ID = arod.OrderSourceID
left join RB_WareHouse (nolock) wh
on os.CustomerID = wh.CustomerID
and os.RemovalOrderDefaultWareHouseID = wh.ID
LEFT JOIN RB_Product_OrderSourceSKU orsku with (NOLOCK)
ON arod.CustomerID = orsku.CustomerID
AND arod.OrderSourceID = orsku.OrderSourceID
AND arod.SKU = orsku.OrderSourceSKU
LEFT JOIN RB_Product pro with (NOLOCK)
ON orsku.SKU = pro.SKU
AND orsku.CustomerID = pro.CustomerID
LEFT JOIN RB_RemovalOrder_SkuItem_AuditSatusExtend (NOLOCK) rsase
ON rsase.CustomerID = arod.CustomerID
AND rsase.ReportID = arod.ID
LEFT JOIN RB_Admin (nolock) ra
ON arod.CustomerID = ra.CustomerID
AND arod.DestroyedAdminID = ra.ID
LEFT JOIN RB_Department (nolock) dp
ON ra.CustomerID = dp.CustomerID
AND ra.DepartmentID = dp.ID INNER JOIN #tabStr1 t1 on t1.id = arod.ID WHERE arod.CustomerID = @CustomerID AND NOT EXISTS (SELECT 1 FROM RB_RemovalOrderCreateRecord (nolock) rocr1
WHERE rocr1.CustomerID = arod.CustomerID
AND rocr1.OrderSourceID = arod.OrderSourceID
AND rocr1.RemovalOrderCode = arod.OrderID) AND rsase.AuditSatus = 2 and exists(select 1
from RB_OrderSource_SaleAdmin osa (NOLOCK)
where osa.OrderSourceID = os.ID
and osa.CustomerID = 1
and osa.AdminID = 3748
) ) AS TempTable ) AS PagerTable WHERE PagerTable.[PageIndex] BETWEEN 1 AND 20 drop table if exists #tabStr0;
drop table if exists #tabStr1;
PARAMS:@CustomerID = 1 ,@StartDate = 2023-10-16 ,@EndDate = 2023/10/31 0:00:00 ,
MESSAGE:执行超时已过期。完成操作之前已超时或服务器未响应。
TRACE: 在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
在 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
在 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
在 System.Data.SqlClient.SqlDataReader.get_MetaData()
在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
在 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
在 RB.DAL.DBOperator.Query(String SQLString, SqlCommand cmd, Int32 Times, SqlParameter[] cmdParms, Boolean IsWriteDB) 在 RB.DAL.DBOperator.toCommonTipException(SqlException ex, String sql, SqlParameter[] cmdParms)
在 RB.DAL.DBOperator.Query(String SQLString, SqlCommand cmd, Int32 Times, SqlParameter[] cmdParms, Boolean IsWriteDB)
在 RB.DAL.DBOperator.QueryPager(String SQLTemporary, String SQLClearTemporary, String SQLString, String strOrder, Int32 pageIndex, Int32 pageSize, Int32& recordCount, Int32 times, SqlParameter[] cmdParms)
在 RB.DAL.DBOperator.QueryPager(String SQLTemporary, String SQLClearTemporary, String SQLString, String strOrder, Int32 pageIndex, Int32 pageSize, Int32& recordCount, SqlParameter[] cmdParms)
在 RB.DALExtendV2.RB_Amazon_Removal_Order_DetailExtendV2.GetRemoveOrderSKUDetail(CM_GetRemovalOrderCreateRecordSkuItemsParam para, Boolean IsAutoSubmit, Int32& recordCount)
在 PandaBuy.ERP.Web.IrobotBox.RemoveOrder.RemoveOrderSKUList.GetBatchAuditCount()
在 PandaBuy.ERP.Web.IrobotBox.RemoveOrder.RemoveOrderSKUList.Page_Load(Object sender, EventArgs e)
在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
在 System.Web.UI.Control.OnLoad(EventArgs e)
在 System.Web.UI.Control.LoadRecursive()
在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
在 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
在 System.Web.UI.Page.ProcessRequest()
在 System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
在 System.Web.UI.Page.ProcessRequest(HttpContext context)
在 ASP.irobotbox_removeorder_removeorderskulist_aspx.ProcessRequest(HttpContext context)
在 System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
在 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
在 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
在 System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
在 System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
在 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
在 System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
在 System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
在 System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr pHandler, RequestNotificationStatus& notificationStatus)
在 System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
在 System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr rootedObjectsPointer, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
-------------------------------------------------------------
[分析过程]
查看执行计划 慢 在 union 的后面查询语句 RB_Amazon_Removal_Order_Detail arod with (NOLOCK) 没有包含有效的查询条件
[期望结果] 加入一些核心关联或者条件 以提升效率,减少小黄鸡。

