Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking through the plan cache, looking for low-hanging optimization fruit and came across this snippet:

enter image description here

Why are many of the costs listed above 100% ? Shouldn't that be impossible?

share|improve this question
    
I even saw costs of up to 1 mill % from the estimated plan. Just use the real cost, it should be better. – Marian Apr 10 '13 at 20:52
4  
Because SQL Server's math is messed up. Grab our free Plan Explorer; we don't have this problem. – Aaron Bertrand Apr 10 '13 at 21:08
    
I love SQL Sentry Plan Explorer, Aaron - I've been using it for a while now. I want to see what the pro version does! – Max Vernon Apr 10 '13 at 21:18
up vote 9 down vote accepted

The visual cost estimator is crap. This sort of stuff happens all the time. Just go with the highest ones are the most expensive and attack those ones first.

share|improve this answer
    
Have you ever seen this with previous versions of SQL Server? As far as I'm concerned, I've never noticed it on SS 2008R2 for example. – KookieMonster Apr 10 '13 at 20:04
5  
I've seen it all the way back to SQL 2000. Far as I know it's just a bug in SSMS (and EM) when it's doing the math to figure out the percentages. – mrdenny Apr 10 '13 at 20:08
    
Thanks for the info! – KookieMonster Apr 10 '13 at 20:10

I'd been also curious about why sometimes some cost is displayed as 100%, 200%, 300%...and even more. After analyse xml file of query plan, i got it.

The cost percentage = my EstimatedTotalSubtreeCost / parent node's EstimatedTotalSubtreeCost

For example, your query plan shows Clustered Index Insert take cost 914%, to understand how it calculate this percentage, 1. Move mouse to `Clustered Index Insert` to show popup, you can see the cost `EstimatedTotalSubtreeCost`, e.g, 0.2 2. Move mouse to this node's parent node `COND WITH QUERY`, check the popup to get `EstimatedTotalSubtreeCost`, e.g, 0.0218818 3. Calculate 0.2/0.0218818 = 914%, this is the cost percentage displayed in `Clustered Index Insert` popup

share|improve this answer
1  
0.002/2.18 is 0.000917 (which is the same as 0.0917%) and not 914%. – ypercubeᵀᴹ May 11 at 7:31
    
thank you for your comment. I will modify my answer. After all, it is just a sample to show how to calculate the percentage. – osexp2003 May 16 at 4:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.