Presentation is loading. Please wait.

Presentation is loading. Please wait.

Query Profiling Options in SQL Server

Similar presentations


Presentation on theme: "Query Profiling Options in SQL Server"— Presentation transcript:

1 Query Profiling Options in SQL Server
Karol Papaj Query Profiling Options in SQL Server

2

3 Karol Papaj SolidQ SQL Server BI SQL Server High Availability
SQL Server Relational Engine @KarolPapaj

4 Execution plan with estimates
What’s Execution Plan Instructions how to perform a given query Execution plan with estimates how many rows each node will have to process Execution plan with runtime statistics

5 Why we need Estimated Plan?
Performance troubleshooting (why is your query slow?) Estimated Serial? Parallel? Seek? Scan? Loop?Merge?Hash? Serial? Parallel? Seek? Scan? Loop?Merge?Hash?

6 How Developer Can Get Estimated Plan
SET SHOWPLAN_TEXT SET SHOWPLAN_XML SET SHOWPLAN_ALL Ctrl+L or “Display Estimated Execution Plan” in SSMS

7 How Developer Can Get Estimated Plan
Demo How Developer Can Get Estimated Plan

8 Why we need Actual Plan? Performance troubleshooting (why is your query slow?) Actual Duration? SQL Server 2014 SP2 and higher Number of rows Cardinality estimation error? Missing filter condition Outdated statistics Memory used Threads used Degree of parallelism

9 How Developer Can Get Actual Plan
SET STATISTICS PROFILE SET STATISTICS XML Ctrl+K or “Include Actual Execution Plan” in SSMS

10 How Developer Can Get Actual Plan
Demo How Developer Can Get Actual Plan

11 How DBA Can Get Estimated Plan?
Showplan XML event in Profiler query_pre_execution_showplan in Extended Events sys.dm_exec_cached_plans

12 How DBA Can Get Estimated Plan
Demo How DBA Can Get Estimated Plan

13 How DBA Can Get Actual Plan?
Showplan XML Statistics Profile in Profiler query_post_execution_showplan in Extended Events

14 How DBA Can Get Actual Plan
Demo How DBA Can Get Actual Plan

15

16 2 Problems

17 1

18 Legacy profiling infrastructure CPU Overhead

19 Lightweight infrastructure
SQL Server 2016 SP1 query_thread_profile extended event DBCC TRACEON(7412,-1) GO Enabled by TF 7412

20 Lightweight infrastructure
Demo Lightweight infrastructure

21 Profiling Infrastructure CPU Overhead
Source:

22 2

23 query_thread_profile
QUERY_PLAN_PROFILE SQL 2016 SP2 CU3 SQL 2017 CU11 SQL 2019 query_thread_profile extended event SELECT COUNT (*) FROM Sales.SalesOrderHeaderEnlarged; OPTION (USE HINT('QUERY_PLAN_PROFILE')); QUERY_PLAN_PROFILE hint

24 Demo QUERY_PLAN_PROFILE

25 How to use QUERY_PLAN_PROFILE without touching a code
Query_ID Profiling 1 2 Configuration table Plan Guide

26 QUERY_PLAN_PROFILE Practical Usage
Demo QUERY_PLAN_PROFILE Practical Usage

27 Be careful on getting Actual Execution Plan from production on SQL Server before 2014 SP2/2016
SQL 2014 SP2/2016 better SQL 2016 SP1 much better (enable lightweight infrastructure if CPU usage is < 95% on your server) SQL Server 2019 has lightweight infrastructure enabled by default SQL 2016 SP2 CU3/2017 CU11/2019 even better! (query_plan_profile_hint)

28 QUESTIONS ? #SQLCLINIC

29 Resources MS SQL Tiger Team blog:
Execution Plan Reference by Hugo Kornelis:

30 THANK YOU !

31


Download ppt "Query Profiling Options in SQL Server"

Similar presentations


Ads by Google