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

Compilation Locks Expand / Collapse
Author
Message
Posted Tuesday, May 11, 2010 11:16 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: Thursday, July 3, 2014 9:59 AM
Points: 990, Visits: 2,217
I'm a bit confused. Several of you suggested using "fully qualified names". But this usually refers to using all 4 parts: Server.Database.Schema.Object.

Is that what you suggest we should use everywhere in code?
Post #919887
Posted Tuesday, May 11, 2010 12:20 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:59 AM
Points: 5,930, Visits: 8,181
rVadim (5/11/2010)
I'm a bit confused. Several of you suggested using "fully qualified names". But this usually refers to using all 4 parts: Server.Database.Schema.Object.

Is that what you suggest we should use everywhere in code?

That was a bit unclear of "several of you" (of which I am one).

In this context, "fully qualified" should be read as "schema-qualified". My apologies.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #919929
Posted Tuesday, May 11, 2010 12:45 PM
Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, December 7, 2010 12:55 AM
Points: 771, Visits: 504
Great question. I learned something new, which is always great!
Post #919943
Posted Tuesday, May 11, 2010 3:16 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 8:24 AM
Points: 21,343, Visits: 15,019
Great question. I learned something good today.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #920047
Posted Tuesday, May 11, 2010 10:11 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, June 30, 2014 2:51 AM
Points: 1,977, Visits: 369
thanks.. good question
Post #920156
Posted Tuesday, May 11, 2010 10:31 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, June 30, 2014 2:51 AM
Points: 1,977, Visits: 369
i generally don't use recompile option for my procs... execution plan is created the first time stored proc is executed and then it takes less time to execute...

plz. suggest... what are the pros & cons of recompile option.
Post #920161
Posted Wednesday, May 12, 2010 1:06 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:59 AM
Points: 5,930, Visits: 8,181
ziangij (5/11/2010)
plz. suggest... what are the pros & cons of recompile option.

Parameter sniffing.

Basically, SQL Server has three ways to deal with constant values in a query:

a) If it's a constant (e.g. WHERE Age = 35), that value is used to optimize. SQL Server will find a plan that is most efficient for that value.

b) If it's a variable (e.g. WHERE Age = @Age), the run-time value is not yet knwon when the query is optimized. Statistical information about the average spread of values in the Age column is used to optimze. The plan SQL Server creates will work good for most values, but might not be optimal for atypical values. If, for instance, a large majority of rows will have an age over 65 and only a small minority will have a younger age (as would be the case in a database of dementia patients), the plan will be optimal when @Age is 80, but less so when @Age is 43.

c) If it's a parameter in a procedure (e.g. CREATE PROC Something @Age int AS .... WHERE Age = @Age), then SQL Server will use ("sniff") the value passed to the parameter when the plan gets created, and find a plan that is optimal for that value. Since the plan goes into cache for future reuse, subsequent executions of the procedure will use the same plan, even if they are called with a different parameter value. In the above case, if the first execution of the procedure happens to use @Age = 43, then it is possible that all future executions with a higher value for @Age are very slow, because SQL Server picked a plan that is optimal for values of @Age where only a small minority of rows match.

In practice, parameter sniffing does more good than it does harm. But in cases where you find it does harm, you can use the RECOMPILE hint to force SQL Server to receompile the plan every time the stored procedure is executed. The benefit is that each execution uses a plan that is optimal for the @Age value passed in (since SQL Server will still sniff the parameter); the down side is that SQL Server has to spend a lot of resources for all those recompilations.



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #920209
Posted Wednesday, May 12, 2010 5:41 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 14, 2014 9:47 AM
Points: 2,919, Visits: 2,525
Thanks for the explanation Hugo. The questio happened to fall while I was on vacation and traveling. In addition to your explanation, each database should have a good maintenance plan. Within that plan should be the updating of statistics on the various indexes as well as rebuilding indexes that need it. I also use a DBCC UPDATEUSAGE as well. After all of my maintenance is completed, I want to ensure that the various stroed procedures are using an optimal QueryPlan. So, the last thing I do is to perform a recompile of all stored procedures and triggers. Ultimately, this will force the procedures to reaquire a new queryplan the first time that they are run.

Additionally, within your explanation, you should go a bit further. It slips me right this moment which hint it is, but for the scenario you describe, there is a hint that can be used in order to have the procedure use the queryplan for the longest running parameter. this takes some effort to identify, but works. I found it while trying to quell an attempted developer revolt, in that the developers wanted to recompile procedures each time that they ran. In a 1200 user high transaction database, where some of these procedures are called literally a hundred times an hour, could be a problem. I will lookup the hint and post it later.


Steve Jimmo
Sr DBA
“If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan
Post #920355
Posted Wednesday, May 12, 2010 6:32 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 8:59 AM
Points: 5,930, Visits: 8,181
sjimmo (5/12/2010)
It slips me right this moment which hint it is, but for the scenario you describe, there is a hint that can be used in order to have the procedure use the queryplan for the longest running parameter.

I think you are referring to the OPTIMIZE FOR option, right?

You can use this to force optimization for the "most often" used vlaue (getting the best performance in most cases, but worse -potentially much worse- in rare cases).
Or you can use it to force optimization for a value that will result in a plan that might not be optimal for all values, but will never hit extreme execution times.

[funny fact - I am typing this right after identifying a query ona customer site where the optimizer decided on a nested loops join and a table scan, based on an estimate of 1 input row; the actual row count turned out to be over 20,000 so a 25,000+-row table got scanned over 20,000 times... - that would be the extreme execution time]



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #920393
Posted Wednesday, May 12, 2010 6:55 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, July 14, 2014 9:47 AM
Points: 2,919, Visits: 2,525
I think you are referring to the OPTIMIZE FOR option, right?


That is the one. Yes there is a down side to it, as with most hints.

Unfortunately, many think that a hint is law, and have spent many hours debating hints, as well as showing hints that work and then not work because the optimizeer deemed that it knew better.

I have not worked with this one yet, but think it is coming with a specific issue. Thanks for the info of your experience.


Steve Jimmo
Sr DBA
“If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan
Post #920420
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse