SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update query taking long time
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nandan316
Starting Member

USA
1 Posts

Posted - 11/04/2013 :  16:55:57  Show Profile  Reply with Quote
Hi,

I am trying to update a table with around 500 million rows. The column i am updating is Cost field. Please see the below listed query. The user defined function runs in less than a minute, so its not the issue. But the update statement is taking around 17 -n 18 hours to complete. I have created a index on BuyID,PageID which are the columns used in the where clause of update statement. Can some one please tell me what i need to do to optimize the query?

Thanks

Query:
--------

declare @year int,@month int,@StartDate DateTime,@EndDate DateTime,@Threshold int
SET @year=2013
SET @month=8

SET @StartDate= (Select dateadd(month, @Month - 1, dateadd(year, @Year - 1900, 0)))
SET @EndDate= (Select dateadd(month, @Month,dateadd(year, @Year - 1900, -1)))

select EffectiveCPMRate,DFACampaignId,DFAPlacementId into #CPM
from dbo.udf_GadgetPlacementEffectiveCPMRateForDateRange(@StartDate, @EndDate)

update CT
set CT.[Cost] = ISNULL(((ISNULL(CP.[EffectiveCPMRate],0)/1000)*CT.[Imps]),0)
from Kraft.MonthlySummaryData CT Inner join #CPM CP
on CT.BuyID = CP.DFACampaignId and CT.[PageID] = CP.DFAPlacementId

Edited by - tkizer on 11/04/2013 16:58:17

tkizer
Almighty SQL Goddess

USA
37119 Posts

Posted - 11/04/2013 :  17:00:21  Show Profile  Visit tkizer's Homepage  Reply with Quote
How many rows are there in #CPM? And how many rows match those rows in Kraft.MonthlySummaryData? What does the execution plan show? Is it blocked at times? Have you tried adding an index to #CPM for DFACampaignId,DFAPlacementId?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000