marrowyung
asked on
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.
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:
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
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:
Well, same request as in your other posts: The entire batch and the actual execution plan, please.
ASKER
here you go.
ExecutionPlan1.sqlplan
ExecutionPlan1.sqlplan
#ResolveIsFuture.[Destinat ionID] as [RF].[DestinationID]=[iXTr ade_Main]. [dbo].[tbR ateAnalysi s].[rDesti nationID] as [R].[rDestinationID]
I am guessing that the #ResolveIsFuture.[Destinat ionID] is not indexed but that the "left semi join" between those 2 tables would be improved by indexing that field.
I am guessing that the #ResolveIsFuture.[Destinat
ASKER
"I am guessing that the #ResolveIsFuture.[Destinat ionID] is not indexed "
because that one is the output list is #ResolveIsFuture.[Destinat ionID] 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 ?
because that one is the output list is #ResolveIsFuture.[Destinat
but that one is a table in tempdB, right? so just index that tempdb table ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
"Which version of SQL Server you have?"
SQL server 2008 R2 SP2 with CU4
"tbRateAnalysis.Destinatio nID should be indexed. And also #ResolveIsFuture.Destinati onID."
I think it should be tbRateAnalysis.RateAnalysi sID and #ResolveIsFuture.Destinati onID, right?
it only has index :
but #ResolveIsFuture is a tempDb table, riht we can simply just go ahead to add an index for it?
SQL server 2008 R2 SP2 with CU4
"tbRateAnalysis.Destinatio
I think it should be tbRateAnalysis.RateAnalysi
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
but #ResolveIsFuture is a tempDb table, riht we can simply just go ahead to add an index for it?
Not tbRateAnalysis.RateAnalysi sID because you don't use that column in the query.
Also your tbRateReAnalysis.rDestinat ionID 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?
Also your tbRateReAnalysis.rDestinat
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?
ASKER
"Also your tbRateReAnalysis.rDestinat ionID 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?
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?
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.
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.
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].[tbRa teAnalysis ].[rDestin ationID] ...
#ResolveIsFuture.[DestinationID]
there is an index already being used for [iXTrade_Main].[dbo].[tbRa
<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]">
ASKER
"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 ?
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 ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
"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.[Destinat ionID] do not have an index? which case a table scan ?
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.[Destinat
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
Then marrowyung just need to create the index in #ResolveIsFuture.
If there is more missing indexes, please post them here.
Cheers
ASKER
tks. clear enought !
http://msdn.microsoft.com/en-us/library/ms190646.aspx