SlideShare una empresa de Scribd logo
1 de 32
1/23/2014 by Shehap El Nagar
Shehap EL-Nagar
I am MVP,MCTS , MCITP SQL Server, I am DB consultant and Architect for lots of Banking, Telecom ,Ministries and
governmental organizations all over Gulf ,also he has deep knowledge about T-SQL performance , HW Performance
issues, Data Warehousing solutions , SQL Server Replication, Clustering solutions and Database Designs for different kinds
of systems ...
The founder of the biggest SQL Server community all over the middle east http://sqlserver-performance-tuning.net/ , you
can watch its success memories at http://www.youtube.com/user/ShehapElNagar
Moderator and author at http://www.sql-server-performance.com ,
, the 1st SQL Server Author at MSDN Arabia http://msdn.microsoft.com/ar-sa/library/jj149119.aspx
, Speaker at SQL Saturday Events worldwide , local events at Saudi Arabia , many online events , more than 90 video
tutorials and also many private sessions for .net developers and Database Administrators
And also influent participator at Microsoft Forums of SQL Server at http://social.technet.microsoft.com.
More about him , you can find him on MVP Microsoft site http://mvp.microsoft.com/en-us/mvp/Shehap%20El-Nagar5000188 .
You can contact him at the below contacts :Mail :idgdirector@yahoo.com ….Cellular phone :00966560700733
Agenda and Overview:
First :How to Start Performance Analysis..?
•
•

How to Capture Expensive Queries..?
How to analyze them to find out performance bottlenecks..?
Second :T-SQL Optimization by checking and replacing poor T-SQL
Practices
1-The practice of Temp Tables and table variables Practice
2-The practice of Union Command
3-The practice of MTVF
4-The practice of Scalar Function
5-The Practice of Views
6-Fast Performance means

Third: Index Tuning by checking and replacing all poor Indexes
(Next Session)
•

How to Capture Expensive Queries..?

Microsoft /Third
party tools

SQL Server

• APM (Application Performance Management)

• Alerts-Based Performance monitors

•
•
•
•

SQL Profiler / SQL Tracer
Activity Monitor / SQL Server Agent Alerts
UCP (Utility Control Point ) of 2008 R2
Dynamic Management Views (DMVs)
Microsoft /Third party tools
1- APM (Application Performance Management) :
•
•
•
•
•
•
•

Dyntrace /Gomez by Compuware
Quest software tools
Redgate
DLD (SQL Deadlock Detector)
SQL Trace Analyzer of SQL Server Solutions.com
RML
SQLIOSim (SQL IO Simulator )
(Exists per SQL Server 2008 Installation directory)

2- Alerts–Based Performance tools :

• SCOM (System Centralized Operation Manager)
• Application Manager /Operation Manager
•

SQL Server Techniques /Tools

1- SQL Profiler / SQL Tracer:
•
•
•

High impact on DB Server
Standstill cases if profiler is capturing frequent events on DB Server
SQL Tracer is better coz it can save 70 % of Network bandwidth

2- Activity Monitor of SQL Server 2008 / SQL Server Agent Alerts
3-UCP (Utility Control Point of SQL Server 2008 R2) which can monitor:
• SQL Server 2008
• SQL Server 2008 R2
• SQL Server 2012
4- Dynamic Management Views (DMVs) and Dynamic Management
Functions (DMFs)
•

How to Analyze Expensive Queries..?

• Database Engine Tuning Advisor (Fundamental Way)

Query-Level

• Query Execution Plans (Advanced Way)
1- Update Statistics/
Rebuild indexes

Update statistics
Online Index Rebuild

Find out Poor Execution
Elements

2- Display Actual/Estimated
Query Execution Plan

Identify Relevant tables

Check how they are used within Query
(Joins/Where /Select /
Scalar functions/Order By/Group By)

3- T-SQL Optimization

4- Index Tuning

Alter these Elements by
Address all poor T-SQL practices

Display Again Query Execution
plan to tune finally indexes

Query Execution Plan
(Advanced Way)
Main Poor Query
execution Elements :
•Table Scan
•Index Scan
•TVF Scan
•Key Lookup/bookmark lookup
•RID lookup
•Hash Match
•High IO /CPU cost of indexes
1 –The Practice of Temp Tables
Impacts of Temp tables and Tables variables
•

Impact on I/O subsystem resources (SAN or local storage)

•

Standstill case due to much Page Latch waits.

•

Much Temp Contention of SGAM (Shared Global Allocation Mapping) , GAM (Global A
, PFS (Page Free Space)

•

Impact on CPU utilization due to much Cxpacket waits resulted of insufficient
indexing of those temp tables.
Healthy Cases of Temp Table usage
1.

Small Volume (Records Number and size) of data entity to be
inserted to Temp tables

2.

Sufficient indexing on Temp Tables (clustered or non clustered)
Alternatives of Temp Tables
1.

CTE expression

2.

Sub queries.

3.

Physical table (Schema Table) if relevant data entity are
seldom changed.

4.

Table Parameters (New 2008 features)
2 –The Practice of Union Commands
Impacts of Union Command
•

Impact on I/O subsystem resources (SAN or local storage)

•

Standstill case due to much Page Latch waits + Page I/O latch waits

•

TempDB contention as explained before
•Alternatives of Union
•

•

Controlling no of unions commands according to
parameters passed from end users.

•

Ordering Union Commands according to data volume of
each select

•

Case When Commands

•

Dynamic T-SQL queries .

•
3- The Practice of MTVF
Cases of MTVF Impact

Usage of MTVF within Joins

Usage of MTVF within Where conditions
How to overcome MTVF Impacts…?
•Transferring

all of MTVF (Multiline TVF) to ITVF (Inline TVF) as much

as possible
•Selecting the Output of MTVF into Temp Tables
•Creating
•Then
•You

Sufficient indexes on these Temp tables

Replacing MTVF everywhere with These Temp tables

should to test it along with your T-SQL queries to check IO cost of
Temp tables
4- The Practice of Scalar functions
Alternatives :
1- Temp Tables as used before with MTVF

2- Persisted deterministic Computed Columns with Sufficient indexing
for them

3- Creating Update Jobs on the appropriate columns to get values of scalar
functions
How to get a Persisted deterministic Computed Columns…?

•Not

to use any aggregative functions of other records.
•Not to use functions that call external system procedures
•Not to use any functions of other fields of other tables.
•To use much better System functions not UDF
How to create index on them..?
Precise Columns only can be put within key column part within index design
Imprecise Columns like decimal ones can be added within include columns part
5- The Practice of Views
Impacts:
•Much CPU Consumption & CXPacket waits particularly more for Huge data cases
and Stressed workload cases
•Dramatic performance degradation for the entire of DB Server due to CPU
bottleneck
Alternatives:
1- Sub queries filtered with the appropriate conditions
2- CTEs (Common Table Expressions)
3- Indexed Views but this option has some restrictive limitations to
enjoy with indexing feature such as :
•Views should be based on a single table not multiple tables
•No use for with (nolock) hint or such similar hints
•No usage for any aggregative functions , Top or distinct commands
•WITH SCHEMABINDING should be used
•View should have unique clustered index.
6- Fast Performance Means
Update Statistics & Index Rebuild:
Update index statistics to help Query Analyzer selecting the best execution plan
Index rebuild to remove index fragmentations to assure indexes are selected
correctly
Table Hints:
Used to enforce Query execution plan to select specific indexes on certain tables
to let it move with another different Route Map
With (Index (Index_Name),Forceseek,nolock)
With (forceseek (index_Name(Column1, Column2..)))
Query Hints:
Used to enforce the entire of query execution plan to move with another route path
that might be better than the default one:
Option ( Maxdop 4)……….Controllable CPU Consumption
Option ( Hash match) ……Much Faster for Large volume of data
Option ( fast N)…………….Faster Execution plan for the first (N) records
Option (Keepfixed plan)…Save elapsed time of Re-estimating Execution plan
Demo Part
Q&A
Post your questions at:

http://www.sqlserver-performancetuning.net/forums/
Thank you ..See you again

1/23/2014
T sql performance guidelines for better db stress powers

Más contenido relacionado

La actualidad más candente

Fault Tolerance and Processing Semantics in Apache Apex
Fault Tolerance and Processing Semantics in Apache ApexFault Tolerance and Processing Semantics in Apache Apex
Fault Tolerance and Processing Semantics in Apache ApexApache Apex Organizer
 
Apache Apex Meetup at Cask
Apache Apex Meetup at CaskApache Apex Meetup at Cask
Apache Apex Meetup at CaskApache Apex
 
Improvements of Funcional Safety for ES.pdf
Improvements of Funcional Safety for ES.pdfImprovements of Funcional Safety for ES.pdf
Improvements of Funcional Safety for ES.pdfVisioneerUG
 
Dealing With The Optimizer complexity
Dealing With The Optimizer complexityDealing With The Optimizer complexity
Dealing With The Optimizer complexityLiron Amitzi
 
Abap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecksAbap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecksMilind Patil
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryAntonios Chatzipavlis
 
Product Information - Fuse Management Central 1.0.0
Product Information - Fuse Management Central 1.0.0Product Information - Fuse Management Central 1.0.0
Product Information - Fuse Management Central 1.0.0antonio.carvalho
 
Time Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOSTime Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOSLaura Hood
 
Management on Cloud 2011
Management on Cloud 2011Management on Cloud 2011
Management on Cloud 2011steccami
 
Creating order in the database patching chaos
Creating order in the database patching chaosCreating order in the database patching chaos
Creating order in the database patching chaosLiron Amitzi
 
Database Performance Tuning Introduction
Database  Performance Tuning IntroductionDatabase  Performance Tuning Introduction
Database Performance Tuning IntroductionMyOnlineITCourses
 
SQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First TimeSQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First TimeDean Richards
 
Traffic Simulator
Traffic SimulatorTraffic Simulator
Traffic Simulatorgystell
 

La actualidad más candente (18)

Breaking data
Breaking dataBreaking data
Breaking data
 
Fault Tolerance and Processing Semantics in Apache Apex
Fault Tolerance and Processing Semantics in Apache ApexFault Tolerance and Processing Semantics in Apache Apex
Fault Tolerance and Processing Semantics in Apache Apex
 
Apache Apex Meetup at Cask
Apache Apex Meetup at CaskApache Apex Meetup at Cask
Apache Apex Meetup at Cask
 
Improvements of Funcional Safety for ES.pdf
Improvements of Funcional Safety for ES.pdfImprovements of Funcional Safety for ES.pdf
Improvements of Funcional Safety for ES.pdf
 
Dealing With The Optimizer complexity
Dealing With The Optimizer complexityDealing With The Optimizer complexity
Dealing With The Optimizer complexity
 
Abap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecksAbap slide lockenqueuedataclustersauthchecks
Abap slide lockenqueuedataclustersauthchecks
 
Why & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to queryWhy & how to optimize sql server for performance from design to query
Why & how to optimize sql server for performance from design to query
 
Product Information - Fuse Management Central 1.0.0
Product Information - Fuse Management Central 1.0.0Product Information - Fuse Management Central 1.0.0
Product Information - Fuse Management Central 1.0.0
 
Time Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOSTime Travelling With DB2 10 For zOS
Time Travelling With DB2 10 For zOS
 
Monitor DB2 performance on z/VM and z/VSE
Monitor DB2 performance on z/VM and z/VSEMonitor DB2 performance on z/VM and z/VSE
Monitor DB2 performance on z/VM and z/VSE
 
Management on Cloud 2011
Management on Cloud 2011Management on Cloud 2011
Management on Cloud 2011
 
Creating order in the database patching chaos
Creating order in the database patching chaosCreating order in the database patching chaos
Creating order in the database patching chaos
 
Database Performance Tuning Introduction
Database  Performance Tuning IntroductionDatabase  Performance Tuning Introduction
Database Performance Tuning Introduction
 
Icin 2009
Icin 2009Icin 2009
Icin 2009
 
SQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First TimeSQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First Time
 
Traffic Simulator
Traffic SimulatorTraffic Simulator
Traffic Simulator
 
14 superscalar
14 superscalar14 superscalar
14 superscalar
 
Madsqlserver
MadsqlserverMadsqlserver
Madsqlserver
 

Similar a T sql performance guidelines for better db stress powers

Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfElboulmaniMohamed
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxJasonTuran2
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizerterraborealis
 
MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...
MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...
MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...sameh samir
 
Was liberty at scale
Was liberty at scaleWas liberty at scale
Was liberty at scalesflynn073
 
FME World Tour 2015 - FME & Data Migration Simon McCabe
FME World Tour 2015 -  FME & Data Migration Simon McCabeFME World Tour 2015 -  FME & Data Migration Simon McCabe
FME World Tour 2015 - FME & Data Migration Simon McCabeIMGS
 
AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationVolodymyr Rovetskiy
 
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginnersKoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginnersTobias Koprowski
 
KoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginnersKoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginnersTobias Koprowski
 
High Performance SSRS
High Performance SSRSHigh Performance SSRS
High Performance SSRSBert Wagner
 
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 DBAsZohar Elkayam
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Antonios Chatzipavlis
 
NoSQL em Windows Azure Table Storage - Vitor Tomaz
NoSQL em Windows Azure Table Storage - Vitor TomazNoSQL em Windows Azure Table Storage - Vitor Tomaz
NoSQL em Windows Azure Table Storage - Vitor TomazComunidade NetPonto
 
EM12c Monitoring, Metric Extensions and Performance Pages
EM12c Monitoring, Metric Extensions and Performance PagesEM12c Monitoring, Metric Extensions and Performance Pages
EM12c Monitoring, Metric Extensions and Performance PagesEnkitec
 
Performance dreams of sql server 2014
Performance dreams of sql server 2014Performance dreams of sql server 2014
Performance dreams of sql server 2014Shehap Elnagar
 
Application Performance Tuning Techniques
Application Performance Tuning TechniquesApplication Performance Tuning Techniques
Application Performance Tuning TechniquesRam Nagesh
 

Similar a T sql performance guidelines for better db stress powers (20)

Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdf
 
Optimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptxOptimizing Application Performance - 2022.pptx
Optimizing Application Performance - 2022.pptx
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Understanding DB2 Optimizer
Understanding DB2 OptimizerUnderstanding DB2 Optimizer
Understanding DB2 Optimizer
 
MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...
MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...
MSF: Sync your Data On-Premises And To The Cloud - dotNetwork Gathering, Oct ...
 
Was liberty at scale
Was liberty at scaleWas liberty at scale
Was liberty at scale
 
FME World Tour 2015 - FME & Data Migration Simon McCabe
FME World Tour 2015 -  FME & Data Migration Simon McCabeFME World Tour 2015 -  FME & Data Migration Simon McCabe
FME World Tour 2015 - FME & Data Migration Simon McCabe
 
AWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentationAWS (Amazon Redshift) presentation
AWS (Amazon Redshift) presentation
 
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginnersKoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
KoprowskiT_SQLSaturday409_MaintenancePlansForBeginners
 
KoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginnersKoprowskiT_SQLSat409_MaintenancePlansForBeginners
KoprowskiT_SQLSat409_MaintenancePlansForBeginners
 
High Performance SSRS
High Performance SSRSHigh Performance SSRS
High Performance SSRS
 
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
 
Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019Modernizing your database with SQL Server 2019
Modernizing your database with SQL Server 2019
 
NoSQL em Windows Azure Table Storage - Vitor Tomaz
NoSQL em Windows Azure Table Storage - Vitor TomazNoSQL em Windows Azure Table Storage - Vitor Tomaz
NoSQL em Windows Azure Table Storage - Vitor Tomaz
 
EM12c Monitoring, Metric Extensions and Performance Pages
EM12c Monitoring, Metric Extensions and Performance PagesEM12c Monitoring, Metric Extensions and Performance Pages
EM12c Monitoring, Metric Extensions and Performance Pages
 
Performance dreams of sql server 2014
Performance dreams of sql server 2014Performance dreams of sql server 2014
Performance dreams of sql server 2014
 
Application Performance Tuning Techniques
Application Performance Tuning TechniquesApplication Performance Tuning Techniques
Application Performance Tuning Techniques
 
ADF Performance Monitor
ADF Performance MonitorADF Performance Monitor
ADF Performance Monitor
 
01 oracle architecture
01 oracle architecture01 oracle architecture
01 oracle architecture
 

Último

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Último (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

T sql performance guidelines for better db stress powers

  • 2. Shehap EL-Nagar I am MVP,MCTS , MCITP SQL Server, I am DB consultant and Architect for lots of Banking, Telecom ,Ministries and governmental organizations all over Gulf ,also he has deep knowledge about T-SQL performance , HW Performance issues, Data Warehousing solutions , SQL Server Replication, Clustering solutions and Database Designs for different kinds of systems ... The founder of the biggest SQL Server community all over the middle east http://sqlserver-performance-tuning.net/ , you can watch its success memories at http://www.youtube.com/user/ShehapElNagar Moderator and author at http://www.sql-server-performance.com , , the 1st SQL Server Author at MSDN Arabia http://msdn.microsoft.com/ar-sa/library/jj149119.aspx , Speaker at SQL Saturday Events worldwide , local events at Saudi Arabia , many online events , more than 90 video tutorials and also many private sessions for .net developers and Database Administrators And also influent participator at Microsoft Forums of SQL Server at http://social.technet.microsoft.com. More about him , you can find him on MVP Microsoft site http://mvp.microsoft.com/en-us/mvp/Shehap%20El-Nagar5000188 . You can contact him at the below contacts :Mail :idgdirector@yahoo.com ….Cellular phone :00966560700733
  • 3. Agenda and Overview: First :How to Start Performance Analysis..? • • How to Capture Expensive Queries..? How to analyze them to find out performance bottlenecks..? Second :T-SQL Optimization by checking and replacing poor T-SQL Practices 1-The practice of Temp Tables and table variables Practice 2-The practice of Union Command 3-The practice of MTVF 4-The practice of Scalar Function 5-The Practice of Views 6-Fast Performance means Third: Index Tuning by checking and replacing all poor Indexes (Next Session)
  • 4.
  • 5. • How to Capture Expensive Queries..? Microsoft /Third party tools SQL Server • APM (Application Performance Management) • Alerts-Based Performance monitors • • • • SQL Profiler / SQL Tracer Activity Monitor / SQL Server Agent Alerts UCP (Utility Control Point ) of 2008 R2 Dynamic Management Views (DMVs)
  • 6. Microsoft /Third party tools 1- APM (Application Performance Management) : • • • • • • • Dyntrace /Gomez by Compuware Quest software tools Redgate DLD (SQL Deadlock Detector) SQL Trace Analyzer of SQL Server Solutions.com RML SQLIOSim (SQL IO Simulator ) (Exists per SQL Server 2008 Installation directory) 2- Alerts–Based Performance tools : • SCOM (System Centralized Operation Manager) • Application Manager /Operation Manager
  • 7. • SQL Server Techniques /Tools 1- SQL Profiler / SQL Tracer: • • • High impact on DB Server Standstill cases if profiler is capturing frequent events on DB Server SQL Tracer is better coz it can save 70 % of Network bandwidth 2- Activity Monitor of SQL Server 2008 / SQL Server Agent Alerts 3-UCP (Utility Control Point of SQL Server 2008 R2) which can monitor: • SQL Server 2008 • SQL Server 2008 R2 • SQL Server 2012 4- Dynamic Management Views (DMVs) and Dynamic Management Functions (DMFs)
  • 8. • How to Analyze Expensive Queries..? • Database Engine Tuning Advisor (Fundamental Way) Query-Level • Query Execution Plans (Advanced Way)
  • 9. 1- Update Statistics/ Rebuild indexes Update statistics Online Index Rebuild Find out Poor Execution Elements 2- Display Actual/Estimated Query Execution Plan Identify Relevant tables Check how they are used within Query (Joins/Where /Select / Scalar functions/Order By/Group By) 3- T-SQL Optimization 4- Index Tuning Alter these Elements by Address all poor T-SQL practices Display Again Query Execution plan to tune finally indexes Query Execution Plan (Advanced Way) Main Poor Query execution Elements : •Table Scan •Index Scan •TVF Scan •Key Lookup/bookmark lookup •RID lookup •Hash Match •High IO /CPU cost of indexes
  • 10.
  • 11. 1 –The Practice of Temp Tables
  • 12. Impacts of Temp tables and Tables variables • Impact on I/O subsystem resources (SAN or local storage) • Standstill case due to much Page Latch waits. • Much Temp Contention of SGAM (Shared Global Allocation Mapping) , GAM (Global A , PFS (Page Free Space) • Impact on CPU utilization due to much Cxpacket waits resulted of insufficient indexing of those temp tables.
  • 13. Healthy Cases of Temp Table usage 1. Small Volume (Records Number and size) of data entity to be inserted to Temp tables 2. Sufficient indexing on Temp Tables (clustered or non clustered)
  • 14. Alternatives of Temp Tables 1. CTE expression 2. Sub queries. 3. Physical table (Schema Table) if relevant data entity are seldom changed. 4. Table Parameters (New 2008 features)
  • 15. 2 –The Practice of Union Commands
  • 16. Impacts of Union Command • Impact on I/O subsystem resources (SAN or local storage) • Standstill case due to much Page Latch waits + Page I/O latch waits • TempDB contention as explained before
  • 17. •Alternatives of Union • • Controlling no of unions commands according to parameters passed from end users. • Ordering Union Commands according to data volume of each select • Case When Commands • Dynamic T-SQL queries . •
  • 18. 3- The Practice of MTVF
  • 19. Cases of MTVF Impact Usage of MTVF within Joins Usage of MTVF within Where conditions
  • 20. How to overcome MTVF Impacts…? •Transferring all of MTVF (Multiline TVF) to ITVF (Inline TVF) as much as possible •Selecting the Output of MTVF into Temp Tables •Creating •Then •You Sufficient indexes on these Temp tables Replacing MTVF everywhere with These Temp tables should to test it along with your T-SQL queries to check IO cost of Temp tables
  • 21. 4- The Practice of Scalar functions
  • 22. Alternatives : 1- Temp Tables as used before with MTVF 2- Persisted deterministic Computed Columns with Sufficient indexing for them 3- Creating Update Jobs on the appropriate columns to get values of scalar functions
  • 23. How to get a Persisted deterministic Computed Columns…? •Not to use any aggregative functions of other records. •Not to use functions that call external system procedures •Not to use any functions of other fields of other tables. •To use much better System functions not UDF How to create index on them..? Precise Columns only can be put within key column part within index design Imprecise Columns like decimal ones can be added within include columns part
  • 24. 5- The Practice of Views
  • 25. Impacts: •Much CPU Consumption & CXPacket waits particularly more for Huge data cases and Stressed workload cases •Dramatic performance degradation for the entire of DB Server due to CPU bottleneck
  • 26. Alternatives: 1- Sub queries filtered with the appropriate conditions 2- CTEs (Common Table Expressions) 3- Indexed Views but this option has some restrictive limitations to enjoy with indexing feature such as : •Views should be based on a single table not multiple tables •No use for with (nolock) hint or such similar hints •No usage for any aggregative functions , Top or distinct commands •WITH SCHEMABINDING should be used •View should have unique clustered index.
  • 28. Update Statistics & Index Rebuild: Update index statistics to help Query Analyzer selecting the best execution plan Index rebuild to remove index fragmentations to assure indexes are selected correctly Table Hints: Used to enforce Query execution plan to select specific indexes on certain tables to let it move with another different Route Map With (Index (Index_Name),Forceseek,nolock) With (forceseek (index_Name(Column1, Column2..))) Query Hints: Used to enforce the entire of query execution plan to move with another route path that might be better than the default one: Option ( Maxdop 4)……….Controllable CPU Consumption Option ( Hash match) ……Much Faster for Large volume of data Option ( fast N)…………….Faster Execution plan for the first (N) records Option (Keepfixed plan)…Save elapsed time of Re-estimating Execution plan
  • 30. Q&A Post your questions at: http://www.sqlserver-performancetuning.net/forums/
  • 31. Thank you ..See you again 1/23/2014