0
To SQL
below is causing much slowness by the fact that I use the
Right(L.nrDiscado, Len(D.Descricao))
(believe me) to compare with the field D.Descricao
:
create table #TempNrDiscado (NrDiscado varchar(150))
Insert into #TempNrDiscado
Select distinct L.nrDiscado from #TempLigacoes L with(nolock)
inner join GI_Dispositivo D with(nolock) on
Right(L.nrDiscado, Len(D.Descricao)) = D.Descricao
Does anyone know any way I could make that comparison?
Note: if I put a number 10 in place of the Len(D.Descricao) (Right(L.nrDiscado, Len(10))
he goes fast.
Text comparison (
string
) are longer, and in your case have two complicated functions (RIGHT
andLEN
) makes the process more costly, has also a problem perhaps, because do not compare this INNER JOIN by the key that would be correct, you yourself proved that by putting the number 10 the process flows better. I ask why join with texts what is the scenario?– novic
If the field will only be searched this way, it may be the case to create a column/index more suitable for search and (although it seems strange) store inverted. Thus, searches will use index, and a LIKE with % on the right solves. Now, if you want something more traditional, it would be cool to [Dit] the question and give more details of data structures and application requirements.
– Bacco
If I put the 10 in place of Len(), the result is on time!
– cmcampos86
Just to complement, if the data is UTF-8 both Len and right are required to scan all strings from start to finish, and it costs a lot of money. At these times the people who speak ill of ISO disappear :)
– Bacco