SSMU Web Seminar: Performance
Tuning Series
Part IV: Optimizing Procedure Performance
(Part II)
Q & A
Q: How can I use Profiler to Filter on a stored
procedure name or a procedure object id?
The answer to this one
may seem a bit frustrating BUT the way that Profiler works is that ONLY events
that generate a value for the column can be filtered on that column. If you
ONLY want to see things with a very specific value it can take quite a bit of
time to remove all of the uninteresting events to narrow it down to only what
you need. As for stored procedures – out of the stored procedure events – the objectname is NOT produced for SP:StmtStarting or SP:StmtCompleted
but the ObjectID is. So – there are often cases where
you might see a value for objectname and not for
objected or visa versa. For more details check out the following topics in the
BOL.
Checkout these topics
in the SQL Server Books Online:
Ø
Stored
Procedures Event Category mk:@MSITStore:C:\Program%20Files\Microsoft%20SQL%20Server\80\Tools\Books\adminsql.chm::/event10.gif
Q: When you CREATE a proc with recompile...does it
then always recompile every time it executes?
This is in fact the
pure definition of it. If you create with recompile then no plan is saved and
therefore each execution generates a new plan!
Q: IF the “dbo.” is better then
why doesn’t Microsoft default to it? In
other words, if only the object name is specified why not assume “dbo.” and if not found then look for “user.” instead.
I guess I see your
point but there is the fact that this is not only a flexibility change (in
ownership on creation) but also a backward compatibility change. This behavior
has been for many versions (in fact – I think *all* versions). The only change
is that the object name (the owner) defaults to the local user (the user
creating the object) rather than the dbo if the
creator is only a member of the db_owner role and not
“the” DBO (i.e. the database creator or the database owner changed by the Sys
Admin executing the sp_changedbowner procedure). It’s
really more of a problem with object creation scripts and applications that
assume the creator (or the person running the script) is a Sys Admin (the Sys
Admin will act just like “the” dbo and all objects
will default to dbo.). This is also potentially a
problem when you go from development systems to production (where in Dev you’re
a Sys Admin and in production you might only be “a” member of the db_owner role).
Q: Is there a global way to refresh sysdepends for all objs?
AND
Q: Is there anyway to straighten out the results from sp_depends (and the information in sydepends)
when objects are altered without altering the child procs?
I guess I see your
point but there is the fact that this is not only a flexibility change but also
a backward compatibility change. This behavior has been for many versions (in
fact – I think *all* versions). The
Q: Which event class in profiler identifies recompiles?
The Event Class is SP:Recompile but that’s typically
not enough. What you need to make sure to add is the Data Column: EventSubClass. This column will further describe the reason
for the recompile. To get more details on this review the following whitepaper:
http://msdn.microsoft.com/library/en-us/dnsql2k/html/sql_queryrecompilation.asp?frame=true
and this specific KB Article: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q243586.
Q: Monitoring SP recompilation will help identify procs recompiling too much, but what do you suggest for
identifying procs that are NOT compiling and should?
(i.e., monitor stored proc durations? or something of this nature?
There is no direct way
to look for stored procedures that aren’t be recompiling and should… This can
only occur by evaluating optimal plans and executing procedures with recompile
(which I showed in demos). In other words, you can really only know by doing a
significant amount of testing – at development time preferably – but if you’re
monitoring an existing application and you suspect that performance is affected
by plans which are bad then there are a couple of things to look for… I would
consider looking for plans that have a high number of I/Os (a bad choice that
results in an excessive bookmark lookup) and/or plans where there are lots of
scans and/or plans that seem to very a lot – might do an aggregation where you
look at min execution and compare to max execution – try to resolve why there’s
such an extreme variation…could be a bad plan!
Q: Please, please, please provide more stuff on temp
tables. There's an institutional
insistence on using #temp tables, & I need to determine with certainty when
they're appropriate--and especially when they're not.
Well – we should
almost consider another webseminar for this one! In a
short list of things to do – instead of using temp tables – here are the things
that I’d recommend learning a bit about:
Ø
Derived
Tables – use these to help minimize the complexity of a query by placing a “subquery” in the location of the FROM clause.
Ø
Views –
define each of the temp tables as a view and then join the views instead of the
temp tables. IF this gives you better performance then stick with it…if not –
try seeing if there are better indexes to create instead.
If none of these yield
better performance – then you can certainly go back to using temp tables.
Luckily derived tables and views are fairly easy and fast to create/test! BUT –
you might also consider whether or not the overall process can be more
streamlined.
Q: Is it possible to get each other's email addresses
and start, say a Yahoo! group. Or better
yet, a chat site hosted by Penton with an occasional
guest appearance by Kim?
This is flattering but
I doubt they want to move to “chat” sites with the mag and more than anything I think they’d rather have
people to continue to use what’s available... So – the best choice is to start
a thread on the SQL Magazine forum (on www.sqlmag.com)
and there are also the public newsgroups on Microsoft. I tend to get there as
often as I can and in addition to my experience there are TONS of MVPs and
other SQL Server experts that can quickly help out. Worst case scenario you can
always email me (Kimberly@SQLSkills.com
or Kimberly@SolidQualityLearning.com)
and I’ll try to take a quick stab at it! J To see the list of
newsgroups as well as instructions for using the NNTP newsgroups/browser go to:
http://www.microsoft.com/sql/community/newsgroups/default.asp.
Here are the links I gave out at the end of the
session:
For all MSDN articles see: http://www.microsoft.com/isapi/redir.dll?Prd=msdn&Ar=sqlserver
For all TechNet articles see: http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/sql
Thanks for the great
questions everyone!!
See you at a
conference or another webseminar online – or on the
newsgroups!
Kimberly
President, SYSolutions, Inc. www.SQLSkills.com
Principal Mentor, Solid Quality Learning www.SolidQualityLearning.com