You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SELECTTOP ( @Top ) ISNULL(xml.deadlock_xml, '') AS deadlock_xml
312
+
SELECTISNULL(xml.deadlock_xml, '') AS deadlock_xml
313
313
INTO #deadlock_data
314
314
FROMxml
315
315
LEFT JOIN #t AS t
@@ -322,6 +322,17 @@ You need to use an Azure storage account, and the path has to look like this: ht
322
322
ORDER BYxml.deadlock_xml.value('(/event/@timestamp)[1]', 'datetime') DESC
323
323
OPTION ( RECOMPILE );
324
324
325
+
/*Optimization: if we got back more rows than @Top, remove them. This seems to be better than using @Top in the query above as that results in excessive memory grant*/
326
+
SET @DeadlockCount =@@ROWCOUNT
327
+
IF( @Top < @DeadlockCount ) BEGIN
328
+
WITH T
329
+
AS (
330
+
SELECTTOP ( @DeadlockCount - @Top) *
331
+
FROM #deadlock_data
332
+
ORDER BY #deadlock_data.deadlock_xml.value('(/event/@timestamp)[1]', 'datetime') ASC)
333
+
DELETEFROM T
334
+
END
335
+
325
336
/*Parse process and input buffer XML*/
326
337
SET @d =CONVERT(VARCHAR(40), GETDATE(), 109);
327
338
RAISERROR('Parse process and input buffer XML %s', 0, 1, @d) WITHNOWAIT;
0 commit comments