SlideShare une entreprise Scribd logo
1  sur  30
Natural Born Killers,
performance issues to avoid
Richard Douglas
Natural Born Killer

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

2

Natural Born Killers
3

Natural Born Killers
Source: http://cheezburger.com/View/5939764992

4

Natural Born Killers
Adhering to best practices?

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

5

Natural Born Killers
Your host
• Richard Douglas
• Systems Consultant
• 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

6

Natural Born Killers
Agenda
• Statistics
• Table Design
• Scalar UDF’s

• Indices
• Key lookups
• Sargability

• Table variables
• Parameter sniffing

7

Natural Born Killers
Statistics
• SQL uses a cost based optimizer
• Costs influenced by statistics

8

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
9

Natural Born Killers
Table Design

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

10

Natural Born Killers
Example of bad design

11

Natural Born Killers
Example of a better design

12

Natural Born Killers
Table Design – Size comparison

13

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.

14

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 the query plan and IO statistics

19

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

20

Natural Born Killers
Indices

21

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

D W I
a
t
a

22

Natural Born Killers

o
r
k
l
o
a
d

n
t
e
r
n
a
l
s
Golden Rules for Clustered Indexes
Bad example; Surname, Firstname, Middle Initial
• Static

Impacts nonclustered
indexes

• Progressive

Fragmentation

• Narrow

• 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
• 1 byte for NULL values and NULL bitmap
23

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-gotchaspart-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
Demos

30

Natural Born Killers
Summary
• Statistics
• Table Design
• Scalar UDF’s
• Indices
• Key lookups
• Sargability
• Table variables
• Parameter sniffing

31

Natural Born Killers
Any questions?

32

Understanding Indices

Dell Software
Thank you
Richard_Douglas@Dell.com
@SQLRich
http://bit.ly/11jr4fC

Contenu connexe

Tendances

SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2Davide Mauri
 
Ultimate Free SQL Server Toolkit
Ultimate Free SQL Server ToolkitUltimate Free SQL Server Toolkit
Ultimate Free SQL Server ToolkitKevin Kline
 
Reduce latency and boost sql server io performance
Reduce latency and boost sql server io performanceReduce latency and boost sql server io performance
Reduce latency and boost sql server io performanceKevin Kline
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum versionsqlserver.co.il
 
Hadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerHadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerIke Ellis
 
Azure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applicationsAzure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applicationsDavide Mauri
 
Indexes: The neglected performance all rounder
Indexes: The neglected performance all rounderIndexes: The neglected performance all rounder
Indexes: The neglected performance all rounderMarkus Winand
 
Introduction to SQL++ for Big Data: Same Language, More Power
Introduction to SQL++ for Big Data: Same Language, More PowerIntroduction to SQL++ for Big Data: Same Language, More Power
Introduction to SQL++ for Big Data: Same Language, More PowerAll Things Open
 
Is there a SQL for NoSQL?
Is there a SQL for NoSQL?Is there a SQL for NoSQL?
Is there a SQL for NoSQL?Arthur Keen
 
Breaking Spark: Top 5 mistakes to avoid when using Apache Spark in production
Breaking Spark: Top 5 mistakes to avoid when using Apache Spark in productionBreaking Spark: Top 5 mistakes to avoid when using Apache Spark in production
Breaking Spark: Top 5 mistakes to avoid when using Apache Spark in productionNeelesh Srinivas Salian
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONDavide Mauri
 
Fully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data ValidationFully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data ValidationDatabricks
 
Dynamic SQL: How to Build Fast Multi-Parameter Stored Procedures
Dynamic SQL: How to Build Fast Multi-Parameter Stored ProceduresDynamic SQL: How to Build Fast Multi-Parameter Stored Procedures
Dynamic SQL: How to Build Fast Multi-Parameter Stored ProceduresBrent Ozar
 
Simple Works Best
 Simple Works Best Simple Works Best
Simple Works BestEDB
 
Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowKevin Kline
 
Best practices for running MySQL on production - Vaibhav Upadhyay
Best practices for running MySQL on production - Vaibhav UpadhyayBest practices for running MySQL on production - Vaibhav Upadhyay
Best practices for running MySQL on production - Vaibhav UpadhyayMydbops
 
SQL Server 2016 JSON
SQL Server 2016 JSONSQL Server 2016 JSON
SQL Server 2016 JSONDavide Mauri
 

Tendances (20)

SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2SQL Server & SQL Azure Temporal Tables - V2
SQL Server & SQL Azure Temporal Tables - V2
 
Ultimate Free SQL Server Toolkit
Ultimate Free SQL Server ToolkitUltimate Free SQL Server Toolkit
Ultimate Free SQL Server Toolkit
 
Reduce latency and boost sql server io performance
Reduce latency and boost sql server io performanceReduce latency and boost sql server io performance
Reduce latency and boost sql server io performance
 
Products.intro.forum version
Products.intro.forum versionProducts.intro.forum version
Products.intro.forum version
 
Sq lite presentation
Sq lite presentationSq lite presentation
Sq lite presentation
 
Hadoop for the Absolute Beginner
Hadoop for the Absolute BeginnerHadoop for the Absolute Beginner
Hadoop for the Absolute Beginner
 
Azure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applicationsAzure ML: from basic to integration with custom applications
Azure ML: from basic to integration with custom applications
 
Indexes: The neglected performance all rounder
Indexes: The neglected performance all rounderIndexes: The neglected performance all rounder
Indexes: The neglected performance all rounder
 
Introduction to SQL++ for Big Data: Same Language, More Power
Introduction to SQL++ for Big Data: Same Language, More PowerIntroduction to SQL++ for Big Data: Same Language, More Power
Introduction to SQL++ for Big Data: Same Language, More Power
 
Sql server infernals
Sql server infernalsSql server infernals
Sql server infernals
 
Is there a SQL for NoSQL?
Is there a SQL for NoSQL?Is there a SQL for NoSQL?
Is there a SQL for NoSQL?
 
Breaking Spark: Top 5 mistakes to avoid when using Apache Spark in production
Breaking Spark: Top 5 mistakes to avoid when using Apache Spark in productionBreaking Spark: Top 5 mistakes to avoid when using Apache Spark in production
Breaking Spark: Top 5 mistakes to avoid when using Apache Spark in production
 
Azure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSONAzure SQL & SQL Server 2016 JSON
Azure SQL & SQL Server 2016 JSON
 
Sqlite
SqliteSqlite
Sqlite
 
Fully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data ValidationFully Utilizing Spark for Data Validation
Fully Utilizing Spark for Data Validation
 
Dynamic SQL: How to Build Fast Multi-Parameter Stored Procedures
Dynamic SQL: How to Build Fast Multi-Parameter Stored ProceduresDynamic SQL: How to Build Fast Multi-Parameter Stored Procedures
Dynamic SQL: How to Build Fast Multi-Parameter Stored Procedures
 
Simple Works Best
 Simple Works Best Simple Works Best
Simple Works Best
 
Ten query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should knowTen query tuning techniques every SQL Server programmer should know
Ten query tuning techniques every SQL Server programmer should know
 
Best practices for running MySQL on production - Vaibhav Upadhyay
Best practices for running MySQL on production - Vaibhav UpadhyayBest practices for running MySQL on production - Vaibhav Upadhyay
Best practices for running MySQL on production - Vaibhav Upadhyay
 
SQL Server 2016 JSON
SQL Server 2016 JSONSQL Server 2016 JSON
SQL Server 2016 JSON
 

Similaire à Natural Born Killers, Performance issues to avoid

'Natural born killers, SQL performance issues to avoid'
'Natural born killers, SQL performance issues to avoid''Natural born killers, SQL performance issues to avoid'
'Natural born killers, SQL performance issues to avoid'damienjoyce
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - ENGianluca Sartori
 
Scaling Pinterest's Monitoring
Scaling Pinterest's MonitoringScaling Pinterest's Monitoring
Scaling Pinterest's MonitoringBrian Overstreet
 
Big Data Rampage
Big Data RampageBig Data Rampage
Big Data RampageNiko Vuokko
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxJasonTuran2
 
2013 11-07 lsr-dublin_m_hausenblas_when solr is best
2013 11-07 lsr-dublin_m_hausenblas_when solr is best2013 11-07 lsr-dublin_m_hausenblas_when solr is best
2013 11-07 lsr-dublin_m_hausenblas_when solr is bestlucenerevolution
 
Data council sf amundsen presentation
Data council sf    amundsen presentationData council sf    amundsen presentation
Data council sf amundsen presentationTao Feng
 
Unifying your data management with Hadoop
Unifying your data management with HadoopUnifying your data management with Hadoop
Unifying your data management with HadoopJayant Shekhar
 
EnterpriseDB's Best Practices for Postgres DBAs
EnterpriseDB's Best Practices for Postgres DBAsEnterpriseDB's Best Practices for Postgres DBAs
EnterpriseDB's Best Practices for Postgres DBAsEDB
 
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...Wes McKinney
 
Data Discovery and Metadata
Data Discovery and MetadataData Discovery and Metadata
Data Discovery and Metadatamarkgrover
 
Everything You Need to Know About Oracle 12c Indexes
Everything You Need to Know About Oracle 12c IndexesEverything You Need to Know About Oracle 12c Indexes
Everything You Need to Know About Oracle 12c IndexesSolarWinds
 
Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...
Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...
Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...DataStax
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Jon Haddad
 
Microsoft SQL Server Seven Deadly Sins of Database Design
Microsoft SQL Server Seven Deadly Sins of Database DesignMicrosoft SQL Server Seven Deadly Sins of Database Design
Microsoft SQL Server Seven Deadly Sins of Database DesignMark Ginnebaugh
 
Sfsvsqlug june-2010
Sfsvsqlug june-2010Sfsvsqlug june-2010
Sfsvsqlug june-2010datamodeling
 
How to Achieve Scale with MongoDB
How to Achieve Scale with MongoDBHow to Achieve Scale with MongoDB
How to Achieve Scale with MongoDBMongoDB
 
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users HappyGeek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users HappyIDERA Software
 

Similaire à Natural Born Killers, Performance issues to avoid (20)

'Natural born killers, SQL performance issues to avoid'
'Natural born killers, SQL performance issues to avoid''Natural born killers, SQL performance issues to avoid'
'Natural born killers, SQL performance issues to avoid'
 
SQL Server Worst Practices - EN
SQL Server Worst Practices - ENSQL Server Worst Practices - EN
SQL Server Worst Practices - EN
 
Scaling Pinterest's Monitoring
Scaling Pinterest's MonitoringScaling Pinterest's Monitoring
Scaling Pinterest's Monitoring
 
Big Data Rampage
Big Data RampageBig Data Rampage
Big Data Rampage
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptx
 
2013 11-07 lsr-dublin_m_hausenblas_when solr is best
2013 11-07 lsr-dublin_m_hausenblas_when solr is best2013 11-07 lsr-dublin_m_hausenblas_when solr is best
2013 11-07 lsr-dublin_m_hausenblas_when solr is best
 
BAS 250 Lecture 1
BAS 250 Lecture 1BAS 250 Lecture 1
BAS 250 Lecture 1
 
Data council sf amundsen presentation
Data council sf    amundsen presentationData council sf    amundsen presentation
Data council sf amundsen presentation
 
Unifying your data management with Hadoop
Unifying your data management with HadoopUnifying your data management with Hadoop
Unifying your data management with Hadoop
 
EnterpriseDB's Best Practices for Postgres DBAs
EnterpriseDB's Best Practices for Postgres DBAsEnterpriseDB's Best Practices for Postgres DBAs
EnterpriseDB's Best Practices for Postgres DBAs
 
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
Practical Medium Data Analytics with Python (10 Things I Hate About pandas, P...
 
Data Discovery and Metadata
Data Discovery and MetadataData Discovery and Metadata
Data Discovery and Metadata
 
Everything You Need to Know About Oracle 12c Indexes
Everything You Need to Know About Oracle 12c IndexesEverything You Need to Know About Oracle 12c Indexes
Everything You Need to Know About Oracle 12c Indexes
 
Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...
Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...
Tales From the Field: The Wrong Way of Using Cassandra (Carlos Rolo, Pythian)...
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)
 
Microsoft SQL Server Seven Deadly Sins of Database Design
Microsoft SQL Server Seven Deadly Sins of Database DesignMicrosoft SQL Server Seven Deadly Sins of Database Design
Microsoft SQL Server Seven Deadly Sins of Database Design
 
Sfsvsqlug june-2010
Sfsvsqlug june-2010Sfsvsqlug june-2010
Sfsvsqlug june-2010
 
How to Achieve Scale with MongoDB
How to Achieve Scale with MongoDBHow to Achieve Scale with MongoDB
How to Achieve Scale with MongoDB
 
Data Science At Zillow
Data Science At ZillowData Science At Zillow
Data Science At Zillow
 
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users HappyGeek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
 

Dernier

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Dernier (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

Natural Born Killers, Performance issues to avoid

  • 1. Natural Born Killers, performance issues to avoid Richard Douglas
  • 5. Adhering to best practices? http://www.flickr.com/photos/12693492@N04/1338123903/sizes/m/in/photostream/ 5 Natural Born Killers
  • 6. Your host • Richard Douglas • Systems Consultant • 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 6 Natural Born Killers
  • 7. Agenda • Statistics • Table Design • Scalar UDF’s • Indices • Key lookups • Sargability • Table variables • Parameter sniffing 7 Natural Born Killers
  • 8. Statistics • SQL uses a cost based optimizer • Costs influenced by statistics 8 Natural Born Killers
  • 9. 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 9 Natural Born Killers
  • 11. Example of bad design 11 Natural Born Killers
  • 12. Example of a better design 12 Natural Born Killers
  • 13. Table Design – Size comparison 13 Natural Born Killers
  • 14. 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. 14 Natural Born Killers
  • 15.
  • 16. 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 the query plan and IO statistics 19 Natural Born Killers
  • 17. 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 20 Natural Born Killers
  • 19. Indexing strategies It’s all about DWI knowledge: D W I a t a 22 Natural Born Killers o r k l o a d n t e r n a l s
  • 20. Golden Rules for Clustered Indexes Bad example; Surname, Firstname, Middle Initial • Static Impacts nonclustered indexes • Progressive Fragmentation • Narrow • 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 • 1 byte for NULL values and NULL bitmap 23 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-gotchaspart-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. Summary • Statistics • Table Design • Scalar UDF’s • Indices • Key lookups • Sargability • Table variables • Parameter sniffing 31 Natural Born Killers

Notes de l'éditeur

  1. You should know data and workloadI can help you learn more about the internals