SlideShare a Scribd company logo
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or
other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must
respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided
after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION
Presented by Harsh Chawla
SQL Community Session –
Delhi NCR
DBA: Query Tuning and Optimization - Expert
1. DB Consultant Approaches
2. Fetching Execution Plans
3. Common execution plan patterns
4. Understand the data distribution
5. Q&A
Welcome.
Microsoft Services
helps businesses
around the world
maximize their return
on investment in
Microsoft products
and technologies.
12/28/2015 2
Proactive
Approach
12/28/2015 3
• Leverage MDW
• Have a Performance Baseline
Understand the load
• Missing Indexes
• Duplicate Indexes
• Unused Indexes
Understand the Indexing
• Leverage Plan hash and Query Hash to find
top resource intensive queries
• Leverage MDW to identify the top queries
Fetch Top Queries for Tuning
Reactive
Approach
12/28/2015 4
• Leverage MDW /SQLNexus to identify the resource
contention
Identify the Top Bottlenecks
• Leverage Plan hash and Query Hash to find top
resource intensive queries
• Leverage MDW to identify the top queries
Identify the Top Resource intensive queries
• Set Statistics IO ON
• Set Statistics Time on
• Set Statistics Profile on
Explore the execution plans
Fetching
Execution
plans
12/28/2015 5
• Estimated Vs Actual
• DMVs show only estimated plans
• Extract the variables from the
execution plan
• Execute the query to get the actual
execution plan
Common
Execution Plan
Patterns
12/28/2015 6
• Index Seek
• Index Scan
• Key/RID Lookups
• Implicit Conversions
• Missing Statistics Warning
• Sort Warning
• Hash Warning
Let’s Delve
Deeper
12/28/2015 7
• Cardinality Estimation
• Residual Predicates
• Impact of Data distribution
• Sorts
Cardinality
Estimation
12/28/2015 8
• Beauty lies in the data
• There is never a coincidence
• Wrong Estimation cause Hash
warnings/sort warning or almost
every mess up
• It’s the biggest gotcha while
query tuning
• Try to investigate the numbers
Demo
12/28/2015 9
Residual
Predicates
12/28/2015 10
• What’s a Predicate
• If the predicate is not
SARGable, Residual Predicates
will be seen
Demo
12/28/2015 11
Impact of data distribution
Demo
12/28/2015 12
Sort
Q&A
12/28/2015 13

More Related Content

PDF
Big Data LDN 2018: AGILE DATA MASTERING: THE RIGHT APPROACH FOR DATAOPS
PPTX
Data Analytics Labs - Advanced Analytics for Predictive Maintenance
PPTX
3 Reasons You Are Losing the Data Management Battle and How To Start Winning
PPTX
Sage Intelligence Reporting for your Sage ERP Software
PDF
Simplify analytics
PDF
TDX Tech - Technology
PPTX
How to Build a Successful Data Team - Florian Douetteau (@Dataiku)
PPT
Data Quality Tools In Data Migrations
Big Data LDN 2018: AGILE DATA MASTERING: THE RIGHT APPROACH FOR DATAOPS
Data Analytics Labs - Advanced Analytics for Predictive Maintenance
3 Reasons You Are Losing the Data Management Battle and How To Start Winning
Sage Intelligence Reporting for your Sage ERP Software
Simplify analytics
TDX Tech - Technology
How to Build a Successful Data Team - Florian Douetteau (@Dataiku)
Data Quality Tools In Data Migrations

Similar to Query tuning optimization (20)

PDF
Gems to help you troubleshoot query performance
PPTX
My Query is slow, now what?
PDF
Advanced tips for making Oracle databases faster
PDF
Discovering the Plan Cache (#SQLSat 206)
PDF
Iod session 3423 analytics patterns of expertise, the fast path to amazing ...
PDF
31063115_1679409488310Developer_Tuning_Tips_-_UTOUG_Mar_2023.pdf
PDF
Integrating BigInsights and Puredata system for analytics with query federati...
PDF
Highly successful performance tuning of an informix database
PDF
Discovering the plan cache (#SQLSat211)
PDF
Database Performance Handling : A comprehensive guide
PDF
Execution Plans in practice - how to make SQL Server queries faster - Damian ...
PDF
What's New in DBArtisan and Rapid SQL 2016
PDF
DB Optimizer Datasheet - Automated SQL Profiling & Tuning for Optimized Perfo...
PPT
Tips tricks to speed nw bi 2009
PDF
An Approach to Sql tuning - Part 1
PPT
Sql tuning
PDF
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
PPTX
Admin Guiding Query Plans
PPTX
Database Performance Tuning
PPTX
Optimizing Application Performance - 2022.pptx
Gems to help you troubleshoot query performance
My Query is slow, now what?
Advanced tips for making Oracle databases faster
Discovering the Plan Cache (#SQLSat 206)
Iod session 3423 analytics patterns of expertise, the fast path to amazing ...
31063115_1679409488310Developer_Tuning_Tips_-_UTOUG_Mar_2023.pdf
Integrating BigInsights and Puredata system for analytics with query federati...
Highly successful performance tuning of an informix database
Discovering the plan cache (#SQLSat211)
Database Performance Handling : A comprehensive guide
Execution Plans in practice - how to make SQL Server queries faster - Damian ...
What's New in DBArtisan and Rapid SQL 2016
DB Optimizer Datasheet - Automated SQL Profiling & Tuning for Optimized Perfo...
Tips tricks to speed nw bi 2009
An Approach to Sql tuning - Part 1
Sql tuning
[DBA]_HiramFleitas_SQL_PASS_Summit_2017_Summary
Admin Guiding Query Plans
Database Performance Tuning
Optimizing Application Performance - 2022.pptx
Ad

More from Harsh Chawla (8)

PPTX
Alwayson AG enhancements
PPTX
Windows clustering and quorum basics
PPTX
AlwaysON Basics
PDF
AlwaysON FCI
PPTX
Storage spaces - for SQL Server Workloads
PDF
Pssdiag and sql nexus
PPTX
Manage sql server proactively
PPTX
SQL Azure DB - BCDR
Alwayson AG enhancements
Windows clustering and quorum basics
AlwaysON Basics
AlwaysON FCI
Storage spaces - for SQL Server Workloads
Pssdiag and sql nexus
Manage sql server proactively
SQL Azure DB - BCDR
Ad

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
A Presentation on Artificial Intelligence
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPT
Teaching material agriculture food technology
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Insight: SEC Turns Pro Crypto
A Presentation on Artificial Intelligence
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Modernizing your data center with Dell and AMD
Encapsulation theory and applications.pdf
NewMind AI Monthly Chronicles - July 2025
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MYSQL Presentation for SQL database connectivity
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Network Security Unit 5.pdf for BCA BBA.
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Teaching material agriculture food technology

Query tuning optimization

  • 1. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION Presented by Harsh Chawla SQL Community Session – Delhi NCR DBA: Query Tuning and Optimization - Expert
  • 2. 1. DB Consultant Approaches 2. Fetching Execution Plans 3. Common execution plan patterns 4. Understand the data distribution 5. Q&A Welcome. Microsoft Services helps businesses around the world maximize their return on investment in Microsoft products and technologies. 12/28/2015 2
  • 3. Proactive Approach 12/28/2015 3 • Leverage MDW • Have a Performance Baseline Understand the load • Missing Indexes • Duplicate Indexes • Unused Indexes Understand the Indexing • Leverage Plan hash and Query Hash to find top resource intensive queries • Leverage MDW to identify the top queries Fetch Top Queries for Tuning
  • 4. Reactive Approach 12/28/2015 4 • Leverage MDW /SQLNexus to identify the resource contention Identify the Top Bottlenecks • Leverage Plan hash and Query Hash to find top resource intensive queries • Leverage MDW to identify the top queries Identify the Top Resource intensive queries • Set Statistics IO ON • Set Statistics Time on • Set Statistics Profile on Explore the execution plans
  • 5. Fetching Execution plans 12/28/2015 5 • Estimated Vs Actual • DMVs show only estimated plans • Extract the variables from the execution plan • Execute the query to get the actual execution plan
  • 6. Common Execution Plan Patterns 12/28/2015 6 • Index Seek • Index Scan • Key/RID Lookups • Implicit Conversions • Missing Statistics Warning • Sort Warning • Hash Warning
  • 7. Let’s Delve Deeper 12/28/2015 7 • Cardinality Estimation • Residual Predicates • Impact of Data distribution • Sorts
  • 8. Cardinality Estimation 12/28/2015 8 • Beauty lies in the data • There is never a coincidence • Wrong Estimation cause Hash warnings/sort warning or almost every mess up • It’s the biggest gotcha while query tuning • Try to investigate the numbers
  • 10. Residual Predicates 12/28/2015 10 • What’s a Predicate • If the predicate is not SARGable, Residual Predicates will be seen
  • 11. Demo 12/28/2015 11 Impact of data distribution

Editor's Notes

  • #5: Add all the scripts to identify top queries
  • #6: Show Demo on basic SQL Execution Estimated Vs Actual Show the Parametrized query and explain how they can get the parameters out of the execution plan Get the query hash and plan hash  Only zero cost plans are not shown here Get the execution plan from the sys.dm_exec_query_plans and sys.dm_exec_query_stats
  • #8: Hash warning sort warning - everything happens due to wrong cardinality estimation
  • #10: Show Demo for Basic Query Execution.sql Improving cardinality estimation Also tell everything is dependant on statistics 4. What if we don’t have statistics , how many rows will be estimated 5. Always keep your statistics updated 6. Auto create stats and auto update stats enable
  • #11: Demo