SQL Server performance tuning basics

Slides:



Advertisements
Similar presentations
Cardinality How many rows? Distribution How many distinct values? density How many rows for each distinct value? Used by optimizer A histogram 200 steps.
Advertisements

SQL Performance 2011/12 Joe Chang, SolidQ
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Managing and Monitoring SQL Server 2005 Shankar Pal Program Manager SQL Server, Redmond.
Lecture 8 Index Organized Tables Clusters Index compression
DAT304 Managing And Executing Stored Procedures For Performance William R. Vaughn Beta V Corporation.
Denny Cherry Manager of Information Systems MVP, MCSA, MCDBA, MCTS, MCITP.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Applications hitting a wall today with SQL Server Locking/Latching Scale-up Throughput or latency SLA Applications which do not use SQL Server.
Parallel Execution Plans Joe Chang
Module 8: Implementing Stored Procedures. Overview Implementing Stored Procedures Creating Parameterized Stored Procedures Working With Execution Plans.
SQL Dev Tips for Small Workstations How to develop SQL on small dev workstations when prod is huge. Kevin Kline and Aaron Bertrand SQL Sentry.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Query Optimizer Execution Plan Cost Model Joe Chang
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Stored Procedure Optimization Preventing SP Time Out Delay Deadlocking More DiskReads By: Nix.
DAT410 SQL Server 2005 Optimizing Procedural Code Kimberly L. Tripp President/Founder, SQLskills.com.
10g Tuning Highlights Presenter JEREMY SCHNEIDER Senior Consultant, ITC Technology Services.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
IT420: Database Management and Organization Triggers and Stored Procedures 24 February 2006 Adina Crăiniceanu
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
Maciej Pilecki Consultant Project Botticelli Ltd. DAT404.
Fundamentals of Great SQL Query Performance Matt Wigdahl, ScriptPro LLC.
SQL Triggers, Functions & Stored Procedures Programming Operations.
Dave LinkedIn
How to kill SQL Server Performance Håkan Winther.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
High Performance Functions SQLBits VI. Going backwards is faster than going forwards.
This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information.
Parameter Sniffing in SQL Server Stored Procedures
Tuning Transact-SQL Queries
Query Optimization Techniques
Stored Procedures – Facts and Myths
Things You Can Find in the Plan Cache.
Query Tuning without Production Data
Query Tuning without Production Data
Query Tuning without Production Data
SQL Server Monitoring Overview
Reading Execution Plans Successfully
Introduction to Execution Plans
Now where does THAT estimate come from?
Cardinality Estimator 2014/2016
Query Optimization Techniques
Top Tips for Better TSQL Stored Procedures
Statistics: What are they and How do I use them
Steve Hood SimpleSQLServer.com
Reading Execution Plans Successfully
TEMPDB – INTERNALS AND USAGE
The PROCESS of Queries John Deardurff
The PROCESS of Queries John Deardurff Website: ThatAwesomeTrainer.com
Statistics for beginners – In-Memory OLTP
The PROCESS of Queries John Deardurff
Introduction to Execution Plans
Chapter 8 Advanced SQL.
Query Tuning Fundamentals
“Magic numbers”, local variable and performance
Diving into Query Execution Plans
Introduction to Execution Plans
Query Optimization Techniques
Reading execution plans successfully
Introduction to Execution Plans
Presentation transcript:

SQL Server performance tuning basics (for the developers) Dean Vitner SQL/Dev UG Osijek Osijek, 30.01.2014..

Some like it hot CHECKPOINT DBCC DROPCLEANBUFFERS DBCC FREESYSTEMCACHE Store (sys.dm_os_memory_clerks) Database Pool ALL DBCC FREEPROCCACHE Plan handle DBCC FLUSHPROCINDB DB_ID

Testing code as you go Mock up or real data Baseline Multiple runs SSMS SET STATISTICS IO ON Logical vs physical reads SET STATISTICS TIME ON Graphical execution plan Missing index hint DMVs sys.dm_os_wait_stats sys.dm_exec_query_stats sys.dm_exec_procedure_stats

What to look for? Fat arrows Operators Estimates vs actual values Table scans Lookups Hash joins in OLTP workload Joins on non-selective columns Sort & sort warnings Parallelism Implicit conversions Estimates vs actual values Stale statistics Parameter sniffing UDFs Complicated predicates

Cursors and while loops Row-by-agonizing-row (RBAR) Could be useful: Running totals Calling SPs Administrative tasks Default settings: global, scrollable, writeable, dynamic Use LOCAL FAST_FORWARD sp_MSForEachDB is dangerous!

(NOT) IN and friends NULLS are neither equal nor different NOT IN on columns with NULLS will return incorrect data Large IN lists are a performance problem EXCEPT eliminates dups  sort Anti semi join Personally, I’d always prefer (NOT) EXISTS

Updating data Indexes Referential integrity Cascades Large inserts – disable indexes first Consider the whole workload, not just SELECTs Referential integrity Cascades Triggers and rollback from trigger Use CTEs to minimize human errors

Stored procedures SPs are not faster than ad hoc, but… Security is a plus Easier maintenance and tuning Parameterization Greater chance of plan reuse Parameter sniffing problem Recompilation SET NOCOUNT ON

Dynamic search procedures Freely combined search conditions Static code for every combination Maintenance nightmare Static code with WHERE (col = @param or @param IS NULL) Performance issues, recompilation Dynamic SQL with sp_executesql Plan reuse Strongly-typed parameters Injection

OMGs (common misconceptions) Order of predicates matters Table variables are stored differently from #tables COALESCE is better than ISNULL UDF are good Adding hints makes it run faster