Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2014-05-30 : 08:31:52
|
I have table E_M (having index in individualid) with 41 million records init, validating the email by comparing the suspect names from the tables ESW,ESP, I have pasted the query below, which takes 5 minites for processing 1 lakh record. please help me to optimise it.declare @CNT int,@Start int=0,@End intselect @CNT=Max(individualid) from E_M (nolock) WHILE(@Start<=@CNT) BEGIN SELECT @End=@Start+1000 INSERT into e_m_1(individualid, validationcode) SELECT individualID ,15 FROM E_M a (NOLOCK) INNER JOIN [ESW] b (NOLOCK) ON(a.email =b.EmailSuspectword ) WHERE individualID >@start AND IndividualID<=@End AND email IS NOT NULL --Whole part check INSERT into e_m_1(individualid, validationcode) SELECT individualID ,14 FROM E_M a (NOLOCK) INNER JOIN [ESP] b (NOLOCK) ON(a.email LIKE '%'+b.EmailSuspectword +'%') WHERE individualID >@start AND IndividualID<=@End AND email IS NOT NULL SELECT @Start=@End ENDthanksSubha |
|
robvolk
Most Valuable Yak
15732 Posts |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-05-30 : 11:12:13
|
In your first inner join you have ON(a.email =b.EmailSuspectword ) Are the join columns indexed?Also, in your second inner join you have ON(a.email LIKE '%'+b.EmailSuspectword +'%') which even if a.email is indexed will still cause a scan, since the LIKE clause is not a SARG. |
 |
|
subhaoviya
Posting Yak Master
135 Posts |
Posted - 2014-05-30 : 11:28:21
|
Hi both, thanks a lot for responseNo i not have index on a.email, i will create index on email,individualid now.thanksfriends |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-05-30 : 11:52:16
|
Do you know what percentage of emails are NULL? If it is small then it may not matter. But, I was thinking that you could put a filtered index on Email where it is not null. *shrug* |
 |
|
|
|
|
|
|