SlideShare a Scribd company logo
Tuna Helper
For SQL Server DBAs
  Speaker: Dean Richards
  Senior DBA, Confio Software


  San Francisco SQL Server User Group
               April 2010




     Mark Ginnebaugh, User Group Leader,
           mark@designmind.com
Tuna Helper
    Proven Process for SQL Tuning
               Dean Richards
        Senior DBA, Confio Software



2
Tuna Helper – Proven Process for SQL Tuning




         Give a man a fish and you feed him for a day.
       Teach a man to fish and you feed him for a lifetime.
                       Chinese Proverb
3
Who Am I?

    Senior DBA for Confio Software
    • DeanRichards@confio.com
    Current – 20+ Years in SQL Server & Oracle
    • DBA and Developer
    Specialize in Performance Tuning
    Review Performance of 100’s of Databases for
    Customers and Prospects
    Common Thread – Paralyzed by Tuning


4
Agenda

    Introduction
    Challenges
    Identify - Which SQL and Why
    Gather – Details about SQL
    Tune – Case Study
    Monitor – Make sure it stays tuned




5
Introduction

    Tuning is Hard
    This Presentation is an Introduction
    • 3-5 day detailed classes are typical
    Providing a Framework
    •   Helps develop your own processes
    •   There is no magic tool
    •   Tools cannot reliably tune SQL statements
    •   Tuning requires the involvement of you and other
        technical and functional members of team


6
Challenges

    Requires Expertise in Many Areas
    • Technical – Plan, Data Access, SQL Design
    • Business – What is the Purpose of SQL?
    Tuning Takes Time
    • Large Number of SQL Statements
    • Each Statement is Different
    Low Priority in Some Companies
    • Vendor Applications
    • Focus on Hardware or System Issues


7
Identify – End-to-End

    Business Aspects
    •   Who registered yesterday for SQL Tuning
    •   Why does the business need to know this
    •   How often is the information needed
    •   Who uses this information
    Technical Information
    • Review ERD
    • Understand tables and the data (at a high level)
    End-to-End Process
    • Understand application architecture
    • What portion of the total time is database
    • Where is it called from in the application

8
Identify – End-to-End Time




9
Identify – Which SQL
       User / Batch Job Complaints
       Tracing a Session / Process
       Queries Performing Most I/O (LIO, PIO)
       Queries Consuming CPU
       Queries Doing Table or Index Scans
       Known Poorly Performing SQL
       Highest Response Times (Wait Types)
     SELECT sql_handle, statement_start_offset,
        statement_end_offset, plan_handle, execution_count,
        total_logical_reads, total_physical_reads,
        total_elapsed_time, st.text
     FROM sys.dm_exec_query_stats AS qs
     CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
     ORDER BY total_elapsed_time DESC


10
Measure Response/Wait Time

     Focus on End User Response Time




      Understand the total time a Query spends in Database
      Measure time while Query executes
      SQL Server helps by providing Wait Types
11
Banking Analogy


     Tellers are the CPUs
     Customers being helped are “running”
     Customers waiting in line are “runnable”
     Customer 1 Requires Higher Level Signature
      • Customer 1 “waits” on “Signature”
      • Customer 2 is checked out, i.e. “running”
      • Customer 3 is “runnable”
     Signature is Completed
      • Customer 1 goes to “runnable”


12
Wait Time Tables (SQL 2000)

          http://support.microsoft.com/kb/822101

                           WaitType – internal binary, 0
     sysprocesses
     loginame              means SPID is on CPU and not
     hostname
     programname
     spid
                           waiting
     dbid
     waittype
     waittime
                           LastWaitType – string value
     lastwaittype
     waitresource          WaitTime – ms of wait for
     sql_handle
     stmt_start
     stmt_end
                           current waittype
     cmd
                           WaitResource – more details
                           about what is being waited on

13
Wait Time Tables (SQL 2005/8)

     http://msdn.microsoft.com/en-us/library/ms188754.aspx

         dm_exec_requests               dm_exec_query_stats
         start_time                     execution_count
         status                         total_logical_writes
         sql_handle                     total_physical_reads
         plan_handle                    total_logical_reads
         start/stop offset
         database_id
         user_id
         blocking_session
         wait_type                      dm_exec_query_plan
         wait_time                      query_plan




         dm_exec_sessions
         login_time
                                       dm_exec_sql_text
         login_name
                                       text
         host_name
         program_name
         session_id


14
DBCC SQLPERF(WAITSTATS)




15
Wait Time Scenario

     Which scenario is worse?
     SQL Statement 1
     • Executed 100 times
     • Caused 10 minutes of wait time for end user
     • Waited 90% of time on “PAGEIOLATCH_SH”
     SQL Statement 2
     • Executed 1 time
     • Caused 10 minutes of wait time for end user
     • Waited 90% on “LCK_M_X”


16
Identify – Simplification

     Break Down SQL Into Simplest Forms
     •   Complex SQL becomes multiple SQL
     •   Sub-Queries Should be Tuned Separately
     •   Tuned SQL in Stored Procedures Separately
     •   Get the definition of views
     •   Understand Distributed Queries




17
Identify – Summary

     Determine the SQL
     Understand End-to-End
     Measure Wait Time
     Simplify Statement




18
Gather - Metrics

     Get baseline metrics
     • How long does it take now
     • What is acceptable (10 sec, 2 min, 1 hour)
     Collect Wait Type Information
     •   Locking / Blocking (LCK)
     •   I/O problem (PAGEIOLATCH)
     •   Latch contention (LATCH)
     •   Network slowdown (NETWORK)
     •   May be multiple issues
     •   All have different resolutions
     Document everything in simple language
19
Gather – Execution Plan

     SQL Server Management Studio
     • Estimated Execution Plan - can be wrong
     • Actual Execution Plan – must execute query, can be
       dangerous in production and also wrong in test
     SQL Server Profiler Tracing
     • Event to collect: MISC: Execution Plan
     • Works when you know a problem will occur
     DM_EXEC_QUERY_PLAN
     • Real execution plan of executed query



20
DM_EXEC_QUERY_PLAN




21
Gather – Bind Values

       <is there something like V$SQL_BIND_CAPTURE>

     SELECT name, position, datatype_string, value_string
     FROM   v$sql_bind_capture
     WHERE sql_id = '15uughacxfh13';

     NAME    POSITION DATATYPE_STRING VALUE_STRING
     ----- ---------- --------------- ------------
     :B1            1 BINARY_DOUBLE

       Bind Values also provided by tracing
        • Level 4 – bind values
        • Level 8 – wait information
        • Level 12 – bind values and wait information



22
Example SQL Statement

       Who registered yesterday for SQL Tuning
     SELECT s.fname, s.lname, r.signup_date
     FROM   student s
     INNER JOIN registration r ON
            s.student_id = r.student_id
     INNER JOIN class c ON
            r.class_id = c.class_id
     WHERE c.name = 'SQL TUNING'
     AND    r.signup_date BETWEEN @BeginDate
                              AND @EndDate
     AND    r.cancelled = 'N'

       Execution Time – 1:30 to execute
       Wait Types – Waits 90% on PAGEIOLATCH_SH
23
Execution Plan




24
Gather - Relationships


     CLASS          REGISTRATION   STUDENT
      class_id       class_id       student_id
      name           student_id     fname
      class_level    signup_date    lname
                     cancelled




25
Gather – Table Information

     Table Definition
     • Where does it physically reside
     • Large columns?
     • Data Profile Viewer – Integration Services
     Existing Indexes
     • Names of all existing indexes
     • Columns those indexes contain




26
Gather – Summary

     Metrics
     • How long does it take currently
     • What does the query wait for (wait types)
     Plan
     • DM_EXEC_QUERY_PLAN
     • Actual Execution Plan
     • Do not use Estimated Plans unless necessary
     Table Relationships
     Table Information
     • Columns and Existing Indexes
27
Tune – Create SQL Diagram
      SQL Tuning – Dan Tow
        • Great book that teaches SQL Diagramming
        • http://www.singingsql.com

                             registration       .04
                             5         30


                         1                  1


                       student           class        .002



     select count(1) from registration where cancelled = 'N'
     and signup_date between '2009-04-08 00:00' and '2009-04-08 23:59'

     3562 / 80000 = .0445

     select count(1) from class where name = 'SQL TUNING'

     2 / 1000 = .002
28
Tune – New Execution Plan
     create index cl_name on class(name)




       Metric – Takes 0:20 to execute
       Why would an Index Scan still occur on REGISTRATION?
29
Gather – Existing Indexes




30
Tune – New Execution Plan

     create index reg_alt on registration(class_id)




       Metric – Takes 0:03 to execute

31
Tune – Better Execution Plan

     create index reg_alt on registration(class_id)
     include (signup_date, cancelled)




       Metric – Takes 0:01.8 to execute
32
Tune – Alternative from SSMS
     create index reg_can on registration(cancelled, signup_date)
     include (class_id, student_id)




       Metric – Takes 0:08 to execute

33
Monitor

     Monitor the improvement
      •   Be able to prove that tuning made a difference
      •   Take new metric measurements
      •   Compare them to initial readings
      •   Brag about the improvements – no one else will
     Monitor for next tuning opportunity
      • Tuning is iterative
      • There is always room for improvement
      • Make sure you tune things that make a difference
     Shameless Product Pitch - Ignite

34
Ignite for SQL Server




                            40%
                        Improvement




35
Summary

     Identify
     •   What is the Bottleneck
     •   End-to-End view of performance
     •   Simplify
     Gather
     •   Metrics – Current Performance
     •   Wait Time
     •   Execution Plan
     •   Object Definitions and Statistics
     Tune
     •   SQL Diagrams – Dan Tow
     Monitor
     •   New Metrics, Wait Time Profile, Execution Plan

36
Confio Software

     Wait-Based Performance Tools
     Igniter Suite
     • Ignite for SQL Server, Oracle, DB2, Sybase
     Provides Help With
     • Identify
     • Gather
     • Monitor
     Based in Colorado, worldwide customers
     Free trial at www.confio.com

37
To learn more or inquire about speaking opportunities, please contact:

                Mark Ginnebaugh, User Group Leader
                      mark@designmind.com

More Related Content

What's hot (20)

PDF
Performance tuning in sql server
Antonios Chatzipavlis
 
PPTX
Oracle sql high performance tuning
Guy Harrison
 
PPT
Sql Server Basics
rainynovember12
 
PPT
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
John Kanagaraj
 
PDF
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
PDF
Oracle Database Performance Tuning Concept
Chien Chung Shen
 
PPTX
Top 10 tips for Oracle performance (Updated April 2015)
Guy Harrison
 
PPT
Sql Server Performance Tuning
Bala Subra
 
PPTX
AWR and ASH Deep Dive
Kellyn Pot'Vin-Gorman
 
PPTX
SQL Plan Directives explained
Mauro Pagano
 
PPTX
Adapting and adopting spm v04
Carlos Sierra
 
PDF
SQL Monitoring in Oracle Database 12c
Tanel Poder
 
PPTX
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Carlos Sierra
 
PPTX
Online index rebuild automation
Carlos Sierra
 
PPTX
SKILLWISE-DB2 DBA
Skillwise Group
 
PDF
Optimizer Hints
InMobi Technology
 
PPTX
Database Performance Tuning
Arno Huetter
 
PPTX
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Carlos Sierra
 
PDF
Analyzing and Interpreting AWR
pasalapudi
 
PPT
Ms sql server architecture
Ajeet Singh
 
Performance tuning in sql server
Antonios Chatzipavlis
 
Oracle sql high performance tuning
Guy Harrison
 
Sql Server Basics
rainynovember12
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
John Kanagaraj
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
Oracle Database Performance Tuning Concept
Chien Chung Shen
 
Top 10 tips for Oracle performance (Updated April 2015)
Guy Harrison
 
Sql Server Performance Tuning
Bala Subra
 
AWR and ASH Deep Dive
Kellyn Pot'Vin-Gorman
 
SQL Plan Directives explained
Mauro Pagano
 
Adapting and adopting spm v04
Carlos Sierra
 
SQL Monitoring in Oracle Database 12c
Tanel Poder
 
Understanding How is that Adaptive Cursor Sharing (ACS) produces multiple Opt...
Carlos Sierra
 
Online index rebuild automation
Carlos Sierra
 
SKILLWISE-DB2 DBA
Skillwise Group
 
Optimizer Hints
InMobi Technology
 
Database Performance Tuning
Arno Huetter
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Carlos Sierra
 
Analyzing and Interpreting AWR
pasalapudi
 
Ms sql server architecture
Ajeet Singh
 

Viewers also liked (20)

PDF
Performance tuning and optimization (ppt)
Harish Chand
 
PDF
SQL Server Query Tuning Tips - Get it Right the First Time
Dean Richards
 
PPT
Sql server performance tuning
ngupt28
 
PPTX
SQL Server Query Optimization, Execution and Debugging Query Performance
Vinod Kumar
 
PDF
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
PPSX
Database Performance Tuning Introduction
MyOnlineITCourses
 
PPTX
Microsoft SQL Server internals & architecture
Kevin Kline
 
PDF
Sql server performance Tuning
Simon Huang
 
PPTX
التحدى 6 الإستعلام بطريقة المعالج
bosy sadek
 
PPSX
Lesson11 Create Query
Abdullatif Tarakji
 
PDF
Trabalho fitos digitais
Guilherme Matias de Medeiros
 
PPSX
Lesson4 Protect and maintain databases
Abdullatif Tarakji
 
PPSX
Lesson8 Manage Records
Abdullatif Tarakji
 
PPTX
MarketLine Country Statistics Database
MarketLine
 
PPTX
Oracle hard and soft parsing
Ishaan Guliani
 
PPTX
Chapter 11new
Weinberghere
 
PPSX
Lesson5 Print and export databases
Abdullatif Tarakji
 
PDF
الوحدة التاسعة - قاعدة البيانات وادارتها
Amin Abu Hammad
 
PDF
Performance Tuning Azure SQL Database
Grant Fritchey
 
PDF
Oracle 11g PL/SQL proqramlamlaşdırma yenilikləri
Ramin Orujov
 
Performance tuning and optimization (ppt)
Harish Chand
 
SQL Server Query Tuning Tips - Get it Right the First Time
Dean Richards
 
Sql server performance tuning
ngupt28
 
SQL Server Query Optimization, Execution and Debugging Query Performance
Vinod Kumar
 
Why & how to optimize sql server for performance from design to query
Antonios Chatzipavlis
 
Database Performance Tuning Introduction
MyOnlineITCourses
 
Microsoft SQL Server internals & architecture
Kevin Kline
 
Sql server performance Tuning
Simon Huang
 
التحدى 6 الإستعلام بطريقة المعالج
bosy sadek
 
Lesson11 Create Query
Abdullatif Tarakji
 
Trabalho fitos digitais
Guilherme Matias de Medeiros
 
Lesson4 Protect and maintain databases
Abdullatif Tarakji
 
Lesson8 Manage Records
Abdullatif Tarakji
 
MarketLine Country Statistics Database
MarketLine
 
Oracle hard and soft parsing
Ishaan Guliani
 
Chapter 11new
Weinberghere
 
Lesson5 Print and export databases
Abdullatif Tarakji
 
الوحدة التاسعة - قاعدة البيانات وادارتها
Amin Abu Hammad
 
Performance Tuning Azure SQL Database
Grant Fritchey
 
Oracle 11g PL/SQL proqramlamlaşdırma yenilikləri
Ramin Orujov
 
Ad

Similar to SQL Server Tuning to Improve Database Performance (20)

PDF
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
PDF
Advanced tips for making Oracle databases faster
SolarWinds
 
PDF
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Zohar Elkayam
 
PPTX
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
SolarWinds
 
PPTX
SQL Server Wait Types Everyone Should Know
Dean Richards
 
PDF
Ebs dba con4696_pdf_4696_0001
jucaab
 
PPTX
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 
PDF
collab2011-tuning-ebusiness-421966.pdf
ElboulmaniMohamed
 
PDF
SQL Server Performance Analysis
Eduardo Castro
 
PDF
Ajuste (tuning) del rendimiento de SQL Server 2008
Eduardo Castro
 
PDF
Collaborate 2019 - How to Understand an AWR Report
Alfredo Krieg
 
PDF
An Approach to Sql tuning - Part 1
Navneet Upneja
 
PPT
Collaborate 2011-tuning-ebusiness-416502
kaziul Islam Bulbul
 
PDF
2013 Collaborate - OAUG - Presentation
Biju Thomas
 
PDF
DB12c: All You Need to Know About the Resource Manager
Maris Elsins
 
PDF
What are you waiting for
Jason Strate
 
PPTX
Wait Watchers ; Gain SQL Performance Increases Fast!
Richard Douglas
 
PDF
Oracle Performance Tuning Fundamentals
Enkitec
 
PDF
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
yishengxi
 
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
Advanced tips for making Oracle databases faster
SolarWinds
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Zohar Elkayam
 
Stop the Chaos! Get Real Oracle Performance by Query Tuning Part 1
SolarWinds
 
SQL Server Wait Types Everyone Should Know
Dean Richards
 
Ebs dba con4696_pdf_4696_0001
jucaab
 
SQL Explore 2012: P&T Part 1
sqlserver.co.il
 
collab2011-tuning-ebusiness-421966.pdf
ElboulmaniMohamed
 
SQL Server Performance Analysis
Eduardo Castro
 
Ajuste (tuning) del rendimiento de SQL Server 2008
Eduardo Castro
 
Collaborate 2019 - How to Understand an AWR Report
Alfredo Krieg
 
An Approach to Sql tuning - Part 1
Navneet Upneja
 
Collaborate 2011-tuning-ebusiness-416502
kaziul Islam Bulbul
 
2013 Collaborate - OAUG - Presentation
Biju Thomas
 
DB12c: All You Need to Know About the Resource Manager
Maris Elsins
 
What are you waiting for
Jason Strate
 
Wait Watchers ; Gain SQL Performance Increases Fast!
Richard Douglas
 
Oracle Performance Tuning Fundamentals
Enkitec
 
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
yishengxi
 
Ad

More from Mark Ginnebaugh (20)

PDF
Automating Microsoft Power BI Creations 2015
Mark Ginnebaugh
 
PDF
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Mark Ginnebaugh
 
PDF
Platfora - An Analytics Sandbox In A World Of Big Data
Mark Ginnebaugh
 
PDF
Microsoft SQL Server Relational Databases and Primary Keys
Mark Ginnebaugh
 
PDF
DesignMind Microsoft Business Intelligence SQL Server
Mark Ginnebaugh
 
PDF
San Francisco Bay Area SQL Server July 2013 meetings
Mark Ginnebaugh
 
PDF
Silicon Valley SQL Server User Group June 2013
Mark Ginnebaugh
 
PDF
Microsoft SQL Server Continuous Integration
Mark Ginnebaugh
 
PDF
Hortonworks Big Data & Hadoop
Mark Ginnebaugh
 
PDF
Microsoft SQL Server Physical Join Operators
Mark Ginnebaugh
 
PDF
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball Approach
Mark Ginnebaugh
 
PDF
Fusion-io Memory Flash for Microsoft SQL Server 2012
Mark Ginnebaugh
 
PDF
Microsoft Data Mining 2012
Mark Ginnebaugh
 
PDF
Microsoft SQL Server PASS News August 2012
Mark Ginnebaugh
 
PDF
Business Intelligence Dashboard Design Best Practices
Mark Ginnebaugh
 
PDF
Microsoft Mobile Business Intelligence
Mark Ginnebaugh
 
PDF
Microsoft SQL Server 2012 Cloud Ready
Mark Ginnebaugh
 
PDF
Microsoft SQL Server 2012 Master Data Services
Mark Ginnebaugh
 
PDF
Microsoft SQL Server PowerPivot
Mark Ginnebaugh
 
PDF
Microsoft SQL Server Testing Frameworks
Mark Ginnebaugh
 
Automating Microsoft Power BI Creations 2015
Mark Ginnebaugh
 
Microsoft SQL Server Analysis Services (SSAS) - A Practical Introduction
Mark Ginnebaugh
 
Platfora - An Analytics Sandbox In A World Of Big Data
Mark Ginnebaugh
 
Microsoft SQL Server Relational Databases and Primary Keys
Mark Ginnebaugh
 
DesignMind Microsoft Business Intelligence SQL Server
Mark Ginnebaugh
 
San Francisco Bay Area SQL Server July 2013 meetings
Mark Ginnebaugh
 
Silicon Valley SQL Server User Group June 2013
Mark Ginnebaugh
 
Microsoft SQL Server Continuous Integration
Mark Ginnebaugh
 
Hortonworks Big Data & Hadoop
Mark Ginnebaugh
 
Microsoft SQL Server Physical Join Operators
Mark Ginnebaugh
 
Microsoft Data Warehouse Business Intelligence Lifecycle - The Kimball Approach
Mark Ginnebaugh
 
Fusion-io Memory Flash for Microsoft SQL Server 2012
Mark Ginnebaugh
 
Microsoft Data Mining 2012
Mark Ginnebaugh
 
Microsoft SQL Server PASS News August 2012
Mark Ginnebaugh
 
Business Intelligence Dashboard Design Best Practices
Mark Ginnebaugh
 
Microsoft Mobile Business Intelligence
Mark Ginnebaugh
 
Microsoft SQL Server 2012 Cloud Ready
Mark Ginnebaugh
 
Microsoft SQL Server 2012 Master Data Services
Mark Ginnebaugh
 
Microsoft SQL Server PowerPivot
Mark Ginnebaugh
 
Microsoft SQL Server Testing Frameworks
Mark Ginnebaugh
 

Recently uploaded (20)

DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Digital Circuits, important subject in CS
contactparinay1
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 

SQL Server Tuning to Improve Database Performance

  • 1. Tuna Helper For SQL Server DBAs Speaker: Dean Richards Senior DBA, Confio Software San Francisco SQL Server User Group April 2010 Mark Ginnebaugh, User Group Leader, [email protected]
  • 2. Tuna Helper Proven Process for SQL Tuning Dean Richards Senior DBA, Confio Software 2
  • 3. Tuna Helper – Proven Process for SQL Tuning Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. Chinese Proverb 3
  • 4. Who Am I? Senior DBA for Confio Software • [email protected] Current – 20+ Years in SQL Server & Oracle • DBA and Developer Specialize in Performance Tuning Review Performance of 100’s of Databases for Customers and Prospects Common Thread – Paralyzed by Tuning 4
  • 5. Agenda Introduction Challenges Identify - Which SQL and Why Gather – Details about SQL Tune – Case Study Monitor – Make sure it stays tuned 5
  • 6. Introduction Tuning is Hard This Presentation is an Introduction • 3-5 day detailed classes are typical Providing a Framework • Helps develop your own processes • There is no magic tool • Tools cannot reliably tune SQL statements • Tuning requires the involvement of you and other technical and functional members of team 6
  • 7. Challenges Requires Expertise in Many Areas • Technical – Plan, Data Access, SQL Design • Business – What is the Purpose of SQL? Tuning Takes Time • Large Number of SQL Statements • Each Statement is Different Low Priority in Some Companies • Vendor Applications • Focus on Hardware or System Issues 7
  • 8. Identify – End-to-End Business Aspects • Who registered yesterday for SQL Tuning • Why does the business need to know this • How often is the information needed • Who uses this information Technical Information • Review ERD • Understand tables and the data (at a high level) End-to-End Process • Understand application architecture • What portion of the total time is database • Where is it called from in the application 8
  • 10. Identify – Which SQL User / Batch Job Complaints Tracing a Session / Process Queries Performing Most I/O (LIO, PIO) Queries Consuming CPU Queries Doing Table or Index Scans Known Poorly Performing SQL Highest Response Times (Wait Types) SELECT sql_handle, statement_start_offset, statement_end_offset, plan_handle, execution_count, total_logical_reads, total_physical_reads, total_elapsed_time, st.text FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st ORDER BY total_elapsed_time DESC 10
  • 11. Measure Response/Wait Time Focus on End User Response Time Understand the total time a Query spends in Database Measure time while Query executes SQL Server helps by providing Wait Types 11
  • 12. Banking Analogy Tellers are the CPUs Customers being helped are “running” Customers waiting in line are “runnable” Customer 1 Requires Higher Level Signature • Customer 1 “waits” on “Signature” • Customer 2 is checked out, i.e. “running” • Customer 3 is “runnable” Signature is Completed • Customer 1 goes to “runnable” 12
  • 13. Wait Time Tables (SQL 2000) http://support.microsoft.com/kb/822101 WaitType – internal binary, 0 sysprocesses loginame means SPID is on CPU and not hostname programname spid waiting dbid waittype waittime LastWaitType – string value lastwaittype waitresource WaitTime – ms of wait for sql_handle stmt_start stmt_end current waittype cmd WaitResource – more details about what is being waited on 13
  • 14. Wait Time Tables (SQL 2005/8) http://msdn.microsoft.com/en-us/library/ms188754.aspx dm_exec_requests dm_exec_query_stats start_time execution_count status total_logical_writes sql_handle total_physical_reads plan_handle total_logical_reads start/stop offset database_id user_id blocking_session wait_type dm_exec_query_plan wait_time query_plan dm_exec_sessions login_time dm_exec_sql_text login_name text host_name program_name session_id 14
  • 16. Wait Time Scenario Which scenario is worse? SQL Statement 1 • Executed 100 times • Caused 10 minutes of wait time for end user • Waited 90% of time on “PAGEIOLATCH_SH” SQL Statement 2 • Executed 1 time • Caused 10 minutes of wait time for end user • Waited 90% on “LCK_M_X” 16
  • 17. Identify – Simplification Break Down SQL Into Simplest Forms • Complex SQL becomes multiple SQL • Sub-Queries Should be Tuned Separately • Tuned SQL in Stored Procedures Separately • Get the definition of views • Understand Distributed Queries 17
  • 18. Identify – Summary Determine the SQL Understand End-to-End Measure Wait Time Simplify Statement 18
  • 19. Gather - Metrics Get baseline metrics • How long does it take now • What is acceptable (10 sec, 2 min, 1 hour) Collect Wait Type Information • Locking / Blocking (LCK) • I/O problem (PAGEIOLATCH) • Latch contention (LATCH) • Network slowdown (NETWORK) • May be multiple issues • All have different resolutions Document everything in simple language 19
  • 20. Gather – Execution Plan SQL Server Management Studio • Estimated Execution Plan - can be wrong • Actual Execution Plan – must execute query, can be dangerous in production and also wrong in test SQL Server Profiler Tracing • Event to collect: MISC: Execution Plan • Works when you know a problem will occur DM_EXEC_QUERY_PLAN • Real execution plan of executed query 20
  • 22. Gather – Bind Values <is there something like V$SQL_BIND_CAPTURE> SELECT name, position, datatype_string, value_string FROM v$sql_bind_capture WHERE sql_id = '15uughacxfh13'; NAME POSITION DATATYPE_STRING VALUE_STRING ----- ---------- --------------- ------------ :B1 1 BINARY_DOUBLE Bind Values also provided by tracing • Level 4 – bind values • Level 8 – wait information • Level 12 – bind values and wait information 22
  • 23. Example SQL Statement Who registered yesterday for SQL Tuning SELECT s.fname, s.lname, r.signup_date FROM student s INNER JOIN registration r ON s.student_id = r.student_id INNER JOIN class c ON r.class_id = c.class_id WHERE c.name = 'SQL TUNING' AND r.signup_date BETWEEN @BeginDate AND @EndDate AND r.cancelled = 'N' Execution Time – 1:30 to execute Wait Types – Waits 90% on PAGEIOLATCH_SH 23
  • 25. Gather - Relationships CLASS REGISTRATION STUDENT class_id class_id student_id name student_id fname class_level signup_date lname cancelled 25
  • 26. Gather – Table Information Table Definition • Where does it physically reside • Large columns? • Data Profile Viewer – Integration Services Existing Indexes • Names of all existing indexes • Columns those indexes contain 26
  • 27. Gather – Summary Metrics • How long does it take currently • What does the query wait for (wait types) Plan • DM_EXEC_QUERY_PLAN • Actual Execution Plan • Do not use Estimated Plans unless necessary Table Relationships Table Information • Columns and Existing Indexes 27
  • 28. Tune – Create SQL Diagram SQL Tuning – Dan Tow • Great book that teaches SQL Diagramming • http://www.singingsql.com registration .04 5 30 1 1 student class .002 select count(1) from registration where cancelled = 'N' and signup_date between '2009-04-08 00:00' and '2009-04-08 23:59' 3562 / 80000 = .0445 select count(1) from class where name = 'SQL TUNING' 2 / 1000 = .002 28
  • 29. Tune – New Execution Plan create index cl_name on class(name) Metric – Takes 0:20 to execute Why would an Index Scan still occur on REGISTRATION? 29
  • 30. Gather – Existing Indexes 30
  • 31. Tune – New Execution Plan create index reg_alt on registration(class_id) Metric – Takes 0:03 to execute 31
  • 32. Tune – Better Execution Plan create index reg_alt on registration(class_id) include (signup_date, cancelled) Metric – Takes 0:01.8 to execute 32
  • 33. Tune – Alternative from SSMS create index reg_can on registration(cancelled, signup_date) include (class_id, student_id) Metric – Takes 0:08 to execute 33
  • 34. Monitor Monitor the improvement • Be able to prove that tuning made a difference • Take new metric measurements • Compare them to initial readings • Brag about the improvements – no one else will Monitor for next tuning opportunity • Tuning is iterative • There is always room for improvement • Make sure you tune things that make a difference Shameless Product Pitch - Ignite 34
  • 35. Ignite for SQL Server 40% Improvement 35
  • 36. Summary Identify • What is the Bottleneck • End-to-End view of performance • Simplify Gather • Metrics – Current Performance • Wait Time • Execution Plan • Object Definitions and Statistics Tune • SQL Diagrams – Dan Tow Monitor • New Metrics, Wait Time Profile, Execution Plan 36
  • 37. Confio Software Wait-Based Performance Tools Igniter Suite • Ignite for SQL Server, Oracle, DB2, Sybase Provides Help With • Identify • Gather • Monitor Based in Colorado, worldwide customers Free trial at www.confio.com 37
  • 38. To learn more or inquire about speaking opportunities, please contact: Mark Ginnebaugh, User Group Leader [email protected]