此视图查询需要 2 分钟才能加载 500 000 行。我正在使用 EF 4.0 并在 DataGrid 上线程加载此视图。我该如何优化它,以便它可以在更短的时间内加载?
更新:我将查询更新为此,现在需要 55 秒,但仍然太长!
SELECT ROW_NUMBER() OVER ( ORDER BY ss.IDStore_CardStore DESC ) AS Id_PK ,
SC.IDStockCardIndex ,
SC.Designation ,
ISNULL(P.PMP, 0) PMP ,
ISNULL(SS.Quantity, 0) Quantity ,
SS.UnitePrice * SS.Quantity AS SubTotalStockCard ,
S.StoreName ,
SS.IDPurchaseInvoice
FROM dbo.Stores S
INNER JOIN dbo.StockCardsStores ss ON S.IDStore = ss.IDStore
RIGHT OUTER JOIN dbo.StockCard SC ON ss.IDStockCardIndex = SC.IDStockCardIndex
LEFT OUTER JOIN ( SELECT SUM(UnitePrice * Quantity) / SUM(Quantity) AS PMP ,
IDStockCardIndex
FROM dbo.StockCardsStores AS SCS
GROUP BY IDStockCardIndex
) AS P ON P.IDStockCardIndex = SC.IDStockCardIndex