重现步骤

[步骤]

(@p1 bigint,@p2 datetimeoffset(7),@p3 datetimeoffset(7),@p4 datetimeoffset(7),@p5 datetimeoffset(7),@p6 bigint)


SELECT TOP 2000 *
FROM   (SELECT a.ID                                           AS PID,
               a.AddTime                                      AS DataAddTime,
               a.CustomerID,
               a.PostedDate,
               a.FinancesReportID,
               Isnull(a.AmazonOrderId, '')                    AS AmazonOrderID,
               Isnull(a.SellerOrderId, '')                    AS SellerOrderID,
               Isnull(c.OrderSourceCountry, '')               AS OrderSourceCountryEn,
               Isnull(ec.ID, 0)                               AS OrderSourceCountryID,
               Isnull(c.SaleAdminID, 0)                       AS SaleAdminID,
               Isnull(cy.ID, 0)                               AS CurrencyCode,
               Isnull(ra.DepartmentID, 0)                     AS DepartmentID,
               Cast(Isnull(a.SellerSKU, '') AS NVARCHAR(500)) AS SellerSKU,
               Isnull(pss.SKU, '')                            AS SKU,
               Isnull(p.ClientSKU, '')                        AS ClientSKU,
               Isnull(p.ProductNameCN, '')                    AS ProductNameCN,
               Isnull(pra.DevelopAdminID, 0)                  AS DevelopAdminID,
               Isnull(p.ClassID, 0)                           AS ClassID,
               Isnull(a.FinancialEventType, '')               AS FinancialEventType,
               Isnull(a.ShipmentItemType, '')                 AS ShipmentItemType,
               Isnull(a.EventItemType, '')                    AS EventItemType,
               Isnull(a.EventDetailType, '')                  AS EventDetailType,
               a.CurrencyAmount,
               Isnull(a.PointsGrantedCurrencyAmount, 0)       AS PointsGrantedCurrencyAmount,
               Isnull(a.PointsReturnedCurrencyAmount, 0)      AS PointsReturnedCurrencyAmount,
               Isnull(a.MarketplaceName, '')                  AS MarketplaceName,
               Isnull(a.QuantityShipped, 0)                   AS QuantityShipped,
               a.OrderSourceID,
               Isnull(a.OrderItemId, '')                      AS OrderItemID,
               Isnull(a.OrderAdjustmentItemId, '')            AS OrderAdjustmentItemID,
               c.OrderSourceType,
               Row_number() OVER (ORDER BY a.ID ASC)          AS RowNumber
        FROM   RB_Amazon_ListFinancialEvents (NOLOCK) a
               LEFT JOIN RB_OrderSource (NOLOCK) c
                 ON a.CustomerID = c.CustomerID
                    AND a.OrderSourceID = c.ID
               LEFT JOIN (SELECT OrderSourceSKU,
                                 CustomerID,
                                 OrderSourceID,
                                 Max(SKU)SKU
                          FROM   RB_Product_OrderSourceSKU WITH(nolock)
                          GROUP  BY OrderSourceSKU,
                                    CustomerID,
                                    OrderSourceID)pss
                 ON a.CustomerID = pss.CustomerID
                    AND a.SellerSKU = pss.OrderSourceSKU
                    AND a.OrderSourceID = pss.OrderSourceID
               LEFT JOIN dbo.RB_Admin ra WITH (NOLOCK)
                 ON c.SaleAdminID = ra.ID
               LEFT JOIN dbo.RB_Product p WITH (NOLOCK)
                 ON p.SKU = pss.SKU
                    AND p.CustomerID = pss.CustomerID
               LEFT JOIN dbo.RB_Product_Admin pra WITH (NOLOCK)
                 ON p.SKU = pra.SKU
                    AND p.CustomerID = pra.CustomerID
               LEFT JOIN dbo.E_Country ec WITH(NOLOCK)
                 ON c.OrderSourceCountry = ec.Shorthand
               LEFT JOIN dbo.E_Currency cy WITH(nolock)
                 ON a.CurrencyCode = cy.Currency
        WHERE  a.CustomerID = @p1
               AND a.PostedDate >= @p2
               AND a.PostedDate < @p3
               AND a.AddTime >= @p4
               AND a.AddTime < @p5
               AND a.OrderSourceID = @p6) TAB
WHERE  RowNumber > 0
ORDER  BY RowNumber 

SELECT OrderSourceSKU,
                                 CustomerID,
                                 OrderSourceID,
                                 Max(SKU)SKU
                          FROM   RB_Product_OrderSourceSKU WITH(nolock)
                          GROUP  BY OrderSourceSKU,
                                    CustomerID,

                                    OrderSourceID


全表分组统计消耗性能大 而且 转化出来的   Max(SKU) 类型也不一致      ON p.SKU = pss.SKU

[结果]


[期望]

查分成多语句 ,优先获取主表的内容,然后再在获取其他表的数据,减少逻辑复杂度。 top 2000 维度也过大


历史记录  
  1. 2024-07-25 09:49:28, 由 袁慧斌 创建。
  2. 2024-07-25 15:30:33, 由 李乐同 指派给 何智军。
    修改了 指派给,旧值为 "liletong",新值为 "hezhijun"。
  3. 2024-07-26 09:22:20, 由 袁慧斌 编辑。
    修改了 优先级 ,旧值为 "2",新值为 "1"。
    修改了 解决时效,旧值为 "0",新值为 "-1"。
  4. 2024-07-26 09:33:17, 由 袁慧斌 编辑。
    修改了 解决时效,旧值为 "0",新值为 "23.71"。
    修改了 上线时效,旧值为 "-1",新值为 "17747745.82"。
    好几个并行,消耗资源。严重影响读库同步 导致读库延迟
  5. 2024-07-26 11:55:09, 由 何智军 指派给 李忠红。
    修改了 指派给,旧值为 "hezhijun",新值为 "lizhonghong"。
  6. 2024-07-26 11:58:20, 由 李忠红 指派给 何智军。
    修改了 指派给,旧值为 "lizhonghong",新值为 "hezhijun"。
  7. 2024-07-26 12:08:58, 由 何智军 解决,方案为 非BUG-纯属误判 。
    修改了 解决方案,旧值为 "",新值为 "feibug"。
    修改了 解决版本,旧值为 "",新值为 "trunk"。
    修改了 解决日期,旧值为 "",新值为 "2024-07-26 11:58:43"。
    修改了 指派给 ,旧值为 "hezhijun",新值为 "yuanhuibin"。
    修改了 Bug状态 ,旧值为 "active",新值为 "resolved"。
    修改了 是否确认,旧值为 "0",新值为 "1"。
    修改了 解决者 ,旧值为 "",新值为 "hezhijun"。
    原因:最近金蝶对接系统在手动拉取亚马逊结算数据,目前频率是1个月执行一次为


    为保证财务做账数据及时性,建议不做并行资源释放

    PS:当前在手动拉取数据会造成ERP库压力过大,手动数据已经拉取完成,ERP库压力应该已经释放。

  8. 2024-07-31 15:02:19, 由 袁慧斌 激活。
    修改了 指派给 ,旧值为 "yuanhuibin",新值为 "hezhijun"。
    修改了 Bug状态 ,旧值为 "resolved",新值为 "active"。
    修改了 激活日期,旧值为 "",新值为 "2024-07-31 15:02:19"。
    修改了 激活次数,旧值为 "0",新值为 "1"。
    修改了 解决方案,旧值为 "feibug",新值为 ""。
    修改了 解决日期,旧值为 "2024-07-26 11:58:43",新值为 "0000-00-00"。
    修改了 解决者 ,旧值为 "hezhijun",新值为 ""。
    修改了 解决版本,旧值为 "trunk",新值为 ""。
    修改了 关闭日期,旧值为 "",新值为 "0000-00-00"。
  9. 2024-08-02 10:41:07, 由 何智军 编辑。
    修改了 解决时效,旧值为 "23.71",新值为 "192.81"。
    修改了 上线时效,旧值为 "17747700",新值为 "17747745.82"。

    取 RB_Product_OrderSourceSKU 表数据全表扫描耗费性能较大,看是否可以根据店铺查询出来后,通过ROW_NUMBER去重来改造一下,参考以下sql


    SELECT T.*
    FROM 
    (
    SELECT ROW_NUMBER() OVER(PARTITION BY OrderSourceSKU,
    CustomerID,
    OrderSourceID,
    SKU ORDER BY ID DESC) AS RowIndex,
    OrderSourceSKU,
    CustomerID,
    OrderSourceID,
    SKU
    FROM   RB_Product_OrderSourceSKU WITH(nolock)
    WHERE CustomerID=1 AND OrderSourceID=5004
    ) T
    WHERE T.RowIndex=1


  10. 2024-08-02 10:41:45, 由 何智军 指派给 李忠红。
    修改了 指派给,旧值为 "hezhijun",新值为 "lizhonghong"。
  11. 2024-08-02 14:44:48, 由 李忠红 解决,方案为 第三方原因(外部系统) 。
    修改了 解决方案,旧值为 "",新值为 "external"。
    修改了 解决版本,旧值为 "",新值为 "trunk"。
    修改了 解决日期,旧值为 "",新值为 "2024-08-02 14:43:05"。
    修改了 指派给 ,旧值为 "lizhonghong",新值为 "yuanhuibin"。
    修改了 Bug状态 ,旧值为 "active",新值为 "resolved"。
    修改了 解决者 ,旧值为 "",新值为 "lizhonghong"。

    1.已优化

  12. 2024-08-07 09:27:01, 由 袁慧斌 关闭。
    修改了 Bug状态 ,旧值为 "resolved",新值为 "closed"。
    修改了 指派给 ,旧值为 "yuanhuibin",新值为 "closed"。
    修改了 由谁关闭,旧值为 "",新值为 "yuanhuibin"。
    修改了 关闭日期,旧值为 "",新值为 "2024-08-07 09:27:01"。
所属项目 技术中心-需求池
所属模块 财务   财务管理
所属计划
所属迭代
Bug类型
严重程度 一般
优先级 P0
Bug状态 已关闭
业务部门
影响功能
开发责任人 何智军
测试责任人
解决时效 192.81
激活次数 1
激活日期 2024-07-31 15:02:19
是否确认 是
当前指派 Closed 于 2024-08-07 09:27:01
截止日期 0000-00-00
上线时间 0000-00-00 00:00:00
上线时效 17747700
操作系统
浏览器
关键词
抄送给
所属迭代
相关需求
相关任务
由谁创建 袁慧斌 于 2024-07-25 09:49:28
影响环境 577
由谁解决 李忠红 于 2024-08-02 14:43:05
解决版本 主干
解决方案 第三方原因(外部系统)
由谁关闭 袁慧斌 于 2024-08-07 09:27:01
最后修改 袁慧斌 于 2024-08-07 09:27:01
相关Bug