|
Greetings, I'm trying to update the columns of one table to contain values copied from a table in a different database. The update statement I'm using is:
The ip2location.dbo.ip2locationData is a table the contains approx 7 million records with regional data based on IP addresses.
I've created non-clustered indexes on the ipFrom and ipTo columns as follows: create nonclustered index idx_ipFrom on ip2locationdata (ipFrom) ON FG_INDEXES create nonclustered index idx_ipTo on ip2locationdata (ipTo) ON FG_INDEXES The loadBannerImpressions table contains approx. 500,000 rows. The update statement tends to take a long time to execute, and I'm wondering if I'm going about this the wrong way. 500,000 rows, joining with a table of 7,000,000 rows is going to eat some CPU time, but I'm wondering if there's a better way I could be doing this? Thanks, Bill
(comments are locked)
|
|
Have you examined the execution plans to see which of the indexes are being used? In all likelihood you will probably need to create a compound index using both the IP columns. SQL Server can do index intersection, but it's not that common for it to do so. You may also need to include the columns from the select list to avoid the key lookup. But again, without the execution plan, it's hard to know. What's the clustered index on ip2locationData? That's an interesting point. I remembered creating a compound index, which, as it happens, is the clustered index: CREATE UNIQUE CLUSTERED INDEX [IDX_IP2LocationData] ON [dbo].[IP2LocationData]([ipFROM], [ipTO]) ON [PRIMARY] The estimated execution plan indicates a table scan on the loadBannerClicks table, and a clustered index seek on the IP2LocationData table. Seems to make sense, based on my limited understanding of these details.
Feb 04 '10 at 03:12 PM
Bill
So, probably you don't need those other indexes at all. What's the index look like on the loadBannerClicks table?
Feb 04 '10 at 03:39 PM
Grant Fritchey ♦♦
There are no indexes on the table loadBannerClicks (or loadBannerImpressions.. sorry, I do the same task for both tables. I was referring to the loadBannerImpressions table in the first post). I didn't expect they'd make much difference, since I'm processing most of the records. I guess I could index the memberNo and/or the clientIPno columns, though. Might that help in this scenario?
Feb 04 '10 at 03:56 PM
Bill
I suspect the clientIPno could speed things up.
Feb 04 '10 at 04:59 PM
Grant Fritchey ♦♦
didn't change the estimated execution plan, but I'll try it out anyway and get back to you. Thanks, Bill
Feb 04 '10 at 05:40 PM
Bill
(comments are locked)
|
|
In SQL Server 2008 and later it's best to avoid using "UPDATE with join". Use MERGE instead. MERGE is frequently more efficieant and is standard SQL whereas UPDATE...JOIN is proprietary. UPDATE...JOIN also gives unpredictable results if the join criteria is non-unique. Good tip. This is SQL Server 2005, however. I'm assuming I should continue as I am... Thanks.
Feb 04 '10 at 04:04 PM
Bill
(comments are locked)
|

