Slow Query - SQL Server 2012

Asked

Viewed 201 times

0

The query below is taking on average 30 seconds to execute. I know that very likely can be the various or and like, but I am searching from the log table and not always the id will be the same, why I used the like. How to 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 
  • With several LIKE with % I don’t think there’s much to improve

  • You can take a look at the answers to this question: https://answall.com/questions/173358/comorbetter-performance-de-leitura-de-um-banco-data

  • @Renanbessa: I could add, in the description of the question, information like : (1) What is the purpose of the query? (2) What contains and how is the LOGDESCRICAO column structured? // I found strange the use of % in the middle of the sequences. // The sequences must be searched along the content of LOGDESCRICAO or from the beginning?

1 answer

0


Renan, you use 2 fields that are of the whole type (S.Winning Paused and S.Solstatus) to filter beyond 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.