Slow Query - SQL Server 2012

0

The query below takes an average of 30 seconds to execute. I know that most likely it will be the various or and like , but I am looking for the log table and not always the id will be the same, for I used the like . How do I adjust this query to become faster?

select max(l.logdescricao),  
S.SolID [N° Chamado],  
S.NomeCliente [Nome Cliente],  
MAX(T.TraData) [Data do Último Trâmite],  
U.UsuNome [Consultor Responsável]  
from Solicitacao S  
inner join Log L on S.SolID = L.LogSolID  
LEFT JOIN Usuario U  
ON U.UsuID = S.UsuIDResponsavel  
LEFT JOIN Tramite T  
ON T.SolID = S.SolID  
left join StatusMotivo SM ON SM.SMSolID = S.SolID  
where S.VencimentoPausado = 0 and S.SolStatus <> 9 and (L.LOGDESCRICAO like '%16357%Aguardando%Operadora%' or L.LOGDESCRICAO like '%1061%Aguardando%Cliente%'
or L.LOGDESCRICAO like '%1061%Aguardando%Desenvolvimento%' or L.LOGDESCRICAO like '%1061%Aguardando%Operadora%')  
group by S.SolID,S.NomeCliente,U.UsuNome 
    
asked by anonymous 07.08.2017 / 21:55

1 answer

0

Renan, you use 2 fields that are of integer type (S.VentionName and S.SolStatus) to make the filter in addition to the text field. If you put an index that contains these fields, the query will certainly be faster. You can also use the execution plan to see if SQL Server suggests creating an index. See the following link for how this works: Missing index

    
14.08.2017 / 19:57