CPU intensive query#3

Dear all,

 I found out some SQL queries that make the CPU hight, tempdb usage hight and I dont' know how to solve, please comment.

UPDATE R							
	SET R.Flag =  CASE WHEN @IsFuture = 1 THEN 33554432						
					   ELSE 0		
				  END			
	FROM tbRateAnalysis R						
	JOIN #ResolveIsFuture RF ON R.rDestinationID = RF.DestinationID						
	WHERE R.OfferID = @OfferID AND R.EffectiveDate = @EffDate						
	-- 2010.04.15 RaS #32826 End						

Open in new window


now the in the execution plan, what I can see the high cost is 1x  table scan and Nested Loop, so how to solve it?

 execution plan:

execution-plan--1.jpg
execution-plan--2.jpg
LVL 1
marrowyungSenior Technical architecture (Data)Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
0
ste5anSenior DeveloperCommented:
Well, same request as in your other posts: The entire batch and the actual execution plan, please.
0
marrowyungSenior Technical architecture (Data)Author Commented:
here you go.
ExecutionPlan1.sqlplan
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PortletPaulfreelancerCommented:
#ResolveIsFuture.[DestinationID] as [RF].[DestinationID]=[iXTrade_Main].[dbo].[tbRateAnalysis].[rDestinationID] as [R].[rDestinationID]

I am guessing that the #ResolveIsFuture.[DestinationID] is not indexed but that the "left semi join" between those 2 tables would be improved by indexing that field.
0
marrowyungSenior Technical architecture (Data)Author Commented:
"I am guessing that the #ResolveIsFuture.[DestinationID] is not indexed "


because that one is the output list is #ResolveIsFuture.[DestinationID]  and this means profiler is looking for an index of that column ?

but that one is a table in tempdB, right? so just index that tempdb table ?
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Which version of SQL Server you have?
Table scan is the worst you can have for tables with millions of rows. At least tbRateAnalysis.DestinationID should be indexed. And also #ResolveIsFuture.DestinationID.
Can you check that?
0
marrowyungSenior Technical architecture (Data)Author Commented:
"Which version of SQL Server you have?"

SQL server 2008 R2 SP2 with CU4

"tbRateAnalysis.DestinationID should be indexed. And also #ResolveIsFuture.DestinationID."

I think it should be tbRateAnalysis.RateAnalysisID and #ResolveIsFuture.DestinationID, right?

it only has index :

CREATE NONCLUSTERED INDEX [IX_tbRateReAnalysis] ON [dbo].[tbRateReAnalysis]
(
	[ReAnalyzeID] ASC,
	[SourceID] ASC,
	[sDestinationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, 

ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO


CREATE NONCLUSTERED INDEX [IX_tbRateReAnalysis_1] ON [dbo].[tbRateReAnalysis]
(
	[ReAnalyzeID] ASC,
	[SourceID] ASC,
	[rDestinationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
GO

Open in new window


but #ResolveIsFuture is a tempDb table, riht we can simply just go ahead to add an index for it?
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Not tbRateAnalysis.RateAnalysisID because you don't use that column in the query.
Also your tbRateReAnalysis.rDestinationID is part of an composed index so SQL Server engine might not use it. That's why you sould create an index only for that field.

When you run the query in SSMS in the query plan view you don't see a line on the top of the diagram advising the creation of an index?
0
marrowyungSenior Technical architecture (Data)Author Commented:
"Also your tbRateReAnalysis.rDestinationID is part of an composed index so SQL Server engine might not use it. That's why you sould create an index only for that field."

I think as long as composed index cover that column, it should be choosen too, right? that why we can sometimes combine index to save space while the index still useful ?

the predicates section show which column an index is being look for ?
 
I think the output  list show me what index SQL is looking for.

"
 When you run the query in SSMS in the query plan view you don't see a line on the top of the diagram advising the creation of an index? "

 
where  ? what did you see?
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
By the query plan isn't using any index, that's why you have a table scan. You should have at least an index scan and you don't have it, so isn't using indexes at all.

And don't create composed indexes for save space. Isn't the idea for these type of indexes. Indexes are for increase performance and not for save space. You create a composed index if you have a long running query that use all those columns and in the same order.

You should see any index creation advice below the query cost and before the diagram. If you don't have it it's because SQL Server engine doesn't think that the query will need it.
0
PortletPaulfreelancerCommented:
It's only the temp table that doesn't have this index.....

#ResolveIsFuture.[DestinationID]

there is an index already being used for [iXTrade_Main].[dbo].[tbRateAnalysis].[rDestinationID] ...

 <RelOp NodeId="3" PhysicalOp="Nested Loops" LogicalOp="Left Semi Join" ...

<ScalarOperator ScalarString="#ResolveIsFuture.[DestinationID] as [RF].[DestinationID]=[iXTrade_Main].[dbo].[tbRateAnalysis].[rDestinationID] as [R].[rDestinationID]">

Open in new window

0
marrowyungSenior Technical architecture (Data)Author Commented:
"You should see any index creation advice below the query cost and before the diagram. If you don't have it it's because SQL Server engine doesn't think that the query will need it. "

I just think you read my plan and you see something.

but one thing, will that place shows all missing indexs we need to create? or just one only ?

"You should have at least an index scan and you don't have it, so isn't using indexes at all.
"

index scan also means performance problem, right? what should be done for that? rebuilt index and update statistics?

"You create a composed index if you have a long running query that use all those columns and in the same order."

so that's why we will have a lot of index for a table anyway !

but in the same order here means ?
0
PortletPaulfreelancerCommented:
cpu-3.pngthere is an index seek, it is the temp table causing the table scan through a left join
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marrowyungSenior Technical architecture (Data)Author Commented:
"there is an index seek"

it should not be a prblem, right?

"it is the temp table causing the table scan through a left join "

so the only problem is
#ResolveIsFuture.[DestinationID] do not have an index? which case a table scan ?
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Thanks PortletPaul. Didn't see that before.
Then marrowyung just need to create the index in #ResolveIsFuture.

If there is more missing indexes, please post them here.

Cheers
0
marrowyungSenior Technical architecture (Data)Author Commented:
tks. clear enought !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.