January 10, 2007 at 10:42 am
Stephane
The scan is scanning the whole index (the whole table in the case of a clustered index) whereas a seek goes straight to where it needs to go to find the data. Therefore a seek is usually desirable. I think the reason for this is that the query optimizer can't use the clustered index to work out the "<= ipTo" part of the "BETWEEN ipFrom and ipTo" clause. Therefore I would recommend you create a non-clustered index on ipTo (assuming that your clustered index is created on ipFrom and ipTo in that order).
John
January 10, 2007 at 11:30 am
Geez...
Still the same results. Works great for 40-50-60, but not for any other number...
I tried this hint:
update
r
set
countryId = c.countryId
from
#regions r join tbl_ip2countries c WITH (INDEX(PK_tbl_ip2countries))
on
r.ipFloat between c.ipFrom and c.ipTo
Does not improve anything...
Thanks for your time guys!
Stephane
January 10, 2007 at 12:44 pm
I made few more tests and It's working great with few hundreds ip. It's really fast.
I'll stick with that from now on!
Thanks a lot!
Stephane
July 29, 2013 at 7:19 am
Hi,
Here is where the problem:
update #regions set countryId = (select countryId from tbl_ip2countries where ipFloat between ipFrom and ipTo)
The above update statment will be executed on (roughly 2000 rows as a sample) all the rows of the temp table whereas it reads the data from the base table which is about 2 million records, hence it would read the records from the base table on each row of the temp table, thus it will use the tempdb for a better performace, the Index spool is happening, why don't you try this with a inner join, so it can search for exact rows and make it faster..
Thanks,
Prabhu
July 29, 2013 at 7:41 am
This thread is six years old.
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
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply