|
I have just run an estimated execution plan and there is one step that is showing an estimated cost of 92029%! The procedure is intended to delete data from a table based on the values in one date column - if its over 3months old then delete it. The whole query cost is 100% but the clustered index delete is 92029%. In the XML version the %cost is not findable .. :-/ SQL 2005 Std edition 64 bit sp3
(comments are locked)
|
|
Just remember, the estimated costs are just that, estimates. It's not common to see the numbers add up to something other than 100, but it's not uncommon either. It's the main reason why you can't use the estimated costs as the only measure when you're tuning a query. You must refer to the scans, the reads, the execution time, other stuff, as well as the cost estimates in the execution plan.
(comments are locked)
|
|
Heh... I've found the actual costs are also "estimated". Grant will tell you that I have code that proves that even the actual execution plan can be 100% wrong. In fact, here it is...
The reason why the execution plan appears to be so wrong is because only the first iteration of the recursive CTE is being considered. It's the reason why people sometimes think that recursive CTE's are so good instead of being the resource sucking performance hogs they can sometimes be. Jeff, this is really interesting but the code doesnt run as you have provided it:- I've had to add code to create the Tally table. Could you provide a link to the (blog article??) documentation mentioned in the comments please? Thanks for the confirmation that the query plan is not always accurate. I was not wholly surprised but the magnitude of the error was totally unexpected.
Mar 08 '10 at 06:03 AM
Fatherjack ♦♦
Ah... my bad. I've corrected the header. The code was originally sent to Grant Fritchey when he was writing one of his books and I forgot to change the header. The "additional explanations" are mostly included (but greatly simplified) in the non-code text in the post above. I also added a comment so people can find the Tally table article to build one.
Mar 09 '10 at 02:07 AM
Jeff Moden
Thanks for the update, Sorry, I've only now come back to this. I like your proof and I'm not surprised really. What did raise my eyebrows was that the est % was over 92000% - I'd have thought it would just be 100% wrong if anything, not mathmatically impossible. Thanks again.
Mar 22 '10 at 03:05 PM
Fatherjack ♦♦
heh... I'm a little bit behind myself. Thank you for the feedback.
Mar 30 '10 at 09:59 PM
Jeff Moden
(comments are locked)
|
|
That's so not surprising if it is a bug (which it looks like it is). Have you ever tried to work out the costs based on the raw data? That is something that majorly busted my balls when implementing plan viewing for SQL Everywhere. working out the cost on the raw data sounds like a good idea - what do I do, how do I do it??!
Mar 01 '10 at 10:19 AM
Fatherjack ♦♦
@Fatherjack - I can't remember off hand - I'll try and remember to email you later!
Mar 01 '10 at 11:03 AM
Matt Whitfield ♦♦
(comments are locked)
|

