September 15, 2015 at 11:27 am
Hi I'm trying to create a temp table using the script below and it's taking forever. I was hoping someone might have some tips on hows I could rewrite the code to speed things up. Thanks in advance.
Select ProductName,
Convert(date, messagereceived) as ProcessDate,
datepart(hour,messagereceived) as ProcessHour,
Pipename,Partnername,
DaTEDIFF(SECOND,MessageCreated,MessageReceived) as TransitTime,
DaTEDIFF(SECOND,MessageReceived,ProcessingStarted) as WaitTime,
DaTEDIFF(SECOND,ProcessingStarted,ProcessingFinished) as ProcessingTime
into #Temp
from Table ml
inner join MessagingProduct mp on ml.MessagingProductId=mp.ProductId
where ml.processingstarted > '2015-09-08' and ml.processingstarted < '2015-09-09'
AND
ml.MessagingSystemId=1
September 15, 2015 at 11:43 am
scotsditch (9/15/2015)
Hi I'm trying to create a temp table using the script below and it's taking forever. I was hoping someone might have some tips on hows I could rewrite the code to speed things up. Thanks in advance.
Select ProductName,
Convert(date, messagereceived) as ProcessDate,
datepart(hour,messagereceived) as ProcessHour,
Pipename,Partnername,
DaTEDIFF(SECOND,MessageCreated,MessageReceived) as TransitTime,
DaTEDIFF(SECOND,MessageReceived,ProcessingStarted) as WaitTime,
DaTEDIFF(SECOND,ProcessingStarted,ProcessingFinished) as ProcessingTime
into #Temp
from Table ml
inner join MessagingProduct mp on ml.MessagingProductId=mp.ProductId
where ml.processingstarted > '2015-09-08' and ml.processingstarted < '2015-09-09'
AND
ml.MessagingSystemId=1
it's not the creation of the temp table, it's the query itself.
you have two tables there, one of which was obfuscated but had the alias [ml]
we'd probably ask to see what indexes exist on [ml] and your two tables [MessagingProduct]
because of the join criteria, i'd wild guess that an index on ml.processingstarted , maybe with a filter ON MessagingSystemId=1 might help., if one doesn't already exist. what columns to include, i don't know, the columns in the query are not qualified witht he table alias (ml.messagereceived or mp.messagereceived? which table?)
Lowell
September 15, 2015 at 4:34 pm
Instead of solving queries against this table one at a time, fix them all in one shot.
Cluster the ml table on processingstarted if that is how you typically query against this table. If you needed to, you could add other columns to the clustering key to make the clustering key unique, but that's not critical initially.
Edit: Rephrased for clarity.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
September 15, 2015 at 4:37 pm
Also, the following comparison should be >= instead of just >.
where ml.processingstarted > '2015-09-08'
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply