SlideShare a Scribd company logo
1 of 13
© 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

Similar to Query tuning optimization

Data-Ed Online Webinar: Data-centric Strategy & Roadmap
Data-Ed Online Webinar: Data-centric Strategy & RoadmapData-Ed Online Webinar: Data-centric Strategy & Roadmap
Data-Ed Online Webinar: Data-centric Strategy & Roadmap
DATAVERSITY
 
Kythera BioPharma Commercial Infrastructure 2015 05 28 final
Kythera BioPharma Commercial Infrastructure 2015 05 28 finalKythera BioPharma Commercial Infrastructure 2015 05 28 final
Kythera BioPharma Commercial Infrastructure 2015 05 28 final
Michael W. Hughes
 
Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...
Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...
Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...
Denodo
 
Edr mds a less is more approach to MDM
Edr mds a less is more approach to MDMEdr mds a less is more approach to MDM
Edr mds a less is more approach to MDM
Thor Henning Hetland
 

Similar to Query tuning optimization (20)

Building a Data Strategy Your C-Suite Will Support
Building a Data Strategy Your C-Suite Will SupportBuilding a Data Strategy Your C-Suite Will Support
Building a Data Strategy Your C-Suite Will Support
 
ANIn Coimbatore Sep 2023 | Agile for data science by Venkatesa Prasanna Selvaraj
ANIn Coimbatore Sep 2023 | Agile for data science by Venkatesa Prasanna SelvarajANIn Coimbatore Sep 2023 | Agile for data science by Venkatesa Prasanna Selvaraj
ANIn Coimbatore Sep 2023 | Agile for data science by Venkatesa Prasanna Selvaraj
 
Strategy and roadmap slides
Strategy and roadmap slidesStrategy and roadmap slides
Strategy and roadmap slides
 
Data-Ed Online Webinar: Data-centric Strategy & Roadmap
Data-Ed Online Webinar: Data-centric Strategy & RoadmapData-Ed Online Webinar: Data-centric Strategy & Roadmap
Data-Ed Online Webinar: Data-centric Strategy & Roadmap
 
Trends in Enterprise Advanced Analytics
Trends in Enterprise Advanced AnalyticsTrends in Enterprise Advanced Analytics
Trends in Enterprise Advanced Analytics
 
Most Common Data Governance Challenges in the Digital Economy
Most Common Data Governance Challenges in the Digital EconomyMost Common Data Governance Challenges in the Digital Economy
Most Common Data Governance Challenges in the Digital Economy
 
Alphonso_Triplett.Sr_Prometheus_Phoenix
Alphonso_Triplett.Sr_Prometheus_PhoenixAlphonso_Triplett.Sr_Prometheus_Phoenix
Alphonso_Triplett.Sr_Prometheus_Phoenix
 
Building Data Warehouse in SQL Server
Building Data Warehouse in SQL ServerBuilding Data Warehouse in SQL Server
Building Data Warehouse in SQL Server
 
Driving A New Age Of Connected Planning
Driving A New Age Of Connected PlanningDriving A New Age Of Connected Planning
Driving A New Age Of Connected Planning
 
How to Structure the Data Organization
How to Structure the Data OrganizationHow to Structure the Data Organization
How to Structure the Data Organization
 
Data architecture around risk management
Data architecture around risk managementData architecture around risk management
Data architecture around risk management
 
Kythera BioPharma Commercial Infrastructure 2015 05 28 final
Kythera BioPharma Commercial Infrastructure 2015 05 28 finalKythera BioPharma Commercial Infrastructure 2015 05 28 final
Kythera BioPharma Commercial Infrastructure 2015 05 28 final
 
March 2016 PHXTUG Meeting
March 2016 PHXTUG MeetingMarch 2016 PHXTUG Meeting
March 2016 PHXTUG Meeting
 
Future Proof Your DAM
Future Proof Your DAMFuture Proof Your DAM
Future Proof Your DAM
 
Synergis60: 6 Critical Steps to Implementing Data Managment
Synergis60: 6 Critical Steps to Implementing Data ManagmentSynergis60: 6 Critical Steps to Implementing Data Managment
Synergis60: 6 Critical Steps to Implementing Data Managment
 
Datascience methodology
Datascience methodologyDatascience methodology
Datascience methodology
 
Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...
Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...
Innovative Data Strategies for Advanced Analytics Solutions and the Role of D...
 
Edr mds a less is more approach to MDM
Edr mds a less is more approach to MDMEdr mds a less is more approach to MDM
Edr mds a less is more approach to MDM
 
2013 ALPFA Leadership Submit, Data Analytics in Practice
2013 ALPFA Leadership Submit, Data Analytics in Practice2013 ALPFA Leadership Submit, Data Analytics in Practice
2013 ALPFA Leadership Submit, Data Analytics in Practice
 
Data-Ed: Metadata Strategies
 Data-Ed: Metadata Strategies Data-Ed: Metadata Strategies
Data-Ed: Metadata Strategies
 

More from Harsh Chawla (8)

Alwayson AG enhancements
Alwayson AG enhancementsAlwayson AG enhancements
Alwayson AG enhancements
 
Windows clustering and quorum basics
Windows clustering and quorum basicsWindows clustering and quorum basics
Windows clustering and quorum basics
 
AlwaysON Basics
AlwaysON BasicsAlwaysON Basics
AlwaysON Basics
 
AlwaysON FCI
AlwaysON FCIAlwaysON FCI
AlwaysON FCI
 
Storage spaces - for SQL Server Workloads
Storage spaces - for SQL Server WorkloadsStorage spaces - for SQL Server Workloads
Storage spaces - for SQL Server Workloads
 
Pssdiag and sql nexus
Pssdiag and sql nexusPssdiag and sql nexus
Pssdiag and sql nexus
 
Manage sql server proactively
Manage sql server proactivelyManage sql server proactively
Manage sql server proactively
 
SQL Azure DB - BCDR
SQL Azure DB - BCDRSQL Azure DB - BCDR
SQL Azure DB - BCDR
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

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

  1. Add all the scripts to identify top queries
  2. 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
  3. Hash warning sort warning - everything happens due to wrong cardinality estimation
  4. 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
  5. Demo