i have a sp which returns 3 millions records. right now its taking 16 minute . i am trying to optimize it. since there is a or condition in join its taking time. is there any way to optimize it?
SELECT
    id, from
FROM
    [#Temp1] AD              
    JOIN [#Temp2]  SS
        ON AD.Id = SS.Id
        OR (SS.Code = AD.Code AND AD.ID IS NULL)        
JOIN wTable1 WSS WITH(NOLOCK)               
    ON SS.PId= WSS.Id
 
     
     
    