Pergunta

I am running a store procedure which is taking a lot of time , due to which i have to increase the timeout to nearly 3 minutes, can any one provide assistance on how i can decrease the time for the store procedure to execute , it works fine on 100-500 codes but when the code exceeds to somehow 20000 , it slows up and takes upto 3-4 minutes , below is the sp, can anyone help me optimizing it.

@GUID uniqueidentifier
-- Insert statements for procedure here
SELECT     
        COUNT(Code.allocatedVendorID) AS Amt, 
        MIN(Code.dateAllocated) AS dateAllocated, 
        derivedtbl_1.startID, derivedtbl_2.endID, 
        tbVendor.name, 
        Code.unitCost, Code.isFree, Code.isAcademic, 
        Code.isVoided, Code.GUID, Code.expiryDate
FROM         
       Code 
        INNER JOIN
              (SELECT     MIN(CodeID) AS startID, GUID
                FROM          Code AS tbAccessCode_1
                GROUP BY GUID) AS derivedtbl_1 
                ON Code.GUID = derivedtbl_1.GUID 
        INNER JOIN
              (SELECT     MAX(accessCodeID) AS endID, GUID
                FROM          Code AS tbAccessCode_1
                GROUP BY GUID) AS derivedtbl_2 
                ON Code.GUID = derivedtbl_2.GUID 
        INNER JOIN  tbVendor 
            ON Code.allocatedVendorID = tbVendor.vendorID
WHERE     (Code.GUID = @GUID) AND (Code.allocatedVendorID > 0)
GROUP BY
        derivedtbl_1.startID, derivedtbl_2.endID, 
        tbVendor.name, 
        Code.unitCost, Code.isFree, Code.isAcademic, 
        Code.isVoided, Code.GUID, Code.expiryDate

ORDER BY dateAllocated DESC

Nenhuma solução correta

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top