1

I am new to extended events however, I got to know about the same by reading some articles like this one

My question: Is there any event in Event Library by which we can identify Fragmented Index ?

Because I got only

enter image description here

I am using SQL Server 2014.

Thanks in advance

priyanka.sarkar
  • 25,766
  • 43
  • 127
  • 173

2 Answers2

2

Not directly. Fragmentation exists when the physical order of an index doesn't match the logical order. And that happens when there is need to put data on a page for which there is no room, thus causing a page split. There is an event for page splits. However, I wouldn't use it to track fragmentation in the general case. The event exists more for tracking activity for one-off operations. If you want to look at fragmentation, take a look at sys.dm_db_index_physical_stats.

Ben Thul
  • 31,080
  • 4
  • 45
  • 68
1

To add to @Ben Thuls's answer, you may track page splits using extended events and thus track fragmentation indirectly. Check this awesome article by Paul Randal to familiarize yourself with the LOP_DELETE_SPLIT log operation and then create a session which will look like that:

CREATE EVENT SESSION [Page Splits] ON SERVER 
ADD EVENT sqlserver.transaction_log(SET collect_database_name = 1
   WHERE (operation = $LOP_DELETE_ID$) ) --LOP_DELETE_SPLIT*
ADD TARGET package0.event_file(SET FILENAME = N'PageSplitsOutput.xel',MAX_FILE_SIZE = 200, MAX_ROLLOVER_FILES = 2, INCREMENT = 20)
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

And fill $LOP_DELETE_ID$ with the result from this:

SELECT *
FROM sys.dm_xe_map_values
WHERE name = 'log_op'
AND map_value = 'LOP_DELETE_SPLIT';
Community
  • 1
  • 1
S.Karras
  • 1,483
  • 15
  • 19