下面的查詢需要20秒來執行,我需要儘可能多地優化它。請幫助我。需要20 - 30秒才能運行的SQL查詢優化
SELECT Distinct
qh.QuoteHeaderId, [dbo].[mpx2_Get_PhoneGrade](qh.QuoteHeaderId)
FROM
t_QuoteHeader QH
INNER JOIN
t_HandsetQuote h ON Qh.QuoteHeaderId = h.QuoteHeaderId
INNER JOIN
t_phoneAudit P ON ISNULL(h.InspectionPhoneAuditId, h.QuotePhoneAuditId) = p.PhoneAuditId
INNER JOIN
mpx2_vw_customers C ON qh.CustomerId = C.CustomerId
INNER JOIN
@ContactChannels CC ON C.ContactChannelId = CC.ContactChannelId
LEFT OUTER JOIN
t_HandsetQuoteAdditionalInfo_TRNX hqa ON hqa.hqid = h.HandsetQuoteId
WHERE
((@VirtualStatusId = 0 OR @VirtualStatusId = -2 OR
C.ContactChannelId NOT IN (1, 2, 13, 80)))
AND ((@VirtualStatusId = -2) OR
('Q'+ CAST(Qh.QuoteStatusId AS VARCHAR(3)) + 'S' + CAST(h.StockStatusId AS VARCHAR(3)) IN
(SELECT 'Q'+ CAST(QuoteStatusId AS VARCHAR(3)) + 'S' + CAST(StockStatusId AS VARCHAR(3)) FROM t_VirtualStatusMap WHERE (@VirtualStatusId IS NULL OR @VirtualStatusId IN (0,-1) OR VirtualStatusId = @VirtualStatusId))
)
)
AND ((qh.IsCancelled = 0 and @onlyOpenOrders = 1) OR @onlyOpenOrders = 0)
AND ((h.IsCancelled = 0 and @onlyOpenOrders = 1) OR @onlyOpenOrders = 0)
AND (qh.ConfirmedDate <= @CutOff)
請幫我優化它。此查詢用於存儲過程。
如何在不知道數據庫結構或者查看查詢計劃的情況下提供幫助? – DavidG
對不起,但我必須上傳執行計劃 – HarshSharma
只需[編輯]問題。 – DavidG