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 Drag picture to placeholder or click icon to add Drag picture Presented by Harsh Chawla SQL Community Session – Delhi NCR DBA: Query Tuning and Optimization - Expert

Query tuning optimization

Embed Size (px)

Citation preview

Page 1: Query tuning optimization

© 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

Drag picture to placeholder or click icon to addDrag picture to placeholder or click icon to add

Presented by Harsh Chawla

SQL Community Session – Delhi NCR

DBA: Query Tuning and Optimization - Expert

Page 2: Query tuning optimization

1. DB Consultant Approaches2. Fetching Execution Plans3. Common execution plan patterns4. Understand the data distribution5. Q&A

Welcome.Microsoft Services helps businesses around the world maximize their return on investment in Microsoft products and technologies.

05/03/2023 2

Page 3: Query tuning optimization

05/03/2023 3

Proactive Approach • 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

Page 4: Query tuning optimization

05/03/2023 4

Reactive Approach

• 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

Page 5: Query tuning optimization

05/03/2023 5

Fetching Execution plans

• Estimated Vs Actual• DMVs show only estimated

plans• Extract the variables from

the execution plan• Execute the query to get the

actual execution plan

Page 6: Query tuning optimization

05/03/2023 6

CommonExecution Plan Patterns

• Index Seek• Index Scan• Key/RID Lookups• Implicit Conversions• Missing Statistics

Warning• Sort Warning• Hash Warning

Page 7: Query tuning optimization

05/03/2023 7

Let’s Delve Deeper

• Cardinality Estimation• Residual Predicates• Impact of Data

distribution• Sorts

Page 8: Query tuning optimization

05/03/2023 8

Cardinality Estimation

• 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

Page 9: Query tuning optimization

05/03/2023 9

Demo

Page 10: Query tuning optimization

05/03/2023 10

Residual Predicates

• What’s a Predicate• If the predicate is not

SARGable, Residual Predicates will be seen

Page 11: Query tuning optimization

05/03/2023 11

Demo Impact of data distribution

Page 12: Query tuning optimization

05/03/2023 12

Demo Sort

Page 13: Query tuning optimization

05/03/2023 13

Q&A