在SQL Server中调整SQL查询

时间:2016-07-01 20:34:03

标签: sql sql-server tsql sql-tuning

我如何调整以下t-sql查询?执行计划看起来不错(即使用索引搜索,索引扫描)。

SELECT 
    CodeID = CL.codeID,
    CodeName = PR.PetTypeCode,
    DisplayName = PR.PetTypeDisplayName,
    AdditionalOptionID = coalesce(currAID.aidID, AID.aidID, 0),
    AdditionalOptionDescription = case
                                     when currAID.aidID is not null 
                                        then currAID.Description
                                     when AID.aidID is not null 
                                        then AID.Description
                                     else ''''
                                   end,
    TransactionCodeID = case
                           when currAID.aidID is not null 
                              then currAID.trancID
                           when AID.aidID is not null 
                              then AID.trancID
                           else 0
                        end,
    Amount = case
                when currAID.aidID is not null 
                   then convert(numeric(10, 2), currAID.TransactionAmount)
                when AID.aidID is not null 
                   then convert(numeric(10, 2), AID.TransactionAmount)
                else 0.00
             end,
    FrequencyCode = 'M',AllowOverrideBit = '0'
FROM
    PetRents PR with (nolock) 
INNER JOIN
    CodeLookup CL with (nolock) ON CL.codeCodeName = PR.PetTypeCode
LEFT JOIN
    AdditionalItemDetail AID with (nolock) ON PR.AdditionalOptionID = AID.aidID
LEFT JOIN
    AdditionalItemDetail currAID with (nolock) ON AID.CurrentID = currAID.aidID
WHERE
    CL.codeDisplayBit = 1 
    AND CL.className = 'Pettypes' 
    AND PR.DisabledBit = 0 
    AND PR.PetTypeAllowedBit = 1

Overall query execution plan Query 1 properties Query 2 properties Query 3 properties Query 4 properties

0 个答案:

没有答案