Presentation is loading. Please wait.

Presentation is loading. Please wait.

Query Tuning Fundamentals

Similar presentations


Presentation on theme: "Query Tuning Fundamentals"— Presentation transcript:

1 Query Tuning Fundamentals

2 Vern Rabe Portland, OR independent consultant, trainer
MCTA, MCDBA, MCSE, MCITP VP Oregon PASS chapter Working with/focusing on SQL Server since 1993, starting with SQL Server 4.21a

3 What We’ll Cover The Optimizer Tools Query Writing Suggestions
Stored Procedures Triggers Views Indexes

4 The Optimizer What is it? What does it do?
Not all plans considered (Good enough) Timeout? Statistics> Auto update statistics Auto create statistics

5 Tools What Resource (usually) has Most Performance Impact?
I/O SET STATISTICS> SET STATISTICS IO ON SET STATISTICS TIME ON Execution Plan Estimated vs. Actual> Join types: Merge/Nested Loop/Hash Match Each has its place Execution Logging> “home grown”

6 Query Writing Suggestions
Think set (avoid RBAR) Sometimes “chunk” NOLOCK (READUNCOMMITTED)> Avoid SELECT * in production code Unnecessary bits across the wire Plans often not as efficient> UNION vs. UNION ALL> Always include schema name SET NOCOUNT ON

7 Query Writing Suggestions
SARGable> Watch out for Implicit Conversion> Avoid leading wild card comparisons Avoid user defined scalar functions in predicates> Limit number of JOINs DISTINCT Only UPDATE if something changed>

8 Stored Procedures Why stored procedures? Parameter Sniffing>
Code modularity Pre-compiled Parameter Sniffing> WITH RECOMPILE OPTION (RECOMPILE) Branch Do not name a stored procedure “sp_”…

9 Triggers Can cause performance issues
Try to use CONSTRAINT first Performance issues obfuscated Triggers code is not in Estimated Execution Plan>

10 Views Views per se are not a performance problem
Abuse of views ARE a performance concern Views of views – too many joins and obfuscated Indexed (materialized) views

11 Not sure what should go here
Thanks. Questions? Not sure what should go here @VernRabe Vern Rabe

12 Thanks Questions? Contact information LinkedIn Resources Join operators


Download ppt "Query Tuning Fundamentals"

Similar presentations


Ads by Google