Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Join on nvarchar column using LIKE


Join on nvarchar column using LIKE

Author
Message
praveen_vejandla
praveen_vejandla
SSC Veteran
SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)

Group: General Forum Members
Points: 249 Visits: 763
UPDATE LII
SET value_exists = 1
FROM LII od
JOIN VPL sl
ON (sl.it like '%' + od.value + '%'
AND od.opr = 9 )
WHERE od.tn = 'VPL'
AND od.cn = 'it'

Is there anyway to rewrite above query for improved performance? I am joining two nvarchar columns (it, value) using LIKE and it seems very slow.

Thanks.
ChrisM@Work
ChrisM@Work
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 8957 Visits: 19016
UPDATE od
SET value_exists = 1
FROM LII od
INNER JOIN VPL sl
ON sl.it LIKE '%' + od.value + '%'
WHERE od.tn = 'VPL'
AND od.cn = 'it'
AND od.opr = 9


The LIKE operator used with a wildcard on the left hand side of the search expression makes the join non-SARGable (Google it), which results in a table scan of table VPL. Do you really need the leading %?

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Bhuvnesh
Bhuvnesh
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2924 Visits: 4076
praveen_vejandla (1/22/2013)
UPDATE LII
SET value_exists = 1
FROM LII od
JOIN VPL sl
ON (sl.it like '%' + od.value + '%'
AND od.opr = 9 )
WHERE od.tn = 'VPL'
AND od.cn = 'it'

Is there anyway to rewrite above query for improved performance? I am joining two nvarchar columns (it, value) using LIKE and it seems very slow.

Thanks.
send the index deifnition of Lil and VPL table

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search