sql server - using tools to analyze query performance

28
Polish SQL Server User Group Using Tools to Analyze Query Performance CHAPTER 14

Upload: marek-masko

Post on 15-Apr-2017

19 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Using Tools to Analyze Query Performance

CHAPTER 14

Page 2: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

About the Author

Marek Maśko• Principal Database Analyst at Sabre

• Working with SQL Server since 2010

• SQL DBA, Dev & Architect

• MCP since 2012

• Contact Information: Email: [email protected]

LinkedIn: https://pl.linkedin.com/in/marekmasko

Twitter: @MarekMasko

Page 3: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Agenda

• Query Optimizer

• SQL Trace

• SQL Server Profiler

• SQL Server Extended Events

• SET Session Options

• Dynamic Management Objects

• Execution Plans

Page 4: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

QUERY OPTIMIZER

Page 5: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Query Performance

• Time

• CPU

• Memory

• I/O

Page 6: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Query Optimization

Relational EngineT-SQL

Statement Parser AlgebrizerQuery

Optimizer

Storage Engine

Query Parsing

Parse Tree

Normalization and Binding

Query Processor

Tree

Query Optimization

Execution Plan

Page 7: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Query Optimizer

• Cost based

• Cardinality Estimation

Page 8: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

SQL TRACE & SQL SERVER PROFILER

Page 9: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

SQL Trace & Profiler

https://msdn.microsoft.com/en-us/library/hh245121.aspx

Page 10: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Benefits and drawbacks

• Easy to use

• Produces overhead:

– Local resources

–Network

• Results grid can consume a lot of memory

• Deprecated!

Page 11: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

SQL SERVER EXTENDED EVENTS

Page 12: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Extended Events Engine

https://technet.microsoft.com/en-us/library/dd822788(v=sql.100).aspx

Page 13: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Extended Events Engine

https://technet.microsoft.com/en-us/library/dd822788(v=sql.100).aspx

Page 14: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

SET SESSION OPTIONS

Page 15: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

SET Session Options

• SET STATISTICS IO

• SET STATISTICS TIME

Page 16: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

DYNAMIC MANAGEMENT OBJECTS

Page 17: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

DMO

• System views and functions

• More than 130

• Exist in sys system schema

• Names start with dm_

• Shows current state or data cumulated from instance start

Page 18: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

DMO

• SQLOS related

• Execution related

• Index related

Page 19: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Most Important DMOs

• dm_exec_requests

• dm_exec_sessions

• dm_exec_sql_text()

• dm_exec_query_stats

• dm_os_wait_stats

• dm_os_waiting_tasks

• dm_db_missing_index_details

• dm_db_missing_index_columns

• dm_db_missing_index_groups

• dm_db_missing_index_group_stats

Page 20: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

EXECUTION PLANS

Page 21: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Estimated and Actual Execution Plans

Estimated execution plan

• Output from the Optimizer

• Query doesn’t have to be executed

• Tells you what SQL Server would most likely do

• Stored in the plan cache

Actual execution plan

• Output from the actual query execution

• Tells you exactly what SQL Server did

Page 22: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Execution Plan Formats

• Graphical Plans

• Text Plans

• XML Plans

Page 23: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Graphical Plan

Page 24: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

Text Plan

Page 25: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

XML Plan

Page 26: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

SET Session Options

• Text plans

– SET SHOWPLAN_TEXT and SET SHOWPLAN_ALL for estimated plans

– SET STATISTICS PROFILE for actual plans

• XML plans

– SET SHOWPLAN_XML for estimated plans

– SET STATISTICS XML for actual plans

Page 27: SQL Server - Using Tools to Analyze Query Performance

Polish SQL Server User Group

THANK YOU!