SlideShare a Scribd company logo
Natural Born Killers, performance
issues to avoid
Richard Douglas
Editor in chief of SQLServerPedia
Natural Born Killer




http://www.flickr.com/photos/merille/4747615138/sizes/z/in/photostream/


2   Natural Born Killers
Adhering to best practices?




http://www.flickr.com/photos/12693492@N04/1338123903/sizes/m/in/photostream/


3   Natural Born Killers
Your host

                           • Richard Douglas
                           • Systems Consultant /
                             Editor in Chief of SQLServerPedia
                           • SQL Server MCITPro
                           • Maidenhead SQL User Group Leader
                           • Blog: http://SQL.RichardDouglas.co.uk
                           • Twitter: @SQLRich
                           • Email: Richard.Douglas@Quest.com
                             Richard_Douglas@Dell.com

4   Natural Born Killers
Agenda
• Statistics

• Table Design

• SELECT pitfalls

• RBAR

• Scalar UDF’s

• Indices

• Key lookups

• Sargability

• Table variables

• Parameter sniffing


5   Natural Born Killers
Statistics

• SQL uses a cost based optimizer
• Costs influenced by statistics




6   Natural Born Killers
Statistics
• Creating Statistics
    – Automatic
    – Manual
       –    CREATE STATISTICS
       –    Sp_CreateStats

• Updating Statistics
           Permanent Table                  Temporary Table
           1st record                       1st record
           -                                6 records
           LT 500 recs, 500 changes         LT 500 recs, 500 changes
           GT 500 recs, 500 changes + 20%   GT 500 recs, 500 changes + 20%
• Sp_UpdateStats
• UPDATE STATISTICS

7   Natural Born Killers
Table Design




                           http://www.flickr.com/photos/aresauburnphotos/2699269321/sizes/o/in/photost
                           ream/

8   Natural Born Killers
Example of bad design




9   Natural Born Killers
Example of a better design




10   Natural Born Killers
Table Design – Size comparison




11   Natural Born Killers
Good table design benefits
• Minimise the CPU overhead.
• Increase the number of records in the buffer cache.
• Reduce the amount of physical disk IO.
• Reduce the amount of network traffic.
• Reduce the data file size(s).
• Reduce the working size of the Transaction Log.
• Reduce Full/Diff /T-Log backup file size.
  Thereby increasing your ability to deliver your RTO.
• Keep transaction time to a minimum.
12   Natural Born Killers
Source: http://cheezburger.com/View/5939764992


13   Natural Born Killers
SELECT *
• Returns all data from one or more tables.
     –   Pulls unnecessary data into the buffer cache
     –   Can result in excessive IO
     –   Increases network activity
     –   Can hide important data in Missing Index DMV’s


• Adding new attributes
     – May break existing code


• Increases code fix time

• SQL Azure
     – Paying for data transfer.



14   Natural Born Killers
SELECT * - A resolution




15   Natural Born Killers
RBAR Vs. Set Based




16   Natural Born Killers
Scalar User Defined Functions

• The Good
     – Re-Usable code


• The Bad
     – Runs once per record in record set
     – They don’t take advantage of parallelism
     – They use Nested Loop joins regardless



• The Ugly
     – So ugly it’s hidden from IO statistics
17   Natural Born Killers
Scalar UDF Solutions and Alternatives

• If you have to use them:
     – View the actual IO usage in Profiler


• If you can replace them:
     – Look at Table Value Functions
     – Look at CLR




18   Natural Born Killers
Indexing strategies
It’s all about DWI knowledge:

                            D W n
                            a o
                                I
                            t   r   t
                            a   k   e
                                l   r
                                o   n
                                a   a
                                d   l
                                    s


19   Natural Born Killers
Golden Rules for Clustered Indexes
Bad example; Surname, Firstname, Middle Initial
• Narrow
                                                 Impacts nonclustered indexes
• Static
• Progressive                                    Fragmentation
• Unique
• Fixed width                                    Space impact
• Not Null
                     This example will have 13 bytes of overhead alone;
                     • 4 byte uniquifier
                     • 2 byte variable offset + 6 bytes for variable length fields
 23
                     • 1 byte for NULL values and NULL bitmap
      Natural Born Killers
Golden Rules for NonClustered Indexes

• Have an optimal clustered key
• Not narrow
• Reduce unnecessary overhead
      – Fixed Width
      – Not null

• Consolidate
• Index foreign keys



 24   Natural Born Killers
Key Lookups – The silent killer




25   Natural Born Killers
Sargability

• SARGable – “Search ARGument able”

• T-SQL functions around a predicate can break
  SARGability

• Some caveats to remember




26   Natural Born Killers
Table Variables Vs. Temp Tables

Table Variables
• Fast when used with small data sets.
• Have a limited scope
• Use less locking and logging resources than temp tables
     – http://sql.richarddouglas.co.uk/archive/2011/06/rollback-gotchas-part-2-2.html

• Estimated statistics always show 1 record
• Cannot be altered after they are declared
• Mythbuster - MAY be memory only, this isn’t guaranteed
• Generally faster with smaller data sets

27   Natural Born Killers
Table Variables Vs. Temp Tables

Temp Tables
• Uses statistics
     – Stat population will cause recompiles (statement level in 2005 +)
     – Can create better plans

• Wider scope
• Can be rolled back
• Can be altered after creation
• Generally faster with larger data sets
28   Natural Born Killers
Parameter Sniffing
• What is it?
     – It’s all a matter of statistics


• How do I know when it will affect me?
     – Monitor the IO and CPU
     – This means baselining your environment


• What are my options?
     – Rewrite dynamic queries
     – Query Hints:
        –    WITH RECOMPILE
        –    OPTIMIZE FOR
     – Plan Guides


29   Natural Born Killers
Demo
30
Free posters, training DVDs, white papers, and more
     http://www.quest.com/landing/?id=5700




1.        SQL Server Blog Aggregator & Wiki at http://www.sqlserverpedia.com.
2.        Product Overviews at http://www.quest.com/sql-server/#c-Performance-
          Management. Plus, http://toadworld.com!
3.        Discussion forums at
          http://sqlserver.quest.com/forumindex.jspa?categoryID=208.
4.        Product video tutorials at http://db-
          management.com/blog/category/sqlserver/tutorials-sqlserver/.
     31   Natural Born Killers
Solution Area                        Product                                         Description

    Backup and
                                                                       Fast, flexible backup and recovery with
    Recovery                                                           industry-leading compression technology



    Performance                                                        Discover and resolve performance issues in
                                                                       production before they impact end users and
    & Operations
                                                                       service levels



    Performance                                                        Deepest possible understanding of database
    Tuning                                                             performance and norms



    Development                                                        Plan and develop applications that deliver
                                                                       both functionality and optimal performance


                                                                       Comprehensive schema, object, security and
    Administration                                                     change management

    Community,
                                    Project                            Community crowdsourcing for SQL Server
    Knowledge,
                                                                       tracing and performance information!
    Training                          Lucy
                     © 2012 Quest Software Inc. All rights reserved.                                        Pg. 32

More Related Content

Viewers also liked

'Gaming Startups - What I've Learned'
'Gaming Startups - What I've Learned''Gaming Startups - What I've Learned'
'Gaming Startups - What I've Learned'
damienjoyce
 
Sejarah perkembangan telekomunikasi wa ode zaniba
Sejarah perkembangan telekomunikasi wa ode zanibaSejarah perkembangan telekomunikasi wa ode zaniba
Sejarah perkembangan telekomunikasi wa ode zanibaOperator Warnet Vast Raha
 
International Junior science Olympiad: Best Career Counsellng for students ...
International Junior science  Olympiad:  Best Career Counsellng for students ...International Junior science  Olympiad:  Best Career Counsellng for students ...
International Junior science Olympiad: Best Career Counsellng for students ...
vikas kumar
 

Viewers also liked (6)

Napier Cert
Napier CertNapier Cert
Napier Cert
 
'Gaming Startups - What I've Learned'
'Gaming Startups - What I've Learned''Gaming Startups - What I've Learned'
'Gaming Startups - What I've Learned'
 
Sejarah perkembangan telekomunikasi wa ode zaniba
Sejarah perkembangan telekomunikasi wa ode zanibaSejarah perkembangan telekomunikasi wa ode zaniba
Sejarah perkembangan telekomunikasi wa ode zaniba
 
Bhan hiv
Bhan hivBhan hiv
Bhan hiv
 
L’alfabeto Italiano
L’alfabeto ItalianoL’alfabeto Italiano
L’alfabeto Italiano
 
International Junior science Olympiad: Best Career Counsellng for students ...
International Junior science  Olympiad:  Best Career Counsellng for students ...International Junior science  Olympiad:  Best Career Counsellng for students ...
International Junior science Olympiad: Best Career Counsellng for students ...
 

Similar to 'Natural born killers, SQL performance issues to avoid'

Natural Born Killers, Performance issues to avoid
Natural Born Killers, Performance issues to avoid Natural Born Killers, Performance issues to avoid
Natural Born Killers, Performance issues to avoid
Richard Douglas
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Zohar Elkayam
 
MyHeritage backend group - build to scale
MyHeritage backend group - build to scaleMyHeritage backend group - build to scale
MyHeritage backend group - build to scale
Ran Levy
 
Complex Data Transformations Made Easy
Complex Data Transformations Made EasyComplex Data Transformations Made Easy
Complex Data Transformations Made Easy
Data Con LA
 
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
Lucas Jellema
 
How to Achieve Scale with MongoDB
How to Achieve Scale with MongoDBHow to Achieve Scale with MongoDB
How to Achieve Scale with MongoDB
MongoDB
 
Essential Data Engineering for Data Scientist
Essential Data Engineering for Data Scientist Essential Data Engineering for Data Scientist
Essential Data Engineering for Data Scientist
SoftServe
 
Oracle Database in-Memory Overivew
Oracle Database in-Memory OverivewOracle Database in-Memory Overivew
Oracle Database in-Memory Overivew
Maria Colgan
 
Architecting Your Own DBaaS in a Private Cloud with EM12c
Architecting Your Own DBaaS in a Private Cloud with EM12cArchitecting Your Own DBaaS in a Private Cloud with EM12c
Architecting Your Own DBaaS in a Private Cloud with EM12c
Gustavo Rene Antunez
 
Hi I need security-related job points for the software develope.docx
Hi I need security-related job points for the software develope.docxHi I need security-related job points for the software develope.docx
Hi I need security-related job points for the software develope.docx
fideladallimore
 
Monitoring MySQL at scale
Monitoring MySQL at scaleMonitoring MySQL at scale
Monitoring MySQL at scale
Ovais Tariq
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
Pini Dibask
 
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
Tommy Lee
 
Stardog 1.1: Easier, Smarter, Faster RDF Database
Stardog 1.1: Easier, Smarter, Faster RDF DatabaseStardog 1.1: Easier, Smarter, Faster RDF Database
Stardog 1.1: Easier, Smarter, Faster RDF Database
Clark & Parsia LLC
 
Stardog 1.1: An Easier, Smarter, Faster RDF Database
Stardog 1.1: An Easier, Smarter, Faster RDF DatabaseStardog 1.1: An Easier, Smarter, Faster RDF Database
Stardog 1.1: An Easier, Smarter, Faster RDF Database
kendallclark
 
Modern Data Security with MySQL
Modern Data Security with MySQLModern Data Security with MySQL
Modern Data Security with MySQL
Vittorio Cioe
 
SQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data ArchitectureSQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data Architecture
Venu Anuganti
 
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Manuel Contreras
 
Just the Job: Employing Solr for Recruitment Search -Charlie Hull
Just the Job: Employing Solr for Recruitment Search -Charlie Hull Just the Job: Employing Solr for Recruitment Search -Charlie Hull
Just the Job: Employing Solr for Recruitment Search -Charlie Hull
lucenerevolution
 

Similar to 'Natural born killers, SQL performance issues to avoid' (20)

Natural Born Killers, Performance issues to avoid
Natural Born Killers, Performance issues to avoid Natural Born Killers, Performance issues to avoid
Natural Born Killers, Performance issues to avoid
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
MyHeritage backend group - build to scale
MyHeritage backend group - build to scaleMyHeritage backend group - build to scale
MyHeritage backend group - build to scale
 
Complex Data Transformations Made Easy
Complex Data Transformations Made EasyComplex Data Transformations Made Easy
Complex Data Transformations Made Easy
 
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
50 Shades of Data - how, when and why Big, Fast, Relational, NoSQL, Elastic, ...
 
How to Achieve Scale with MongoDB
How to Achieve Scale with MongoDBHow to Achieve Scale with MongoDB
How to Achieve Scale with MongoDB
 
Essential Data Engineering for Data Scientist
Essential Data Engineering for Data Scientist Essential Data Engineering for Data Scientist
Essential Data Engineering for Data Scientist
 
Oracle Database in-Memory Overivew
Oracle Database in-Memory OverivewOracle Database in-Memory Overivew
Oracle Database in-Memory Overivew
 
Architecting Your Own DBaaS in a Private Cloud with EM12c
Architecting Your Own DBaaS in a Private Cloud with EM12cArchitecting Your Own DBaaS in a Private Cloud with EM12c
Architecting Your Own DBaaS in a Private Cloud with EM12c
 
Hi I need security-related job points for the software develope.docx
Hi I need security-related job points for the software develope.docxHi I need security-related job points for the software develope.docx
Hi I need security-related job points for the software develope.docx
 
Monitoring MySQL at scale
Monitoring MySQL at scaleMonitoring MySQL at scale
Monitoring MySQL at scale
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
 
PostgreSQL and MySQL
PostgreSQL and MySQLPostgreSQL and MySQL
PostgreSQL and MySQL
 
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
제3회난공불락 오픈소스 인프라세미나 - MySQL Performance
 
Stardog 1.1: Easier, Smarter, Faster RDF Database
Stardog 1.1: Easier, Smarter, Faster RDF DatabaseStardog 1.1: Easier, Smarter, Faster RDF Database
Stardog 1.1: Easier, Smarter, Faster RDF Database
 
Stardog 1.1: An Easier, Smarter, Faster RDF Database
Stardog 1.1: An Easier, Smarter, Faster RDF DatabaseStardog 1.1: An Easier, Smarter, Faster RDF Database
Stardog 1.1: An Easier, Smarter, Faster RDF Database
 
Modern Data Security with MySQL
Modern Data Security with MySQLModern Data Security with MySQL
Modern Data Security with MySQL
 
SQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data ArchitectureSQL, NoSQL, BigData in Data Architecture
SQL, NoSQL, BigData in Data Architecture
 
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
Oracle MySQL Tutorial -- MySQL NoSQL Cloud Buenos Aires Nov, 13 2014
 
Just the Job: Employing Solr for Recruitment Search -Charlie Hull
Just the Job: Employing Solr for Recruitment Search -Charlie Hull Just the Job: Employing Solr for Recruitment Search -Charlie Hull
Just the Job: Employing Solr for Recruitment Search -Charlie Hull
 

Recently uploaded

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 

'Natural born killers, SQL performance issues to avoid'

  • 1. Natural Born Killers, performance issues to avoid Richard Douglas Editor in chief of SQLServerPedia
  • 3. Adhering to best practices? http://www.flickr.com/photos/12693492@N04/1338123903/sizes/m/in/photostream/ 3 Natural Born Killers
  • 4. Your host • Richard Douglas • Systems Consultant / Editor in Chief of SQLServerPedia • SQL Server MCITPro • Maidenhead SQL User Group Leader • Blog: http://SQL.RichardDouglas.co.uk • Twitter: @SQLRich • Email: Richard.Douglas@Quest.com Richard_Douglas@Dell.com 4 Natural Born Killers
  • 5. Agenda • Statistics • Table Design • SELECT pitfalls • RBAR • Scalar UDF’s • Indices • Key lookups • Sargability • Table variables • Parameter sniffing 5 Natural Born Killers
  • 6. Statistics • SQL uses a cost based optimizer • Costs influenced by statistics 6 Natural Born Killers
  • 7. Statistics • Creating Statistics – Automatic – Manual – CREATE STATISTICS – Sp_CreateStats • Updating Statistics Permanent Table Temporary Table 1st record 1st record - 6 records LT 500 recs, 500 changes LT 500 recs, 500 changes GT 500 recs, 500 changes + 20% GT 500 recs, 500 changes + 20% • Sp_UpdateStats • UPDATE STATISTICS 7 Natural Born Killers
  • 8. Table Design http://www.flickr.com/photos/aresauburnphotos/2699269321/sizes/o/in/photost ream/ 8 Natural Born Killers
  • 9. Example of bad design 9 Natural Born Killers
  • 10. Example of a better design 10 Natural Born Killers
  • 11. Table Design – Size comparison 11 Natural Born Killers
  • 12. Good table design benefits • Minimise the CPU overhead. • Increase the number of records in the buffer cache. • Reduce the amount of physical disk IO. • Reduce the amount of network traffic. • Reduce the data file size(s). • Reduce the working size of the Transaction Log. • Reduce Full/Diff /T-Log backup file size. Thereby increasing your ability to deliver your RTO. • Keep transaction time to a minimum. 12 Natural Born Killers
  • 14. SELECT * • Returns all data from one or more tables. – Pulls unnecessary data into the buffer cache – Can result in excessive IO – Increases network activity – Can hide important data in Missing Index DMV’s • Adding new attributes – May break existing code • Increases code fix time • SQL Azure – Paying for data transfer. 14 Natural Born Killers
  • 15. SELECT * - A resolution 15 Natural Born Killers
  • 16. RBAR Vs. Set Based 16 Natural Born Killers
  • 17. Scalar User Defined Functions • The Good – Re-Usable code • The Bad – Runs once per record in record set – They don’t take advantage of parallelism – They use Nested Loop joins regardless • The Ugly – So ugly it’s hidden from IO statistics 17 Natural Born Killers
  • 18. Scalar UDF Solutions and Alternatives • If you have to use them: – View the actual IO usage in Profiler • If you can replace them: – Look at Table Value Functions – Look at CLR 18 Natural Born Killers
  • 19. Indexing strategies It’s all about DWI knowledge: D W n a o I t r t a k e l r o n a a d l s 19 Natural Born Killers
  • 20. Golden Rules for Clustered Indexes Bad example; Surname, Firstname, Middle Initial • Narrow Impacts nonclustered indexes • Static • Progressive Fragmentation • Unique • Fixed width Space impact • Not Null This example will have 13 bytes of overhead alone; • 4 byte uniquifier • 2 byte variable offset + 6 bytes for variable length fields 23 • 1 byte for NULL values and NULL bitmap Natural Born Killers
  • 21. Golden Rules for NonClustered Indexes • Have an optimal clustered key • Not narrow • Reduce unnecessary overhead – Fixed Width – Not null • Consolidate • Index foreign keys 24 Natural Born Killers
  • 22. Key Lookups – The silent killer 25 Natural Born Killers
  • 23. Sargability • SARGable – “Search ARGument able” • T-SQL functions around a predicate can break SARGability • Some caveats to remember 26 Natural Born Killers
  • 24. Table Variables Vs. Temp Tables Table Variables • Fast when used with small data sets. • Have a limited scope • Use less locking and logging resources than temp tables – http://sql.richarddouglas.co.uk/archive/2011/06/rollback-gotchas-part-2-2.html • Estimated statistics always show 1 record • Cannot be altered after they are declared • Mythbuster - MAY be memory only, this isn’t guaranteed • Generally faster with smaller data sets 27 Natural Born Killers
  • 25. Table Variables Vs. Temp Tables Temp Tables • Uses statistics – Stat population will cause recompiles (statement level in 2005 +) – Can create better plans • Wider scope • Can be rolled back • Can be altered after creation • Generally faster with larger data sets 28 Natural Born Killers
  • 26. Parameter Sniffing • What is it? – It’s all a matter of statistics • How do I know when it will affect me? – Monitor the IO and CPU – This means baselining your environment • What are my options? – Rewrite dynamic queries – Query Hints: – WITH RECOMPILE – OPTIMIZE FOR – Plan Guides 29 Natural Born Killers
  • 28. Free posters, training DVDs, white papers, and more http://www.quest.com/landing/?id=5700 1. SQL Server Blog Aggregator & Wiki at http://www.sqlserverpedia.com. 2. Product Overviews at http://www.quest.com/sql-server/#c-Performance- Management. Plus, http://toadworld.com! 3. Discussion forums at http://sqlserver.quest.com/forumindex.jspa?categoryID=208. 4. Product video tutorials at http://db- management.com/blog/category/sqlserver/tutorials-sqlserver/. 31 Natural Born Killers
  • 29. Solution Area Product Description Backup and Fast, flexible backup and recovery with Recovery industry-leading compression technology Performance Discover and resolve performance issues in production before they impact end users and & Operations service levels Performance Deepest possible understanding of database Tuning performance and norms Development Plan and develop applications that deliver both functionality and optimal performance Comprehensive schema, object, security and Administration change management Community, Project Community crowdsourcing for SQL Server Knowledge, tracing and performance information! Training Lucy © 2012 Quest Software Inc. All rights reserved. Pg. 32