Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Hits and Misses Expand / Collapse
Author
Message
Posted Friday, March 4, 2005 3:03 PM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Wednesday, May 22, 2013 10:04 AM
Points: 585, Visits: 53
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/mmetcalf/hitsandmisses.asp
Post #165863
Posted Thursday, March 10, 2005 1:57 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Sunday, November 10, 2013 11:52 AM
Points: 877, Visits: 188

Mike,

That was a great article and told me somethnig I didn't know. Thanks.

I'm interested in one thing you said though: "If you are seeing a high proportion of misses as opposed to hits then you should consider going back and checking that all objects are being called with the correct owner and also that they are being passed in the same case as they were originally created."

What in your opinion (or anyone else's opinion) would constitute "a high proportion of misses as opposed to hits"? We're talking ratios here aren't we? At what ratio do I need to start worrying?

 

As an aside, what is SQL DevCon 2005? I live in London and have never heard of it.

Thanks again. Cracking article.



Jamie Thomson
http://sqlblog.com/blogs/jamie_thomson
Post #166782
Posted Thursday, March 10, 2005 2:12 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 11, 2013 3:30 AM
Points: 127, Visits: 40

Supurb article Mike, cheers.

As for Devcon Jamie, see http://www.devweek.com/ its probabbly he bigest in the UK and generally the one to go for, if you only go to one.

Post #166786
Posted Thursday, March 10, 2005 2:52 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
I agree with the others, very interesting article and something that I did not know about. However, I am not quite sure that everything is fully correct in the article, or at least I am not sure what conclusions to draw from it. First off, I could not trace any SP:CacheMiss events when only the casing of the parameter(s) to procedures changed. No matter how I wrote them I never got a cache miss if that was the only change in the call to the procedure. And since only the procedure name is stored with the cache object (and used when looking for a cached plan) I can not see how it could work differently.

Furthermore, I do not think that the plans are actually recompiled, even though there is sometimes a SP:CacheMiss (when using incorrect case for procedure name). You wrote that even if a procedure is executed using incorrect casing it is still stored in the cache with the correct casing (the way it was once created using CREATE PROC). You can see this in syscacheobjects, where the sql column stores the procedure name in correct casing, so we know that the name is looked up. From this I draw the conclusion that the same thing happens when you later on call the procedure, using incorrect case. The SP:CacheMiss we are seeing is for the cached object with the incorrect casing. Since none can exist (it will always be correctly cased) we get a cache miss. This is of course good, since otherwise there would be different plans for the same procedure. Note that if the server would be using case-sensitive settings then there could be two procs with the same name, only using different casing, and they should of course have different plans.

After the cache miss SQL Server looks for a cached plan stored with the correctly cased procedure name (which it now looks up). If one is found then that plan is used. You can see this by watching the value in column UseCounts incrementing one step each time the procedure is executed, irregardless of whether or not the name is correctly cased and we are seeing an SP:CacheMiss or not. Also, in SQL Profiler, add the data column ObjectName to the output. Then you will see what the cache lookup is actually missing. Clear the cache (using DBCC FREEPROCCACHE) and then execute the procedure using incorrect casing for the proc name. In Profiler you will see two cache misses, first for the incorrectly cased name, next for the correctly cased name. Since this is the first time the proc is executed (after clearing the cache) this is the behaviour we could expect. After this there is an SP:CacheInsert event, which of copurse inserts that plan to the cache using the correctly cased name of the proc.

At least this is the conclusions I draw from experimenting a little with this, but I might be wrong here. Otherwise, in summary I think the implications of this problem is even smaller than it would be with a lot of recompiles, although I for one definitely agree that any small thing that helps performance is always a good thing. Like you said, if SQL Server is spending (any) time doing anything that it would not have needed to if we only coded correctly, then we should not be happy with ourselves.

Thanks again for the article and for teaching me something new.




--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #166798
Posted Thursday, March 10, 2005 5:27 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 3:07 AM
Points: 2,916, Visits: 1,854
If the cache is case sensitive then surely this also has implications for sp_executesql?


LinkedIn Profile
Newbie on www.simple-talk.com
Post #166826
Posted Thursday, March 10, 2005 6:16 AM
UDP Broadcaster

UDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP BroadcasterUDP Broadcaster

Group: General Forum Members
Last Login: Saturday, February 28, 2009 6:51 AM
Points: 1,489, Visits: 7
Very good point David. And it is in fact much worse for sp_executesql, since there it means that a new plan must be compiled (and cached) in order to execute a prepared statement that is exactly the same as a previous one except for casing. The reason is that for statements it is the entire statement that is matched (with a hashing function) to the one stored in the cache. For procs it is only the proc name, so SQL Server can much easier gather the correctly cased name (in fact it already has got it since it needed the proc definition to compile it) for storing. For a statement it would need to gather (and replace) all the object names used in the statement, plus use one case for all keywords. Using the following test script you can see that it does not do that.

----------------------------------

use northwind

dbcc freeproccache

declare @sql1 nvarchar(500)
set @sql1 = N'select * from dbo.Orders'

declare @sql2 nvarchar(500)
set @sql2 = N'select * FROM dbo.Orders'

exec sp_executesql @sql1
exec sp_executesql @sql2

exec sp_executesql @sql1
exec sp_executesql @sql2

exec sp_executesql @sql1
exec sp_executesql @sql2

-- Note the two plans for the same statement only differing in case for the keyword FROM
-- Also note how UseCounts show each one is used three times
-- Finally, also note that the two plans are stored in different hash buckets, so they cannot be matched of course
select * from master..syscacheobjects
----------------------------------




--
Chris Hedgate http://www.hedgate.net/
Contributor to the Best of SQL Server Central volumes
Articles: http://www.sqlservercentral.com/columnists/chedgate/
Post #166841
Posted Thursday, March 10, 2005 7:22 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: Moderators
Last Login: Friday, November 14, 2014 10:06 AM
Points: 8,370, Visits: 745

First off it is a very good article and pointed out something I never noticed before.

But I do agree with Chris.

Only when the name of the executing SP was different in case did I see a CacheMiss. When the name of the parameters were not exactly cased the same it made no difference.

And I never saw a recompile occurr or a new CacheInsert. I just saw a CacheMiss. Of course this still means a performance degrade on high transaction systems.

As for the question earlier about how many would you say before you consider it bad. I would suggest any, you just simple want to avoid as much unneeded work on SQLs part as much as possible.




Post #166860
Posted Thursday, March 10, 2005 7:38 AM
SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: Moderators
Last Login: Friday, November 14, 2014 10:06 AM
Points: 8,370, Visits: 745
Also tested the same things with SQL 7 and it behaved differently with this. Case made no difference on the third or forth run afterwards. So is this specific to 2000?


Post #166867
Posted Thursday, March 10, 2005 8:17 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Friday, November 21, 2014 6:34 AM
Points: 6,259, Visits: 2,031

I have a friend who develops on case-sensitive servers and his opinion is that what he develops will also work on case-insensitive ones. He will love to see this one.

BTW Thanks for the article (Another trick for my bag)

 




* Noel
Post #166885
Posted Thursday, March 10, 2005 9:28 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, November 17, 2014 2:18 PM
Points: 1,035, Visits: 411

First off, thank you for the article.  It isn't very often that I get to read an article that really teaches me something new and explains something that has left me totally puzzled in the past.  That said, I think Chris' analysis is probably correct.  I saw cache misses, but not recompiles; and the capitalization of parameter names apparently doesn't have any effect on this.

I had noticed several years ago that one of our applications tended to generate many cache misses, but not a lot of recompiles.  Adding more RAM to the system helped overall performance, but not this particular situation.  I could never come up with a plausible explanation, this fits the bill.

Thanks again for sharing this bit of information.




/*****************

If most people are not willing to see the difficulty, this is mainly because, consciously or unconsciously, they assume that it will be they who will settle these questions for the others, and because they are convinced of their own capacity to do this. -Friedrich August von Hayek



*****************/
Post #166919
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse