Are You There, DBA? It’s Me, The App Developer
Who am I? Jacquelyn Keeper C#, ASP.NET, SQL Server, Oracle JacquelynKeeper@ gmail.com Strategies Common roadblocks
DBA vs. Developer Relationship can be contentious Blame game Us or them Work as a team or everyone goes down with the ship. Us v them Dba dev roles users
Developers: How to Ask For Data Provide the query Reasonable result size Specify output format Destructive or long-running query? Warn the DBA! Use app name in connection string
DBAs: How to Provide Data No screenshots Readable format Takeaway
Request/Provide Data Takeaways Few minutes work up front No wasted time or emails
Breaking Out of Your Bubble What causes DBAs and Devs to observe different results?
Parameter Sniffing When a stored procedure is compiled, SQL Server uses the parameter values to create an execution plan.
Parameter Sniffing Demo
Parameter Sniffing – Demo Screenshot “USA” as First Parameter “Canada” as Second Parameter
Parameter Sniffing – Demo Screenshot “Canada” as First Parameter “USA” as Second Parameter
Parameter Sniffing - Takeaways Performance can vary significantly depending on your parameter values Make sure DBA and Developer use the same parameter values when troubleshooting
Breaking Out of Your Bubble - Take 2 What causes DBAs and Devs to observe different results?
Different Clients, Different Plans Even when executing a stored procedure using the same parameter values, an application may get a different query plan than SSMS. Different clients, different plans? Different plans, different results?
Default Cache Key Settings Applications using ADO.NET, ODBC, or OLE DB SSMS SQLCMD, BCP, SQL Server Agent QUOTED_IDENTIFIER ON OFF ARITHABORT Source: Slow in the Application, Fast in SSMS? Understanding Performance Mysteries, http://www.sommarskog.se/query-plan-mysteries.html
Query Plan Cache Demo Clear query cache. Run proc from SSMS. Show query cache. Rerun proc from SSMS with different parameter value. Show query cache. Run proc from SSMS. Show query cache.
Query Plan Cache – Demo Screenshot Stored procedure executed twice, only 1 plan in cache
Query Plan Cache – Demo Screenshot Run stored procedure from application, 2 plans in cache
Detour – My demos aren’t working?!? Plan cache getting cleared within in a few seconds! Check SQL Server error log KB 918483 might be affecting you too! https://support.microsoft.com/en-us/help/918483/how-to-reduce-paging-of-buffer-pool-memory-in-the-64-bit-version-of-sq Lock pages in memory option
Getting the Execution Plan Get the actual plan, not the estimate Use Profiler to capture the application query plan Using Profiler can cause performance issues!
Actual Execution Plan Demo Have a template ready with the correct events selected
Actual Execution Plan – Demo Screenshot
Reading the Execution Plan SQL Sentry Plan Explorer Integrates with SSMS https://www.sentryone.com/plan-explorer
Techniques for troubleshooting together Tips & Tricks Techniques for troubleshooting together
Statistics DBA Consider a weekly or monthly job to update statistics. Developer Some tables may need frequently updated statistics.
Compare Execution Plans SSMS Application
Query Types Stored Procedures Use whenever possible Easy to change Dynamic SQL Sometimes unavoidable Consider using snippets
Get Creative Option Recompile Plan Guides Partition Meetup Force a good plan to be used Option Recompile Work around parameter sniffing Partition Force queries to use a single partition Meetup In person brainstorming session
Learn from each other!
DBAs & Developers… this is the beginning of a beautiful friendship!
Questions? JacquelynKeeper@gmail.com ?
I made use of the following resources: Credits I made use of the following resources: Presentation template by SlidesCarnival The truly excellent article “Slow in the Application, Fast in SSMS? Understanding Performance Mysteries” by Erland Sommarskog http://www.sommarskog.se/query-plan-mysteries.html