任务描述

DECLARE @CustomerID INT=1

IF EXISTS (SELECT *
           FROM   tempdb.dbo.sysobjects
           WHERE  id = Object_id(N'tempdb..#tbOrderSourceID')
                  AND type = 'U')
  DROP TABLE #tbOrderSourceID

CREATE TABLE #tbOrderSourceID
  (
     Id INT PRIMARY KEY
  )

INSERT INTO #tbOrderSourceID
SELECT item AS Id
FROM   Charsplitforin('13238,10481,10103,10372,11237,11238,10792,10489,10102,8960,7962,6759,6240,16641,13245,16107,16101,15936,15889,15791,14893,14652,10482,10478,10101,8592,8134,7783,17225,17814,17813,17816,10500,6635,7172,10235,9500,12626,18054,18063,10232,12824,9636,13235,13354,13062,7100,18224,18223,10791,10227,13645,9502,9674,10828,9656,10451,10098,6864,10473,10470,8419', ',')

SELECT *
FROM   (SELECT Row_number()
                 OVER (
                   ORDER BY ListingProductID DESC ) AS [PageIndex],
               *
        FROM   (SELECT P.ListingProductID,
                       P.CustomerID,
                       P.OrderSourceID,
                       P.SiteCode,
                       P.ListingBasicID,
                       P.SKU,
                       P.OrderSourceSKU,
                       P.BuyItNowPrice,
                       P.EnableBestOffer,
                       B.Duration,
                       B.EnableTimerPosting,
                       B.TimerPosting,
                       P.MinBestOfferPrice,
                       P.AutoAcceptPrice,
                       P.Quantity,
                       P.EAN,
                       P.UPC,
                       P.EPID,
                       P.ParentListingProductID,
                       P.IsVariation,
                       P.ProductType,
                       P.IsPriceStrategy,
                       P.PriceStrategyID,
                       P.PriceStrategyName,
                       B.TagName,
                       B.ItemID,
                       B.ListingType,
                       B.ProductTitle,
                       B.ProductSubTitle,
                       B.AuctionStartPrice,
                       B.AuctionReservePrice,
                       B.AuctionBuyItNowPrice,
                       B.Brand,
                       B.BrandMPN,
                       B.ClassID1,
                       B.ClassID2,
                       B.StoreClass1,
                       B.StoreClass2,
                       B.StoreURL,
                       B.StartTime,
                       B.FbaOrderSourceSKU,
                       B.EndTime,
                       Isnull(B.UpdateStatus, 0)           UpdateStatus,
                       B.ViewItemURL,
                       B.AddTime,
                       B.AdminID,
                       B.AdminName,
                       B.UpdateTime,
                       B.UpdateAdminID,
                       B.UpdateAdminName,
                       B.AddItemAdminID,
                       B.AddItemAdminName,
                       B.SellerAdminID,
                       B.SellerAdminName,
                       B.AddItemFee,
                       B.OnlineState,
                       B.Visits,
                       B.RowVersion,
                       B.SyncTime,
                       B.IsSync,
                       Isnull(B.QuantitySold, 0)           QuantitySold,
                       OS.OrderSourceName,
                       ''                                  ClientSKU,
                       ''                                  ProductNameCN,
                       NULL                                ProductState,
                       Isnull(ASP.EnableAutoSupplement, 0) EnableAutoSupplement,
                       Isnull(ASP.IsInventoryCheck, 0)     IsInventoryCheck,
                       ASP.ListingQty,
                       ASP.SupplementaryQty,
                       B.Warehouse,
                       ELS.SiteCountry,
                       country.CountryDescription,
                       Isnull(LSA.SalesToday, 0)           AS SalesToday,
                       Isnull(LSA.SalesYesterDay, 0)       AS SalesYesterDay,
                       Isnull(LSA.SalesBeforeDay, 0)       AS SalesBeforeDay,
                       Isnull(LSA.SalesMoth, 0)            AS SalesMoth,
                       Isnull(LSA.SalesDayTrend, 0)        AS SalesDayTrend,
                       Isnull(LSA.ViewsToday, 0)           AS ViewsToday,
                       Isnull(LSA.ViewsYesterDay, 0)       AS ViewsYesterDay,
                       Isnull(LSA.ViewsBeforeDay, 0)       AS ViewsBeforeDay,
                       Isnull(LSA.ViewsMoth, 0)            AS ViewsMoth,
                       Isnull(LSA.ViewsDayTrend, 0)        AS ViewsDayTrend,
                       CASE
                         WHEN Isnull(LSA.ViewsToday, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesToday, 0)) / CONVERT(FLOAT, LSA.ViewsToday), 4) * 100
                       END                                 AS RoiToday,
                       CASE
                         WHEN Isnull(LSA.ViewsYesterDay, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesYesterDay, 0)) / CONVERT(FLOAT, LSA.ViewsYesterDay), 4) * 100
                       END                                 AS RoiYesterDay,
                       CASE
                         WHEN Isnull(LSA.ViewsBeforeDay, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesBeforeDay, 0)) / CONVERT(FLOAT, LSA.ViewsBeforeDay), 4) * 100
                       END                                 AS RoiBeforeDay,
                       CASE
                         WHEN Isnull(LSA.ViewsMoth, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesMoth, 0)) / CONVERT(FLOAT, LSA.ViewsMoth), 4) * 100
                       END                                 AS RoiMoth,
                       0                                   SkuCount,
                       B.BidCount,
                       B.BidCurrentPrice,
                       P.OriginalRetailPrice,
                       B.MarkdownPromotionID,
                       B.MarkdownPromotionName,
                       B.MarkdownPromotionDisCountName,
                       B.MarkdownPromotionStartDate,
                       B.MarkdownPromotionEndDate,
                       B.MarkdownPromotionDisCountID,
                       MK.PromotionStatus                  AS MKPromotionStutas
                FROM   RB_Ebay_Listing_Basic_V2 AS B WITH (NOLOCK)
                       INNER JOIN #tbOrderSourceID OrderSourceIDs
                               ON B.OrderSourceID = OrderSourceIDs.Id
                       LEFT JOIN RB_Ebay_Listing_Product_V2 AS P WITH (NOLOCK)
                              ON B.CustomerID = P.CustomerID
                                 AND B.ListingBasicID = P.ListingBasicID
                                 AND B.OrderSourceID = P.OrderSourceID
                                 AND B.SiteCode = P.SiteCode
                       LEFT JOIN RB_Ebay_Listing_Sale_Attach_V2 LSA WITH (NOLOCK)
                              ON LSA.CustomerID = P.CustomerID
                                 AND LSA.ListingBasicID = p.ListingBasicID
                                 AND LSA.OrderSourceID = p.OrderSourceID
                       LEFT OUTER JOIN RB_OrderSource AS OS WITH (NOLOCK)
                                    ON B.CustomerID = OS.CustomerID
                                       AND B.OrderSourceID = OS.ID
                       LEFT JOIN RB_Ebay_Listing_AutoSupplement_V2 ASP WITH (NOLOCK)
                              ON ASP.CustomerID = P.CustomerID
                                 AND ASP.ListingBasicID = P.ListingBasicID
                                 AND ASP.ListingProductID = P.ListingProductID
                                 AND ASP.OrderSourceID = P.OrderSourceID
                                 AND ASP.SiteCode = P.SiteCode
                       LEFT JOIN RB_Ebay_Listing_Shipping_V2 ELS WITH(NOLOCK)
                              ON B.ListingBasicID = ELS.ListingBasicID
                                 AND B.CustomerID = ELS.CustomerID
                       LEFT JOIN E_Ebay_Country_V2 country (NOLOCK)
                              ON country.Country = ELS.SiteCountry
                       LEFT JOIN RB_Ebay_Listing_Markdown_Promotion MK WITH(NOLOCK)
                              ON MK.CustomerID = P.CustomerID
                                 AND MK.ID = B.MarkdownPromotionID
                WHERE  P.CustomerID = @CustomerID
                       AND P.IsVariation = 0
                       AND B.OnlineState = 0
                       AND ( Datediff(day, B.AddTime, '2023-04-01 00:00:00') <= 0 )) AS TempTable) AS PagerTable
WHERE  PagerTable.[PageIndex] BETWEEN 1 AND 500
OPTION(maxdop 8) ;

优化前2分钟都出不来,新建(idx_AddTime_OrderSourceID_ListingBasicID)这个索引,并强制指定,AddTime条件改变,优化后1秒出来,请参考。



DECLARE @CustomerID INT=1


IF EXISTS (SELECT *
           FROM   tempdb.dbo.sysobjects
           WHERE  id = Object_id(N'tempdb..#tbOrderSourceID')
                  AND type = 'U')
  DROP TABLE #tbOrderSourceID

CREATE TABLE #tbOrderSourceID
  (
     Id INT PRIMARY KEY
  )

INSERT INTO #tbOrderSourceID
SELECT item AS Id
FROM   Charsplitforin('13238,10481,10103,10372,11237,11238,10792,10489,10102,8960,7962,6759,6240,16641,13245,16107,16101,15936,15889,15791,14893,14652,10482,10478,10101,8592,8134,7783,17225,17814,17813,17816,10500,6635,7172,10235,9500,12626,18054,18063,10232,12824,9636,13235,13354,13062,7100,18224,18223,10791,10227,13645,9502,9674,10828,9656,10451,10098,6864,10473,10470,8419', ',')

SELECT *
FROM   (SELECT Row_number()
                 OVER (
                   ORDER BY ListingProductID DESC ) AS [PageIndex],
               *
        FROM   (SELECT P.ListingProductID,
                       P.CustomerID,
                       P.OrderSourceID,
                       P.SiteCode,
                       P.ListingBasicID,
                       P.SKU,
                       P.OrderSourceSKU,
                       P.BuyItNowPrice,
                       P.EnableBestOffer,
                       B.Duration,
                       B.EnableTimerPosting,
                       B.TimerPosting,
                       P.MinBestOfferPrice,
                       P.AutoAcceptPrice,
                       P.Quantity,
                       P.EAN,
                       P.UPC,
                       P.EPID,
                       P.ParentListingProductID,
                       P.IsVariation,
                       P.ProductType,
                       P.IsPriceStrategy,
                       P.PriceStrategyID,
                       P.PriceStrategyName,
                       B.TagName,
                       B.ItemID,
                       B.ListingType,
                       B.ProductTitle,
                       B.ProductSubTitle,
                       B.AuctionStartPrice,
                       B.AuctionReservePrice,
                       B.AuctionBuyItNowPrice,
                       B.Brand,
                       B.BrandMPN,
                       B.ClassID1,
                       B.ClassID2,
                       B.StoreClass1,
                       B.StoreClass2,
                       B.StoreURL,
                       B.StartTime,
                       B.FbaOrderSourceSKU,
                       B.EndTime,
                       Isnull(B.UpdateStatus, 0)           UpdateStatus,
                       B.ViewItemURL,
                       B.AddTime,
                       B.AdminID,
                       B.AdminName,
                       B.UpdateTime,
                       B.UpdateAdminID,
                       B.UpdateAdminName,
                       B.AddItemAdminID,
                       B.AddItemAdminName,
                       B.SellerAdminID,
                       B.SellerAdminName,
                       B.AddItemFee,
                       B.OnlineState,
                       B.Visits,
                       B.RowVersion,
                       B.SyncTime,
                       B.IsSync,
                       Isnull(B.QuantitySold, 0)           QuantitySold,
                       OS.OrderSourceName,
                       ''                                  ClientSKU,
                       ''                                  ProductNameCN,
                       NULL                                ProductState,
                       Isnull(ASP.EnableAutoSupplement, 0) EnableAutoSupplement,
                       Isnull(ASP.IsInventoryCheck, 0)     IsInventoryCheck,
                       ASP.ListingQty,
                       ASP.SupplementaryQty,
                       B.Warehouse,
                       ELS.SiteCountry,
                       country.CountryDescription,
                       Isnull(LSA.SalesToday, 0)           AS SalesToday,
                       Isnull(LSA.SalesYesterDay, 0)       AS SalesYesterDay,
                       Isnull(LSA.SalesBeforeDay, 0)       AS SalesBeforeDay,
                       Isnull(LSA.SalesMoth, 0)            AS SalesMoth,
                       Isnull(LSA.SalesDayTrend, 0)        AS SalesDayTrend,
                       Isnull(LSA.ViewsToday, 0)           AS ViewsToday,
                       Isnull(LSA.ViewsYesterDay, 0)       AS ViewsYesterDay,
                       Isnull(LSA.ViewsBeforeDay, 0)       AS ViewsBeforeDay,
                       Isnull(LSA.ViewsMoth, 0)            AS ViewsMoth,
                       Isnull(LSA.ViewsDayTrend, 0)        AS ViewsDayTrend,
                       CASE
                         WHEN Isnull(LSA.ViewsToday, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesToday, 0)) / CONVERT(FLOAT, LSA.ViewsToday), 4) * 100
                       END                                 AS RoiToday,
                       CASE
                         WHEN Isnull(LSA.ViewsYesterDay, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesYesterDay, 0)) / CONVERT(FLOAT, LSA.ViewsYesterDay), 4) * 100
                       END                                 AS RoiYesterDay,
                       CASE
                         WHEN Isnull(LSA.ViewsBeforeDay, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesBeforeDay, 0)) / CONVERT(FLOAT, LSA.ViewsBeforeDay), 4) * 100
                       END                                 AS RoiBeforeDay,
                       CASE
                         WHEN Isnull(LSA.ViewsMoth, 0) = 0 THEN 0
                         ELSE Round(CONVERT(FLOAT, Isnull(LSA.SalesMoth, 0)) / CONVERT(FLOAT, LSA.ViewsMoth), 4) * 100
                       END                                 AS RoiMoth,
                       0                                   SkuCount,
                       B.BidCount,
                       B.BidCurrentPrice,
                       P.OriginalRetailPrice,
                       B.MarkdownPromotionID,
                       B.MarkdownPromotionName,
                       B.MarkdownPromotionDisCountName,
                       B.MarkdownPromotionStartDate,
                       B.MarkdownPromotionEndDate,
                       B.MarkdownPromotionDisCountID,
                       MK.PromotionStatus                  AS MKPromotionStutas
                FROM   RB_Ebay_Listing_Basic_V2 AS B WITH (NOLOCK,index(idx_AddTime_OrderSourceID_ListingBasicID))
                       INNER JOIN #tbOrderSourceID OrderSourceIDs
                               ON B.OrderSourceID = OrderSourceIDs.Id
                       LEFT JOIN RB_Ebay_Listing_Product_V2 AS P WITH (NOLOCK)
                              ON B.CustomerID = P.CustomerID
                                 AND B.ListingBasicID = P.ListingBasicID
                                 AND B.OrderSourceID = P.OrderSourceID
                                 AND B.SiteCode = P.SiteCode
                       LEFT JOIN RB_Ebay_Listing_Sale_Attach_V2 LSA WITH (NOLOCK)
                              ON LSA.CustomerID = P.CustomerID
                                 AND LSA.ListingBasicID = p.ListingBasicID
                                 AND LSA.OrderSourceID = p.OrderSourceID
                       LEFT OUTER JOIN RB_OrderSource AS OS WITH (NOLOCK)
                                    ON B.CustomerID = OS.CustomerID
                                       AND B.OrderSourceID = OS.ID
                       LEFT JOIN RB_Ebay_Listing_AutoSupplement_V2 ASP WITH (NOLOCK)
                              ON ASP.CustomerID = P.CustomerID
                                 AND ASP.ListingBasicID = P.ListingBasicID
                                 AND ASP.ListingProductID = P.ListingProductID
                                 AND ASP.OrderSourceID = P.OrderSourceID
                                 AND ASP.SiteCode = P.SiteCode
                       LEFT JOIN RB_Ebay_Listing_Shipping_V2 ELS WITH(NOLOCK)
                              ON B.ListingBasicID = ELS.ListingBasicID
                                 AND B.CustomerID = ELS.CustomerID
                       LEFT JOIN E_Ebay_Country_V2 country (NOLOCK)
                              ON country.Country = ELS.SiteCountry
                       LEFT JOIN RB_Ebay_Listing_Markdown_Promotion MK WITH(NOLOCK)
                              ON MK.CustomerID = b.CustomerID
                                 AND MK.ID = B.MarkdownPromotionID
                WHERE  b.CustomerID = @CustomerID
                       AND P.IsVariation = 0
                       AND B.OnlineState = 3
                       --AND ( Datediff(day, B.AddTime, '2023-04-01 00:00:00') <= 0 )
                       and b.AddTime>'2023-04-01'
                       ) AS TempTable) AS PagerTable
WHERE  PagerTable.[PageIndex] BETWEEN 1 AND 500

OPTION(maxdop 8)



历史记录  
  1. 2023-04-07 17:25:58, 由 吴高发 创建。
  2. 2023-04-10 10:14:38, 由 王翔宇 指派给 彭康。
    修改了 指派给 ,旧值为 "wangxiangyu",新值为 "pengkang"。
    修改了 预计剩余,旧值为 "0",新值为 "1"。
  3. 2023-04-10 11:55:54, 由 冯名明 完成。
    修改了 总计消耗,旧值为 "0",新值为 "1"。
    修改了 指派给 ,旧值为 "pengkang",新值为 "liletong"。
    修改了 实际完成,旧值为 "",新值为 "2023-04-10 11:48:26"。
    修改了 任务状态,旧值为 "wait",新值为 "done"。
    修改了 实际开始,旧值为 "0000-00-00 00:00:00",新值为 "2023-04-10 11:55:54"。
    修改了 预计剩余,旧值为 "1",新值为 "0"。
    修改了 由谁完成,旧值为 "",新值为 "fengmingming"。

    1.已经按系统部提供的方案,强制新增索引:新建(idx_AddTime_OrderSourceID_ListingBasicID)这个索引,并强制指定

    2.更改代码:







    3.测试结果,可正常搜索,根据条件也可正常搜索




  4. 2023-04-10 14:20:38, 由 彭康 激活。
    修改了 指派给 ,旧值为 "liletong",新值为 "pengkang"。
    修改了 预计剩余,旧值为 "0",新值为 "1"。
    修改了 任务状态,旧值为 "done",新值为 "doing"。
    修改了 由谁完成,旧值为 "fengmingming",新值为 ""。
    修改了 实际完成,旧值为 "2023-04-10 11:48:26",新值为 "0000-00-00"。
    修改了 取消时间,旧值为 "",新值为 "0000-00-00"。
    修改了 关闭时间,旧值为 "",新值为 "0000-00-00"。
    冯名明改错了
  5. 2023-04-10 14:25:26, 由 彭康 完成。
    修改了 总计消耗,旧值为 "1",新值为 "2"。
    修改了 实际完成,旧值为 "",新值为 "2023-04-10 14:24:42"。
    修改了 任务状态,旧值为 "doing",新值为 "done"。
    修改了 预计剩余,旧值为 "1",新值为 "0"。
    修改了 由谁完成,旧值为 "",新值为 "pengkang"。

    在使用添加时间搜索的时候使用指定索引

  6. 2023-10-31 14:53:16, 由 周杰 关闭。
    修改了 任务状态,旧值为 "done",新值为 "closed"。
    修改了 指派给 ,旧值为 "pengkang",新值为 "closed"。
    修改了 由谁关闭,旧值为 "",新值为 "zhoujie"。
    修改了 关闭时间,旧值为 "0000-00-00 00:00:00",新值为 "2023-10-31 14:53:16"。
    修改了 关闭原因,旧值为 "",新值为 "done"。
所属迭代 系统管理部 - 系统服务优化
所属模块 /
相关需求 暂无
指派给 Closed 于 2023-10-31 14:53:16
任务类型 后端
任务标签 初始
开发组 百货开发组
任务状态 已关闭
进度 100%
优先级 P2
关键词
抄送给
由谁创建 吴高发 于 2023-04-07 17:25:58
由谁完成 彭康 于 2023-04-10 14:24:42
由谁取消 暂无
由谁关闭 周杰 于 2023-10-31 14:53:16
关闭原因 已完成
最后编辑 周杰 于 2023-10-31 14:53:16
团队 最初预计 总计消耗 预计剩余
工时信息
最初预计 0工时
总计消耗 2工时
预计剩余 0工时
预计开始 0000-00-00
实际开始 2023-04-10
截止日期 0000-00-00