23
Uncovering the hidden gems in execution plans Kevan Riley Newcastle 27 October 2014

Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley [email protected] @kevriley Independent freelance

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Uncovering the hidden gems in

execution plans

Kevan Riley

Newcastle 27 October 2014

Page 2: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Who is this guy?

Kevan Riley

[email protected]

@kevriley

Independent freelance SQL Server

15+ years SQL Server

Moderator at ask.sqlservercentral.com

2

Page 3: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

What’s it all about?

Query performance tuning

Execution plan analysis

XML

Some show in graphical

Don’t always get full picture

3

Page 4: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Missing Indexes

Query level warning

2005 ‘hidden’ in XML

2008+ Graphical execution plan

4

Page 5: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Missing Indexes

SSMS Demo

5

Page 6: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Missing Indexes

Every statement in multi-statement batch

SSMS only shows one missing index

Fixed in SQL 2012 SP2 +onwards

6

Page 7: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Reason for Early Termination

Plan level attribute

No graphical indication / No tooltip info

Available in Properties / XML

Reason For Early Termination of Statement

Optimization

3 values

Good enough plan found

Timeout

Memory limit exceeded

7

Page 8: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Reason for Early Termination

SSMS Demo

8

Page 9: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Reason for Early Termination

Full optimization level

Timeout – complex query

9

Page 10: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

No Join Predicate Warning

Operator level warning

10

Page 11: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

No Join Predicate Warning

SSMS Demo

11

Page 12: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

No Join Predicate Warning

Cartesian Product

Cross Join

‘old’ join syntax

Incomplete predicate

Complex query (possibly with Timeout)

Complex predicate

12

Page 13: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Convert Issue ‘Cardinality Estimate’

Query level warning

SQL 2012

13

Page 14: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Convert Issue ‘Cardinality Estimate’

SSMS Demo

14

Page 15: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Convert Issue ‘Cardinality Estimate’

Potential tuning opportunities

All conversions

15

Page 16: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Sort Warnings

Operator level warning

Introduced SQL 2012

16

Page 17: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Sort Warnings

SSMS Demo

17

Page 18: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Sort Warnings

Bad stats, bad estimates

Certain query patterns

Parameter sniffing

Spill Level

single pass / multiple passes http://www.sqlskills.com/blogs/joe/spilltotempdb-warning-and-

spilllevels-mapping-to-single-versus-multiple-pass

18

Page 19: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

RetrievedFromCache attribute

Was plan retrieved from cache?

19

Was plan retrieved from cache?

Was the plan cached?

Plan was in cache => True

Generated plan now in cache => True

Generated plan not in cache => False

Page 20: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

RetrievedFromCache attribute

Plan level attribute

SQL 2012

No graphical indication / No tooltip info

Available in Properties / XML

20

Page 21: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Taking this further

sys.dm_exec_cached_plans

sys.dm_exec_query_plan

Proactive tuning

Jason Strate MVP MCM (www.jasonstrate.com)

Blog series - Can you dig it?

22

Page 22: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

References

Grant Fritchey @GFritchey | www.scarydba.com

Paul White @SQL_Kiwi | sqlblog.com/blogs/paul_white

Joseph Sack @josephsack | www.sqlskills.com/blogs/joe

Benjamin Nevarez @BenjaminNevarez | www.benjaminnevarez.com

Jason Strate @StrateSQL | www.jasonstrate.com

23

Page 23: Uncovering the hidden gems in Execution plans · 2018. 4. 10. · Newcastle 27 Oct 2014 Who is this guy? Kevan Riley kevan.riley@rileywaterhouse.co.uk @kevriley Independent freelance

Newcastle

27 Oct 2014

Questions?

Thanks for listening

[email protected]

www.rileywaterhouse.co.uk

@kevriley

24