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 ««1234»»»

Why Object Qualification is important. Expand / Collapse
Author
Message
Posted Monday, March 10, 2008 7:48 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, June 17, 2011 8:17 AM
Points: 15, Visits: 70
Thanks,
luckily the nature of and the environment that our system runs in makes security more or less a non-issue. I'll take the example code from the article and see if I can apply the theory to embedded SQL.
Post #466673
Posted Monday, March 10, 2008 7:48 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Thursday, May 29, 2014 12:39 PM
Points: 110, Visits: 495
Roy,

Nice Work !

This is a well written, clear article.

I've always known this to be an issue, and in many places I've worked, we've adamantly forced the qualified naming conventions.

In the relatively new job I have now, we dont enforce the qualified conventions. I'd be very interested to see some quantified measurements of the performance impact that is being introduced here.

Do you have any numbers at all to add to your research?




Gregory A Jackson MBA, CSM
Post #466674
Posted Monday, March 10, 2008 8:09 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, July 17, 2014 10:43 AM
Points: 3,309, Visits: 6,700
Thanks Gregory for the positive feedback. Unfortunately I do not have hard numbers to match what I have said. The main reason is that the profiler does not show any details for cachemiss and Locks Acquired. I have been researching on how to get the numbers but so far I have not succeeded. If I do get any idea regarding this matter, I will surely let you know.



-Roy
Post #466686
Posted Monday, March 10, 2008 8:13 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Thursday, May 29, 2014 12:39 PM
Points: 110, Visits: 495
I would just execute the statement in question 5-10 times while profiling it for duration.

run it 5-10 times without qualified naming and then 5-10 times with qualified names.

average the durations

probably run dbcc freeproccache and dbcc dropcleanbuffers between each execution to standardize the results.

it wont be a perfect test statistically, but you should see some measurable differences....





Gregory A Jackson MBA, CSM
Post #466688
Posted Monday, March 10, 2008 8:14 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:07 AM
Points: 11,157, Visits: 12,899
Drew (3/10/2008)
Thank you for the quick reply, I don't think I was specific enough with my question however.
Let's assume that those queries are not contained in a stored procedure and are executed from our program.
As I understand, frequently run queries will be stored and optimized over time. Could I expect to have these locks occur with these "ad-hoc" queries?
Thanks again.


Based on this quote from Microsoft in article about locking:

"If user "dbo" owns object dbo.mystoredproc, and another user "Harry" runs this stored procedure with the command "exec mystoredproc," the initial cache lookup by object name fails because the object is not owner-qualified. (It is not yet known whether another stored procedure named Harry.mystoredproc exists, so SQL cannot be sure that the cached plan for dbo.mystoredproc is the right one to execute.) SQL Server then acquires an exclusive compile lock on the procedure and makes preparations to compile the procedure, including resolving the object name to an object ID. Before it compiles the plan, SQL Server uses this object ID to perform a more precise search of the procedure cache and is able to locate a previously compiled plan even without the owner qualification.


I would venture to say that locking would not be an issue in the case of ad-hoc sql because the ad-hoc SQL is not compiled like the sp is. You will have the same issues with having to check the ownership and then permissions so it will still be a better practice to qualify the object names anyway. Another thing to note is that if you sometimes qualify the object and sometimes don't you get 2 plans in the cache and in that case you are reducing the actual number of queries that can be cached. Best practices are to always use at least 2 part naming.




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #466690
Posted Monday, March 10, 2008 8:18 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, July 17, 2014 10:43 AM
Points: 3,309, Visits: 6,700
Hi Gregory, Thats worth a try. I will try to do that and see if I can find anything.
Jack, Thanks for answering that. I was not sure about it to say for certain that it wont have an issue.


-Roy
Post #466693
Posted Monday, March 10, 2008 8:55 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, October 16, 2008 10:10 AM
Points: 13, Visits: 15
Good article Roy.

Jack, ad hoc queries are compiled. I believe this started in 2000, if not, then definitely 2005.

Also, that brings up another point, I guess this article was written for 2000 because 2005 Profiler no longer has the event ExecContextHit (that I see). It does have one under Stored Procedures called "Deprecated", maybe that is it?

Btw, when I ran my profile on 2005, I get way more cache misses in both cases than the article says. However, bottom line is that I get twice as many lines in Profiler when I don't qualify as when I do. So it seems like a good idea to do so.

Paul



Post #466732
Posted Monday, March 10, 2008 8:59 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, August 13, 2013 11:43 AM
Points: 242, Visits: 433
Out of curiosity, does specifying the 3-part name for a stored procedure (e.g. srienstr.dbo.sp_diabetes) prevent the check of master for procedures with a prefix of 'sp_'?

Not that I've been foolish enough to make 17 such stored procedures...



Puto me cogitare, ergo puto me esse.
I think that I think, therefore I think that I am.
Post #466736
Posted Monday, March 10, 2008 9:07 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, July 17, 2014 10:43 AM
Points: 3,309, Visits: 6,700
Hi srienstr,

No, Even if you provide the DB and the object qualifier, it will still go through all the hassles of Acquiring a Lock and then releasing it.


-Roy
Post #466742
Posted Monday, March 10, 2008 9:09 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, July 17, 2014 10:43 AM
Points: 3,309, Visits: 6,700
Hi Paul,

Yes, you are right. I had both 2005 and 2000 installed in my local box and ran the tests under 2000 instance.


-Roy
Post #466745
« Prev Topic | Next Topic »

Add to briefcase ««1234»»»

Permissions Expand / Collapse