Using xEvents to capture an Actual Execution Plan

Published Apr 01 2019 01:39 PM 9,586 Views
Microsoft

If you still are working with SQL Profiler/SQL trace, welcome to the world of Extended Events (also known as xEvents or XE). SQL Trace has been deprecated and shouldn’t be used anymore. Why? Since SQL Server 2012 we have xEvents for lower-impact troubleshooting and performance investigations, providing scalable insights into SQL Server behavior, and in the case we’re discussing here, query execution plans.

 

Query execution plans, otherwise known as actual execution plans or just Showplan, provide a map of all the required operations to get the query output, which includes runtime performance statistics.

These are available through Query Store (QS) for example, which is a valuable tool for troubleshooting workload *trends* via specific queries – this is because QS aggregates performance data on queries. However, sometimes we need to get the specific, singleton query execution plan to analyze and troubleshoot – this is where xEvents come in.

Since SQL Server 2012 we’ve had the query_post_execution_showplan xEvent for this. As the name suggests, it gets you the actual query plan – because it is *after* execution – when we have the runtime statistics available. However this xEvent is based on the standard query execution statistics profile infrastructure (quite a mouthful) – or standard profiling for short (read more about it here). This one has a very high overhead (75%+ with a TPC-C like workload), which is why its use needs to be seriously considered, and most likely not used unless in last resort.

 

In more recent releases we have other alternatives for these requirements to get the singleton actual execution plans, based on the lightweight query execution statistics profile infrastructure – or lightweight profiling for short (read more about it here). These xEvents are listed below, where we’ll see examples on how to use them.

 

query_thread_profile

This is available starting with SQL Server 2014 SP2 and SQL Server 2016.

This xEvent doesn’t really give you a consolidated showplan as other xEvents, however it is useful in the sense it outputs one event per each data access operator and each execution thread found in an actual query execution plan – it can get quite verbose but allows use at a scale that was not possible with any other event before. An example session looks like this:

 

CREATE EVENT SESSION [PerfStats_Node] ON SERVER

ADD EVENT sqlserver.query_thread_profile(

ACTION(sqlos.scheduler_id,sqlserver.database_id,sqlserver.is_system,sqlserver.plan_handle,sqlserver.query_hash_signed,sqlserver.query_plan_hash_signed,sqlserver.server_instance_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.sql_text))

ADD TARGET package0.event_file(SET filename=N'C:\Temp\PerfStats_Node.xel',max_file_size=(50),max_rollover_files=(2))

WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO

 

For this example, I ran the following query in the AdventureWorks2016 database:

 

SELECT COUNT(*)

FROM Sales.SalesOrderDetail AS sod

INNER JOIN Sales.SalesOrderHeader AS soh

ON soh.SalesOrderID = sod.SalesOrderID

GROUP BY soh.Status;

GO

 

So, let’s see the resulting session output:

 

query_thread_profile XEquery_thread_profile XE

The information found in each xEvent matches the RunTimeCountersPerThread showplan element that may include such information as elapsed time, CPU time, logical and physical reads (if applicable). Notice we have selected the last event generated, and the node_id is 4. Something I know now is this plan has 5 operators – nodes 0 through 4 – which can be searched in the graphical execution plan. Also notice that in each of these events you can find the plan_handle property. This can be used to get the graphical plan from cache, using the query below:

 

sys.dm_exec_query_plansys.dm_exec_query_plan

Clicking on the link in the results tab opens the graphical plan, and now it’s time to start mapping the XE session runtime information with the cached plan. To do this we’ll use a very useful feature in SSMS – Node Search – just right-click a blank area in the plan and you see it:

 

Find Node in SSMSFind Node in SSMS

This feature allows me to search for any property in the plan – and so I search for NodeId 4 – and get immediately positioned in the plan operator that represents that node id 4.

 

Find Node - NodeIdFind Node - NodeId

And now comparing with the XE output, I can see the graphical plan and the actual and estimated rows that were read by that Index Scan:

 

query_thread_profile XE compare with Graphical Planquery_thread_profile XE compare with Graphical Plan

It can be an arduous task to do the above, but for collecting runtime plan data at scale and then zero in on some specific plan, it is useful.

 

query_plan_profile

This is available starting with SQL Server 2016 SP2 CU3 and SQL Server 2017 CU11. This xEvent outputs the equivalent of a query execution plan similar to the query_post_execution_showplan xEvent, but only for the query or queries that are using the USE HINT ('QUERY_PLAN_PROFILE'). An example session looks like this:

 

CREATE EVENT SESSION [PerfStats_LWP_Plan_Single] ON SERVER
ADD EVENT sqlserver.query_plan_profile(
ACTION(sqlos.scheduler_id,sqlserver.database_id,sqlserver.is_system,sqlserver.plan_handle,sqlserver.query_hash_signed,sqlserver.query_plan_hash_signed,sqlserver.server_instance_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.sql_text))
ADD TARGET package0.event_file(SET filename=N'C:\Temp\PerfStats_LWP_Plan_Single.xel',max_file_size=(50),max_rollover_files=(2))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO

 

This allows a very targeted plan collection that doesn’t require filtering of any sort in the XE session. If a query you want to track is generated by an application and you can’t change the query at its origin, then you can use a plan guide to add the hint, as in the example below created for a stored procedure named Sales.CountSalesOrderByStatus:

 

EXEC sp_create_plan_guide  

@name = N'Guide1',

@stmt = 'SELECT COUNT(*)

FROM Sales.SalesOrderDetail AS sod

INNER JOIN Sales.SalesOrderHeader AS soh

       ON soh.SalesOrderID = sod.SalesOrderID

GROUP BY soh.STATUS;',

@type = N'OBJECT',

@module_or_batch = N'Sales.CountSalesOrderByStatus',

@params = NULL,

@hints = N'OPTION (USE HINT (''QUERY_PLAN_PROFILE''))';

 

So, let’s see the resulting session output where I can already see runtime data such as the query duration, the memory grant and used memory:

 

query_plan_profile XEquery_plan_profile XE

Clicking on the tab Query Plan shows me the actual execution plan. The immediate giveaway is that I see information on how many actual rows of estimated rows flowed through the operators.

 

image013.png

 

Notice the query text is not shown. This is another way of keeping these events lightweight. The xEvent already captures the sql_text. And if needed and the plan is cached, you can always get the cached plan from sys.dm_exec_cached_plans using the plan_handle, and the query text is shown there.

 

query_post_execution_plan_profile

This is a new xEvent available starting with SQL Server 2017 CU14 and SQL Server 2019. Much like the query_post_execution_showplan xEvent, the new query_post_execution_plan_profile outputs the actual query execution plan with fundamental data that’ usually required to troubleshoot query performance, such as the row counts flowing through the plan operators. To keep it lightweight, the plan that’s output by this xEvent doesn’t contain the session wait types, CPU times nor I/O metrics. An example session looks like this:

 

CREATE EVENT SESSION [PerfStats_LWP_Plan_All] ON SERVER
ADD EVENT sqlserver.query_post_execution_plan_profile(
ACTION(sqlos.scheduler_id,sqlserver.database_id,sqlserver.is_system,sqlserver.plan_handle,sqlserver.query_hash_signed,sqlserver.query_plan_hash_signed,sqlserver.server_instance_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.sql_text))
ADD TARGET package0.event_file(SET filename=N'C:\Temp\PerfStats_LWP_Plan_All.xel',max_file_size=(50),max_rollover_files=(2))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO

 

For this example, I ran the same query as in the query_thread_profile example. So, let’s see the resulting session output:

 

query_post_execution_plan_profile XEquery_post_execution_plan_profile XE

Same as in the previous example, clicking on the tab Query Plan shows me the actual execution plan, where again I see information on how many actual rows of estimated rows flowed through the operators.

 

image013.png

 

Same as in the previous example, the query text is not shown.

 

Pedro Lopes ( @SQLPedro ) – Senior Program Manager

12 Comments
Frequent Visitor

Thanks for the post! How is the new query_post_execution_plan_profile different from query_plan_profile? And does it still require the usage of the QUERY_PLAN_PROFILE hint?

Regular Visitor

This is fabulous. I'm excited to see that we continue to move toward a lower impact way of getting actual plans and runtime stats.  Hoping to see wait stats in these plan , too. Cheers. 

Occasional Contributor

[sqlserver.query_thread_profile] event is really cool stuff for dbas.

 

but this event only returns greater-than-zero value of [total_time_us] on SOME condition which I haven't figure out yet,.

can you specify the condition?

I try to use this data column as [sqlserver.query_thread_profile] for events so my event session won't flood by plan nodes event data

 

"okay, I want to collect all that plan nodes that exceed total_time_us greater than 10000 microseconds)"

Microsoft

Not sure I understand what condition you're referring to. You can filter on cpu_time or duration with the filter you want.

Occasional Contributor

i’m sorry I made a little bit of confusion.

 

I would like to make a filter on [total_time_us] data column of [sqlserver.query_thread_profile] event. but they barely return non-zero value.

 

Also, aren't [cpu time] and [duration] columns of the [rpc completed] event?

Occasional Contributor

* column description of sqlserver.query_thread_profile.[total_time_us] is following..

 -- Cumulative time in microseconds, including waits

* and this is a query of my event session

create event session [somesession] on server
add event [sqlserver.query_thread_profile
( action (
  sqlserver.database_id,
  sqlserver.is_system,
  sqlserver.plan_handle,
  sqlserver.query_hash_signed,
  sqlserver.query_plan_hash_signed,
  sqlserver.sql_text)
 where sqlserver.database_id > 4  -- all plan nodes from user database
 and sqlserver.is_system = 0  -- non system queries
 and [total_time_us] > 100000 -- all plans exceeding 100 milliseconds, I tried 10, 100, 5.
) add target package0.ring_buffer(SET max_memory=(4096))

and even I ran a stored procedure (simple select query) which took longer that 5 seconds, but data greater than 0 barely had been collected.

also sql version I tested is 'Microsoft SQL Server 2017 (RTM-CU17)'

 

Occasional Contributor

forget about previous comment. I should have read BOL carefully. 

 

It seems it is not enable to show detailed information (ex)cpu cost, total_tims_us.,) without using standard profiling infrastructure.

I would like to collect any resource information using light weight profiling, but not it is not easy to collect without additional work. (like adding set statistics profile on every stored procedure..)

 

can It be more easier? any plan for updating?

Occasional Contributor

Because, In production env. there is no signal for slow query will be executing any time. that is why I need to be prepare, collecting any queries and any query execution plans to capture that slow query. 


also it looks almost impossible to ask to devs that "hey guys can you add hint QUERY_PLAN_PROFILE on every queries for query monitoring?"

it sounds more like an impossible options to use in real life..

 

Microsoft

The XE we've been talking about is a troubleshooting XE, if I understood you, you want to run it 24x7 to detect "slow queries"? I suggest you use the Query Store for that purpose.

If that wasn't your scenario, then please explain your scenario carefully, and enter a feedback item at https://aka.ms/sqlfeedback.

Occasional Contributor

@Pedro Lopes  
yes, that is our scenario. 24x7 to detect "slow queries"?


we use XE as local profiler that always drops events if there is any pressure on server. and this let us to analyze workload when problem appears.

wait completed and rpc completed events and a few more events are helpful but event for plans are expensive events for a profiler.

so I found light weight profiling and was thinking maybe I could use it for analyzing slow queries.

 

now I am thinking "Query store" feature that you suggested for detecting and analyzing slow queries in real-time.

 

Thank you.

Occasional Contributor

query_post_execution_plan_profile

I Think this event is very useful also powerful, we don't need to use HINT or SET command and also using light weight profiling structure so that has less overhead of performance. following this article it is only about 2%(Developers Choice: Query progress - anytime, anywhere | Microsoft Docs)

 

I would rather use this one than QueryStore and the reason is that I can specify the condition I want to monitor. (ie, duration greater that 100 millisecond, cpu time greater than 100000 microsecond)

 

I can do query monitoring 24X7 only with 2% deal with performance. how fantastic it is!

Occasional Contributor

For the engineers those who got a bit confused like me.

 

There are 3 version of lightweight profiling(https://docs.microsoft.com/en-us/sql/relational-databases/performance/query-profiling-infrastructure...)

 

and some resources might not be collected due to selection of lightweight profiling version.

Please make sure to confirm which version you are using.

 

"Unlike standard profiling, lightweight profiling does not collect CPU runtime information. However, lightweight profiling still collects row count and I/O usage information......" - LightWeight Profiling v1

 

%3CLINGO-SUB%20id%3D%22lingo-sub-392136%22%20slang%3D%22en-US%22%3EUsing%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-392136%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%20still%20are%20working%20with%20SQL%20Profiler%2FSQL%20trace%2C%20welcome%20to%20the%20world%20of%20Extended%20Events%20(also%20known%20as%20xEvents%20or%20XE).%20SQL%20Trace%20has%20been%20deprecated%20and%20shouldn%E2%80%99t%20be%20used%20anymore.%20Why%3F%20Since%20SQL%20Server%202012%20we%20have%20xEvents%20for%20lower-impact%20troubleshooting%20and%20performance%20investigations%2C%20providing%20scalable%20insights%20into%20SQL%20Server%20behavior%2C%20and%20in%20the%20case%20we%E2%80%99re%20discussing%20here%2C%20query%20execution%20plans.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EQuery%20execution%20plans%2C%20otherwise%20known%20as%20actual%20execution%20plans%20or%20just%20Showplan%2C%20provide%20a%20map%20of%20all%20the%20required%20operations%20to%20get%20the%20query%20output%2C%20which%20includes%20runtime%20performance%20statistics.%3C%2FP%3E%0A%3CP%3EThese%20are%20available%20through%20Query%20Store%20(QS)%20for%20example%2C%20which%20is%20a%20valuable%20tool%20for%20troubleshooting%20workload%20*%3CSTRONG%3Etrends%3C%2FSTRONG%3E*%20via%20specific%20queries%20%E2%80%93%20this%20is%20because%20QS%20aggregates%20performance%20data%20on%20queries.%20However%2C%20sometimes%20we%20need%20to%20get%20the%20specific%2C%20singleton%20query%20execution%20plan%20to%20analyze%20and%20troubleshoot%20%E2%80%93%20this%20is%20where%20xEvents%20come%20in.%3C%2FP%3E%0A%3CP%3ESince%20SQL%20Server%202012%20we%E2%80%99ve%20had%20the%20%3CSTRONG%3E%3CEM%3Equery_post_execution_showplan%3C%2FEM%3E%3C%2FSTRONG%3E%20xEvent%20for%20this.%20As%20the%20name%20suggests%2C%20it%20gets%20you%20the%20actual%20query%20plan%20%E2%80%93%20because%20it%20is%20*%3CSTRONG%3Eafter%3C%2FSTRONG%3E*%20execution%20%E2%80%93%20when%20we%20have%20the%20runtime%20statistics%20available.%20However%20this%20xEvent%20is%20based%20on%20the%20%3CEM%3Estandard%20query%20execution%20statistics%20profile%20infrastructure%3C%2FEM%3E%20(quite%20a%20mouthful)%20%E2%80%93%20or%20standard%20profiling%20for%20short%20(read%20more%20about%20it%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Frelational-databases%2Fperformance%2Fquery-profiling-infrastructure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E).%20This%20one%20has%20a%20very%20high%20overhead%20(75%25%2B%20with%20a%20TPC-C%20like%20workload)%2C%20which%20is%20why%20its%20use%20needs%20to%20be%20seriously%20considered%2C%20and%20most%20likely%20not%20used%20unless%20in%20last%20resort.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20more%20recent%20releases%20we%20have%20other%20alternatives%20for%20these%20requirements%20to%20get%20the%20singleton%20actual%20execution%20plans%2C%20based%20on%20the%20%3CEM%3Elightweight%20query%20execution%20statistics%20profile%20infrastructure%20%3C%2FEM%3E%E2%80%93%20or%20lightweight%20profiling%20for%20short%20(read%20more%20about%20it%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Frelational-databases%2Fperformance%2Fquery-profiling-infrastructure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E).%20These%20xEvents%20are%20listed%20below%2C%20where%20we%E2%80%99ll%20see%20examples%20on%20how%20to%20use%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3E%3CEM%3Equery_thread_profile%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EThis%20is%20available%20starting%20with%20SQL%20Server%202014%20SP2%20and%20SQL%20Server%202016.%3C%2FP%3E%0A%3CP%3EThis%20xEvent%20doesn%E2%80%99t%20really%20give%20you%20a%20consolidated%20showplan%20as%20other%20xEvents%2C%20however%20it%20is%20useful%20in%20the%20sense%20it%20outputs%20one%20event%20per%20each%20data%20access%20operator%20and%20each%20execution%20thread%20found%20in%20an%20actual%20query%20execution%20plan%20%E2%80%93%20it%20can%20get%20quite%20verbose%20but%20allows%20use%20at%20a%20scale%20that%20was%20not%20possible%20with%20any%20other%20event%20before.%20An%20example%20session%20looks%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECREATE%20EVENT%20SESSION%20%5BPerfStats_Node%5D%20ON%20SERVER%3C%2FP%3E%0A%3CP%3EADD%20EVENT%20%3CSTRONG%3Esqlserver.query_thread_profile%3C%2FSTRONG%3E(%3C%2FP%3E%0A%3CP%3EACTION(sqlos.scheduler_id%2Csqlserver.database_id%2Csqlserver.is_system%2Csqlserver.plan_handle%2Csqlserver.query_hash_signed%2Csqlserver.query_plan_hash_signed%2Csqlserver.server_instance_name%2Csqlserver.session_id%2Csqlserver.session_nt_username%2Csqlserver.sql_text))%3C%2FP%3E%0A%3CP%3EADD%20TARGET%20package0.event_file(SET%20filename%3D%3CSTRONG%3EN'C%3A%5CTemp%5CPerfStats_Node.xel'%3C%2FSTRONG%3E%2Cmax_file_size%3D(50)%2Cmax_rollover_files%3D(2))%3C%2FP%3E%0A%3CP%3EWITH%20(MAX_MEMORY%3D4096%20KB%2CEVENT_RETENTION_MODE%3DALLOW_SINGLE_EVENT_LOSS%2CMAX_DISPATCH_LATENCY%3D30%20SECONDS%2CMAX_EVENT_SIZE%3D0%20KB%2CMEMORY_PARTITION_MODE%3DNONE%2CTRACK_CAUSALITY%3DOFF%2CSTARTUP_STATE%3DOFF)%3CBR%20%2F%3EGO%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20this%20example%2C%20I%20ran%20the%20following%20query%20in%20the%20AdventureWorks2016%20database%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESELECT%20COUNT(*)%3C%2FP%3E%0A%3CP%3EFROM%20Sales.SalesOrderDetail%20AS%20sod%3C%2FP%3E%0A%3CP%3EINNER%20JOIN%20Sales.SalesOrderHeader%20AS%20soh%3C%2FP%3E%0A%3CP%3EON%20soh.SalesOrderID%20%3D%20sod.SalesOrderID%3C%2FP%3E%0A%3CP%3EGROUP%20BY%20soh.Status%3B%3C%2FP%3E%0A%3CP%3EGO%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20let%E2%80%99s%20see%20the%20resulting%20session%20output%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100872i2F48AB6CA3CF2427%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image001.png%22%20title%3D%22image001.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Equery_thread_profile%20XE%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThe%20information%20found%20in%20each%20xEvent%20matches%20the%20%3CEM%3ERunTimeCountersPerThread%3C%2FEM%3E%20showplan%20element%20that%20may%20include%20such%20information%20as%20elapsed%20time%2C%20CPU%20time%2C%20logical%20and%20physical%20reads%20(if%20applicable).%20Notice%20we%20have%20selected%20the%20last%20event%20generated%2C%20and%20the%20%3CEM%3Enode_id%3C%2FEM%3E%20is%204.%20Something%20I%20know%20now%20is%20this%20plan%20has%205%20operators%20%E2%80%93%20nodes%200%20through%204%20%E2%80%93%20which%20can%20be%20searched%20in%20the%20graphical%20execution%20plan.%20Also%20notice%20that%20in%20each%20of%20these%20events%20you%20can%20find%20the%20%3CEM%3Eplan_handle%3C%2FEM%3E%20property.%20This%20can%20be%20used%20to%20get%20the%20graphical%20plan%20from%20cache%2C%20using%20the%20query%20below%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100869i7FBDA3290B0E036B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image003.png%22%20title%3D%22image003.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Esys.dm_exec_query_plan%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EClicking%20on%20the%20link%20in%20the%20results%20tab%20opens%20the%20graphical%20plan%2C%20and%20now%20it%E2%80%99s%20time%20to%20start%20mapping%20the%20XE%20session%20runtime%20information%20with%20the%20cached%20plan.%20To%20do%20this%20we%E2%80%99ll%20use%20a%20very%20useful%20feature%20in%20SSMS%20%E2%80%93%20Node%20Search%20%E2%80%93%20just%20right-click%20a%20blank%20area%20in%20the%20plan%20and%20you%20see%20it%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20809px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100870i253B7B855CB4ED7A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image005.png%22%20title%3D%22image005.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EFind%20Node%20in%20SSMS%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EThis%20feature%20allows%20me%20to%20search%20for%20any%20property%20in%20the%20plan%20%E2%80%93%20and%20so%20I%20search%20for%20%3CSTRONG%3ENodeId%3C%2FSTRONG%3E%204%20%E2%80%93%20and%20get%20immediately%20positioned%20in%20the%20plan%20operator%20that%20represents%20that%20node%20id%204.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20534px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100871iD53A2EA8EACFC279%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image007.png%22%20title%3D%22image007.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EFind%20Node%20-%20NodeId%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EAnd%20now%20comparing%20with%20the%20XE%20output%2C%20I%20can%20see%20the%20graphical%20plan%20and%20the%20actual%20and%20estimated%20rows%20that%20were%20read%20by%20that%20Index%20Scan%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20815px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100873i58A1BC019F6B0677%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image009.png%22%20title%3D%22image009.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Equery_thread_profile%20XE%20compare%20with%20Graphical%20Plan%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EIt%20can%20be%20an%20arduous%20task%20to%20do%20the%20above%2C%20but%20for%20collecting%20runtime%20plan%20data%20at%20scale%20and%20then%20zero%20in%20on%20some%20specific%20plan%2C%20it%20is%20useful.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3E%3CEM%3Equery_plan_profile%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EThis%20is%20available%20starting%20with%20SQL%20Server%202016%20SP2%20CU3%20and%20SQL%20Server%202017%20CU11.%20This%20xEvent%20outputs%20the%20equivalent%20of%20a%20query%20execution%20plan%20similar%20to%20the%20%3CEM%3Equery_post_execution_showplan%3C%2FEM%3E%20xEvent%2C%20but%20only%20for%20the%20query%20or%20queries%20that%20are%20using%20the%20USE%20HINT%20('QUERY_PLAN_PROFILE').%20An%20example%20session%20looks%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECREATE%20EVENT%20SESSION%20%5BPerfStats_LWP_Plan_Single%5D%20ON%20SERVER%3CBR%20%2F%3EADD%20EVENT%20%3CSTRONG%3Esqlserver.query_plan_profile%3C%2FSTRONG%3E(%3CBR%20%2F%3EACTION(sqlos.scheduler_id%2Csqlserver.database_id%2Csqlserver.is_system%2Csqlserver.plan_handle%2Csqlserver.query_hash_signed%2Csqlserver.query_plan_hash_signed%2Csqlserver.server_instance_name%2Csqlserver.session_id%2Csqlserver.session_nt_username%2Csqlserver.sql_text))%3CBR%20%2F%3EADD%20TARGET%20package0.event_file(SET%20filename%3D%3CSTRONG%3EN'C%3A%5CTemp%5CPerfStats_LWP_Plan_Single.xel'%3C%2FSTRONG%3E%2Cmax_file_size%3D(50)%2Cmax_rollover_files%3D(2))%3CBR%20%2F%3EWITH%20(MAX_MEMORY%3D4096%20KB%2CEVENT_RETENTION_MODE%3DALLOW_SINGLE_EVENT_LOSS%2CMAX_DISPATCH_LATENCY%3D30%20SECONDS%2CMAX_EVENT_SIZE%3D0%20KB%2CMEMORY_PARTITION_MODE%3DNONE%2CTRACK_CAUSALITY%3DOFF%2CSTARTUP_STATE%3DOFF)%3CBR%20%2F%3EGO%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20allows%20a%20very%20targeted%20plan%20collection%20that%20doesn%E2%80%99t%20require%20filtering%20of%20any%20sort%20in%20the%20XE%20session.%20If%20a%20query%20you%20want%20to%20track%20is%20generated%20by%20an%20application%20and%20you%20can%E2%80%99t%20change%20the%20query%20at%20its%20origin%2C%20then%20you%20can%20use%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Frelational-databases%2Fperformance%2Fplan-guides%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eplan%20guide%3C%2FA%3E%20to%20add%20the%20hint%2C%20as%20in%20the%20example%20below%20created%20for%20a%20stored%20procedure%20named%20%3CEM%3ESales.CountSalesOrderByStatus%3C%2FEM%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEXEC%20sp_create_plan_guide%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%40name%20%3D%20N'Guide1'%2C%3C%2FP%3E%0A%3CP%3E%40stmt%20%3D%20'SELECT%20COUNT(*)%3C%2FP%3E%0A%3CP%3EFROM%20Sales.SalesOrderDetail%20AS%20sod%3C%2FP%3E%0A%3CP%3EINNER%20JOIN%20Sales.SalesOrderHeader%20AS%20soh%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20ON%20soh.SalesOrderID%20%3D%20sod.SalesOrderID%3C%2FP%3E%0A%3CP%3EGROUP%20BY%20soh.STATUS%3B'%2C%3C%2FP%3E%0A%3CP%3E%40type%20%3D%20N'OBJECT'%2C%3C%2FP%3E%0A%3CP%3E%40module_or_batch%20%3D%20N'Sales.CountSalesOrderByStatus'%2C%3C%2FP%3E%0A%3CP%3E%40params%20%3D%20NULL%2C%3C%2FP%3E%0A%3CP%3E%40hints%20%3D%20N'OPTION%20(USE%20HINT%20(''QUERY_PLAN_PROFILE''))'%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20let%E2%80%99s%20see%20the%20resulting%20session%20output%20where%20I%20can%20already%20see%20runtime%20data%20such%20as%20the%20query%20duration%2C%20the%20memory%20grant%20and%20used%20memory%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100874i1FD7BD48D4A7CBF1%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image011.png%22%20title%3D%22image011.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Equery_plan_profile%20XE%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EClicking%20on%20the%20tab%20Query%20Plan%20shows%20me%20the%20actual%20execution%20plan.%20The%20immediate%20giveaway%20is%20that%20I%20see%20information%20on%20how%20many%20%3CEM%3Eactual%20rows%20%3CSTRONG%3Eof%3C%2FSTRONG%3E%20estimated%20rows%3C%2FEM%3E%20flowed%20through%20the%20operators.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20816px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100875i3BDCE360AE9A3FCD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image013.png%22%20title%3D%22image013.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENotice%20the%20query%20text%20is%20not%20shown.%20This%20is%20another%20way%20of%20keeping%20these%20events%20lightweight.%20The%20xEvent%20already%20captures%20the%20%3CEM%3Esql_text%3C%2FEM%3E.%20And%20if%20needed%20and%20the%20plan%20is%20cached%2C%20you%20can%20always%20get%20the%20cached%20plan%20from%20%3CEM%3Esys.dm_exec_cached_plans%3C%2FEM%3E%20using%20the%20%3CEM%3Eplan_handle%3C%2FEM%3E%2C%20and%20the%20query%20text%20is%20shown%20there.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%225%22%3E%3CSTRONG%3E%3CEM%3Equery_post_execution_plan_profile%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3EThis%20is%20a%20new%20xEvent%20available%20starting%20with%20SQL%20Server%202017%20CU14%20and%20SQL%20Server%202019.%20Much%20like%20the%20%3CEM%3Equery_post_execution_showplan%3C%2FEM%3E%20xEvent%2C%20the%20new%20%3CEM%3Equery_post_execution_plan_profile%3C%2FEM%3E%20outputs%20the%20actual%20query%20execution%20plan%20with%20fundamental%20data%20that%E2%80%99%20usually%20required%20to%20troubleshoot%20query%20performance%2C%20such%20as%20the%20row%20counts%20flowing%20through%20the%20plan%20operators.%20To%20keep%20it%20lightweight%2C%20the%20plan%20that%E2%80%99s%20output%20by%20this%20xEvent%20doesn%E2%80%99t%20contain%20the%20session%20wait%20types%2C%20CPU%20times%20nor%20I%2FO%20metrics.%20An%20example%20session%20looks%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECREATE%20EVENT%20SESSION%20%5BPerfStats_LWP_Plan_All%5D%20ON%20SERVER%3CBR%20%2F%3EADD%20EVENT%20%3CSTRONG%3Esqlserver.query_post_execution_plan_profile%3C%2FSTRONG%3E(%3CBR%20%2F%3EACTION(sqlos.scheduler_id%2Csqlserver.database_id%2Csqlserver.is_system%2Csqlserver.plan_handle%2Csqlserver.query_hash_signed%2Csqlserver.query_plan_hash_signed%2Csqlserver.server_instance_name%2Csqlserver.session_id%2Csqlserver.session_nt_username%2Csqlserver.sql_text))%3CBR%20%2F%3EADD%20TARGET%20package0.event_file(SET%20filename%3D%3CSTRONG%3EN'C%3A%5CTemp%5CPerfStats_LWP_Plan_All.xel'%3C%2FSTRONG%3E%2Cmax_file_size%3D(50)%2Cmax_rollover_files%3D(2))%3CBR%20%2F%3EWITH%20(MAX_MEMORY%3D4096%20KB%2CEVENT_RETENTION_MODE%3DALLOW_SINGLE_EVENT_LOSS%2CMAX_DISPATCH_LATENCY%3D30%20SECONDS%2CMAX_EVENT_SIZE%3D0%20KB%2CMEMORY_PARTITION_MODE%3DNONE%2CTRACK_CAUSALITY%3DOFF%2CSTARTUP_STATE%3DOFF)%3CBR%20%2F%3EGO%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20this%20example%2C%20I%20ran%20the%20same%20query%20as%20in%20the%20%3CEM%3Equery_thread_profile%3C%2FEM%3E%20example.%20So%2C%20let%E2%80%99s%20see%20the%20resulting%20session%20output%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100876i53BF63C62C42A1FE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image015.png%22%20title%3D%22image015.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Equery_post_execution_plan_profile%20XE%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ESame%20as%20in%20the%20previous%20example%2C%20clicking%20on%20the%20tab%20Query%20Plan%20shows%20me%20the%20actual%20execution%20plan%2C%20where%20again%20I%20see%20information%20on%20how%20many%20%3CEM%3Eactual%20rows%20%3CSTRONG%3Eof%3C%2FSTRONG%3E%20estimated%20rows%3C%2FEM%3E%20flowed%20through%20the%20operators.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20816px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F100875i3BDCE360AE9A3FCD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image013.png%22%20title%3D%22image013.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESame%20as%20in%20the%20previous%20example%2C%20the%20query%20text%20is%20not%20shown.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPedro%20Lopes%20(%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2FSQLPedro%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%40SQLPedro%20%3C%2FA%3E)%20%E2%80%93%20Senior%20Program%20Manager%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-392136%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20style%3D%22display%3A%20inline%20!important%3B%20float%3A%20none%3B%20background-color%3A%20%23ffffff%3B%20color%3A%20%23333333%3B%20cursor%3A%20text%3B%20font-family%3A%20inherit%3B%20font-size%3A%2016px%3B%20font-style%3A%20normal%3B%20font-variant%3A%20normal%3B%20font-weight%3A%20300%3B%20letter-spacing%3A%20normal%3B%20line-height%3A%201.7142%3B%20orphans%3A%202%3B%20text-align%3A%20left%3B%20text-decoration%3A%20none%3B%20text-indent%3A%200px%3B%20text-transform%3A%20none%3B%20-webkit-text-stroke-width%3A%200px%3B%20white-space%3A%20normal%3B%20word-spacing%3A%200px%3B%22%3EIf%20you%20still%20are%20working%20with%20SQL%20Profiler%2FSQL%20trace%2C%20welcome%20to%20the%20world%20of%20Extended%20Events%20(also%20known%20as%20xEvents%20or%20XE).%20SQL%20Trace%20has%20been%20deprecated%20and%20shouldn%E2%80%99t%20be%20used%20anymore.%3C%2FSPAN%3E%20However%2C%20in%20the%20last%20few%20months%20we%20have%20made%20available%20a%20few%20xEvents%20that%20allow%20you%20to%20track%20query%20plans%2C%20which%20are%20useful%20for%20edge-case%20scenarios%20where%20the%20aggregated%20data%20found%20in%20Query%20Store%20is%20not%20enough%20for%20troubleshooting.%20This%20post%20explains%20what%20these%20xEvents%20are.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-392136%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerTiger%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-393573%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-393573%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20post!%20How%20is%20the%20new%20query_post_execution_plan_profile%20different%20from%26nbsp%3Bquery_plan_profile%3F%20And%20does%20it%20still%20require%20the%20usage%20of%20the%26nbsp%3B%3CSPAN%3EQUERY_PLAN_PROFILE%20hint%3F%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-839874%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-839874%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%20fabulous.%20I'm%20excited%20to%20see%20that%20we%20continue%20to%20move%20toward%20a%20lower%20impact%20way%20of%20getting%20actual%20plans%20and%20runtime%20stats.%26nbsp%3B%20Hoping%20to%20see%20wait%20stats%20in%20these%20plan%20%2C%20too.%20Cheers.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1240771%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1240771%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%5Bsqlserver.query_thread_profile%5D%20event%20is%20really%20cool%20stuff%20for%20dbas.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebut%20this%20event%20only%20returns%20greater-than-zero%20value%20of%20%5Btotal_time_us%5D%20on%20SOME%20condition%20which%20I%20haven't%20figure%20out%20yet%2C.%3C%2FP%3E%3CP%3Ecan%20you%20specify%20the%20condition%3F%3C%2FP%3E%3CP%3EI%20try%20to%20use%20this%20data%20column%20as%20%5Bsqlserver.query_thread_profile%5D%20for%20events%20so%20my%20event%20session%20won't%20flood%20by%20plan%20nodes%20event%20data%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22okay%2C%20I%20want%20to%20collect%20all%20that%20plan%20nodes%20that%20exceed%20total_time_us%20greater%20than%2010000%20microseconds)%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1242874%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1242874%22%20slang%3D%22en-US%22%3E%3CP%3ENot%20sure%20I%20understand%20what%20condition%20you're%20referring%20to.%20You%20can%20filter%20on%20cpu_time%20or%20duration%20with%20the%20filter%20you%20want.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1243339%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1243339%22%20slang%3D%22en-US%22%3E%3CP%3Ei%E2%80%99m%20sorry%20I%20made%20a%20little%20bit%20of%20confusion.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20make%20a%20filter%20on%20%5Btotal_time_us%5D%20data%20column%20of%20%5Bsqlserver.query_thread_profile%5D%20event.%20but%20they%20barely%20return%20non-zero%20value.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20aren't%20%5Bcpu%20time%5D%20and%20%5Bduration%5D%20columns%20of%20the%20%5Brpc%20completed%5D%20event%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1243632%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1243632%22%20slang%3D%22en-US%22%3E%3CP%3E*%20column%20description%20of%20sqlserver.query_thread_profile.%5Btotal_time_us%5D%20is%20following..%3C%2FP%3E%3CP%3E%26nbsp%3B--%26nbsp%3B%3CSTRONG%3E%3CSPAN%3ECumulative%20time%20in%20microseconds%2C%20including%20waits%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E*%20and%20this%20is%20a%20query%20of%20my%20event%20session%3C%2FP%3E%3CPRE%3Ecreate%20event%20session%20%5Bsomesession%5D%20on%20server%0Aadd%20event%20%5Bsqlserver.query_thread_profile%0A(%20action%26nbsp%3B(%0A%26nbsp%3B%20sqlserver.database_id%2C%0A%26nbsp%3B%20sqlserver.is_system%2C%0A%26nbsp%3B%20sqlserver.plan_handle%2C%0A%26nbsp%3B%20sqlserver.query_hash_signed%2C%0A%26nbsp%3B%20sqlserver.query_plan_hash_signed%2C%0A%26nbsp%3B%20sqlserver.sql_text)%0A%26nbsp%3Bwhere%20sqlserver.database_id%20%26gt%3B%204%20%26nbsp%3B--%20all%20plan%20nodes%20from%20user%20database%0A%26nbsp%3Band%20sqlserver.is_system%20%3D%200%20%26nbsp%3B--%20non%20system%20queries%0A%26nbsp%3Band%20%5Btotal_time_us%5D%20%26gt%3B%20100000%20--%20all%20plans%20exceeding%20100%20milliseconds%2C%20I%20tried%2010%2C%20100%2C%205.%0A)%20add%20target%26nbsp%3Bpackage0.ring_buffer(SET%20max_memory%3D(4096))%3C%2FPRE%3E%3CP%3Eand%20even%20I%20ran%20a%20stored%20procedure%20(simple%20select%20query)%20which%20took%20longer%20that%205%20seconds%2C%20but%20data%20greater%20than%200%20barely%20had%20been%20collected.%3C%2FP%3E%3CP%3Ealso%20sql%20version%20I%20tested%20is%20'%3CSPAN%3EMicrosoft%20SQL%20Server%202017%20(RTM-CU17)'%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1245824%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1245824%22%20slang%3D%22en-US%22%3E%3CP%3Eforget%20about%20previous%20comment.%20I%20should%20have%20read%20BOL%20carefully.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20seems%20it%20is%20not%20enable%20to%20show%20detailed%20information%20(ex)cpu%20cost%2C%20total_tims_us.%2C)%20without%20using%20standard%20profiling%20infrastructure.%3C%2FP%3E%3CP%3EI%20would%20like%20to%20collect%20any%20resource%20information%20using%20light%20weight%20profiling%2C%20but%20not%20it%20is%20not%20easy%20to%20collect%20without%20additional%20work.%20(like%20adding%20set%20statistics%20profile%20on%20every%20stored%20procedure..)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecan%20It%20be%20more%20easier%3F%20any%20plan%20for%20updating%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1245865%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1245865%22%20slang%3D%22en-US%22%3E%3CP%3EBecause%2C%20In%20production%20env.%20there%20is%20no%20signal%20for%20slow%20query%20will%20be%20executing%20any%20time.%20that%20is%20why%20I%20need%20to%20be%20prepare%2C%20collecting%20any%20queries%20and%20any%20query%20execution%20plans%20to%20capture%20that%20slow%20query.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Ealso%20it%20looks%20almost%20impossible%20to%20ask%20to%20devs%20that%20%22hey%20guys%20can%20you%20add%20hint%26nbsp%3BQUERY_PLAN_PROFILE%20on%20every%20queries%20for%20query%20monitoring%3F%22%3C%2FP%3E%3CP%3E%3CSPAN%3Eit%20sounds%20more%20like%20an%20impossible%20options%20to%20use%20in%20real%20life..%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1247292%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1247292%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20XE%20we've%20been%20talking%20about%20is%20a%20troubleshooting%20XE%2C%20if%20I%20understood%20you%2C%20you%20want%20to%20run%20it%2024x7%20to%20detect%20%22slow%20queries%22%3F%20I%20suggest%20you%20use%20the%20Query%20Store%20for%20that%20purpose.%3C%2FP%3E%0A%3CP%3EIf%20that%20wasn't%20your%20scenario%2C%20then%20please%20explain%20your%20scenario%20carefully%2C%20and%20enter%20a%20feedback%20item%20at%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fsqlfeedback%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Faka.ms%2Fsqlfeedback%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1248382%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1248382%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F194232%22%20target%3D%22_blank%22%3E%40Pedro%20Lopes%3C%2FA%3E%26nbsp%3B%26nbsp%3B%3CBR%20%2F%3Eyes%2C%20that%20is%20our%20scenario.%26nbsp%3B%3CU%3E24x7%20to%20detect%20%22slow%20queries%22%3F%3C%2FU%3E%3C%2FP%3E%3CP%3E%3CBR%20%2F%3Ewe%20use%20XE%20as%20local%20profiler%20that%20always%20drops%20events%20if%20there%20is%20any%20pressure%20on%20server.%20and%20this%20let%20us%20to%20analyze%20workload%20when%20problem%20appears.%3C%2FP%3E%3CP%3Ewait%20completed%20and%20rpc%20completed%20events%20and%20a%20few%20more%20events%20are%20helpful%20but%20event%20for%20plans%20are%20expensive%20events%20for%20a%20profiler.%3C%2FP%3E%3CP%3Eso%20I%20found%20light%20weight%20profiling%20and%20was%20thinking%20maybe%20I%20could%20use%20it%20for%20analyzing%20slow%20queries.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Enow%20I%20am%20thinking%20%22Query%20store%22%20feature%20that%20you%20suggested%20for%20detecting%20and%20analyzing%20slow%20queries%20in%20real-time.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2245975%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2245975%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%3CEM%3Equery_post_execution_plan_profile%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3EI%20Think%20this%20event%20is%20very%20useful%20also%20powerful%2C%20we%20don't%20need%20to%20use%20HINT%20or%20SET%20command%20and%20also%20using%20light%20weight%20profiling%20structure%20so%20that%20has%20less%20overhead%20of%20performance.%20following%20this%20article%20it%20is%20only%20about%202%25(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fko-kr%2Farchive%2Fblogs%2Fsql_server_team%2Fquery-progress-anytime-anywhere%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EDevelopers%20Choice%3A%20Query%20progress%20-%20anytime%2C%20anywhere%20%7C%20Microsoft%20Docs%3C%2FA%3E)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20rather%20use%20this%20one%20than%20QueryStore%20and%20the%20reason%20is%20that%20I%20can%20specify%20the%20condition%20I%20want%20to%20monitor.%20(ie%2C%20duration%20greater%20that%20100%20millisecond%2C%20cpu%20time%20greater%20than%20100000%20microsecond)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can%20do%20query%20monitoring%2024X7%20only%20with%202%25%20deal%20with%20performance.%20how%20fantastic%20it%20is!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2248150%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20xEvents%20to%20capture%20an%20Actual%20Execution%20Plan%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2248150%22%20slang%3D%22en-US%22%3E%3CP%3EFor%20the%20engineers%20those%20who%20got%20a%20bit%20confused%20like%20me.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%203%20version%20of%20lightweight%20profiling(%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fperformance%2Fquery-profiling-infrastructure%3Fview%3Dsql-server-ver15%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Frelational-databases%2Fperformance%2Fquery-profiling-infrastructure%3Fview%3Dsql-server-ver15%3C%2FA%3E)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eand%20some%20resources%20might%20not%20be%20collected%20due%20to%20selection%20of%20lightweight%20profiling%20version.%3C%2FP%3E%3CP%3EPlease%20make%20sure%20to%20confirm%20which%20version%20you%20are%20using.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3E%22Unlike%20standard%20profiling%2C%20lightweight%20profiling%20does%20not%20collect%20CPU%20runtime%20information.%20However%2C%20lightweight%20profiling%20still%20collects%20row%20count%20and%20I%2FO%20usage%20information......%22%20-%20LightWeight%20Profiling%20v1%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CH3%20id%3D%22toc-hId-1505513437%22%20id%3D%22toc-hId-1505513437%22%3E%26nbsp%3B%3C%2FH3%3E%3C%2FLINGO-BODY%3E
Version history
Last update:
‎Apr 02 2019 08:37 AM
Updated by: