Criamos um evento estendido para capturar consultas de longa duração, o objetivo é obter o plano de execução juntando-se à coluna de manipulação do plano, alguns dados do evento têm um identificador de plano com valor de id, mas alguns têm apenas "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 e incapaz de buscar o plano de execução com base neste ZERO e produzir Null.
aqui está 1 exemplo, por favor, guie o que está errado aqui e como recuperar o plano de execução para tal identificador de plano?
Muito obrigado pelo seu tempo.
<event name="sql_batch_completed" package="sqlserver" timestamp="2022-08-19T16:13:10.711Z">
<data name="cpu_time">
<value>34797000</value>
</data>
<data name="duration">
<value>42259048</value>
</data>
<data name="physical_reads">
<value>640</value>
</data>
<data name="logical_reads">
<value>17204111</value>
</data>
<data name="writes">
<value>79477</value>
</data>
<data name="row_count">
<value>8180</value>
</data>
<data name="result">
<value>0</value>
<text>OK</text>
</data>
<data name="batch_text">
<value>select SYSDATETIMEOFFSET() AS [Current_System_DateTime_Offset], event_data,
DATEADD(SS, DATEDIFF(SS, GETUTCDATE(), CURRENT_TIMESTAMP), CONVERT(XML, event_Data).value('(event/@timestamp)[1]', 'datetime2')) AS [ServerDateTime]
, (select top 1 query_plan from sys.dm_exec_query_plan(CONVERT(VARBINARY(64), '0x' +
CAST((CONVERT(XML, event_Data).value(N'(event/action[@name="plan_handle"]/value)[1]', N'nvarchar(max)')) AS varchar(4000)),1))) Query_plan ,
CONVERT(XML, event_Data).value(N'(event/action[@name="plan_handle"]/value)[1]', N'nvarchar(max)') plan_handle
FROM sys.fn_xe_file_target_read_file('C:\folder1\long_queries_long_queries_36c0ad49cf4e462fb7419312d0*xel', NULL, NULL, NULL)
where DATEADD(SS, DATEDIFF(SS, GETUTCDATE(), CURRENT_TIMESTAMP), CONVERT(XML, event_Data).value('(event/@timestamp)[1]', 'datetime2')) > '2022-08-18 17:45:11.3280000'
order by DATEADD(SS, DATEDIFF(SS, GETUTCDATE(), CURRENT_TIMESTAMP), CONVERT(XML, event_Data).value('(event/@timestamp)[1]', 'datetime2')) desc</value>
</data>
<action name="collect_system_time" package="package0">
<value>2022-08-19T16:13:10.711Z</value>
</action>
<action name="client_app_name" package="sqlserver">
<value>Microsoft SQL Server Management Studio - Query</value>
</action>
<action name="client_hostname" package="sqlserver">
<value>CHANDAN-PC</value>
</action>
<action name="database_name" package="sqlserver">
<value>SQLPlanner</value>
</action>
<action name="plan_handle" package="sqlserver">
<value>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</value>
</action>
<action name="session_id" package="sqlserver">
<value>53</value>
</action>
<action name="session_nt_username" package="sqlserver">
<value>CHANDAN-PC\Chandan Kumar</value>
</action>
<action name="sql_text" package="sqlserver">
<value>select SYSDATETIMEOFFSET() AS [Current_System_DateTime_Offset], event_data,
DATEADD(SS, DATEDIFF(SS, GETUTCDATE(), CURRENT_TIMESTAMP), CONVERT(XML, event_Data).value('(event/@timestamp)[1]', 'datetime2')) AS [ServerDateTime]
, (select top 1 query_plan from sys.dm_exec_query_plan(CONVERT(VARBINARY(64), '0x' +
CAST((CONVERT(XML, event_Data).value(N'(event/action[@name="plan_handle"]/value)[1]', N'nvarchar(max)')) AS varchar(4000)),1))) Query_plan ,
CONVERT(XML, event_Data).value(N'(event/action[@name="plan_handle"]/value)[1]', N'nvarchar(max)') plan_handle
FROM sys.fn_xe_file_target_read_file('C:\folder1\long_queries_36c0ad49cf4e462fb7419312d0*xel', NULL, NULL, NULL)
where DATEADD(SS, DATEDIFF(SS, GETUTCDATE(), CURRENT_TIMESTAMP), CONVERT(XML, event_Data).value('(event/@timestamp)[1]', 'datetime2')) > '2022-08-18 17:45:11.3280000'
order by DATEADD(SS, DATEDIFF(SS, GETUTCDATE(), CURRENT_TIMESTAMP), CONVERT(XML, event_Data).value('(event/@timestamp)[1]', 'datetime2')) desc</value>
</action>
<action name="transaction_id" package="sqlserver">
<value>0</value>
</action>
<action name="transaction_sequence" package="sqlserver">
<value>0</value>
</action>
<action name="username" package="sqlserver">
<value>CHANDAN-PC\Chandan Kumar</value>
</action>
</event>