SQL Server: DMV to Track Page Split

原文链接:http://social.technet.microsoft.com/wiki/contents/articles/25473.sql-server-dmv-to-track-page-split.aspx

Introduction

Page split is important factor in analyzing how often a fragmentation occurs in the database. Page splits are normal because when rows are added to index, a page needs to be added to right hand side of index to accommodate new rows and for this database engine does page splits and adds a new page. But it can be performance bottleneck when update is done on a row and the value added is not able to fit on the page and thus causing page split.. This type of page split is nasty one as it leave space on the page which would not be utilized as when data will be inserted in table having index it would be written to last page on right hand side.

Page Split

When page split happens due to update operation, SQL Server will have to allocate a new page and now process will have to wait till a new page is allocated and this whole time the page which needs to be updated will be locked. In more granular term a latch will be taken and this would continue till page is allocated and rows are inserted. This could be a deciding factor on OLTP environment. Page splits can be normal as pointed above or can be nasty. Its difficult to find Nasty page split and normal one using DMV you can track that with fn_dblog. if you are using SQL Server 2012 you can use extended events to track nasty page splits
As per online resources there are lot of articles which point you how to track page splits using undocumented command fn_dblog and fn_dump_dblog. But there are performance implications using this command in Production server and also such commands are not supported by Microsoft.

DMV to Track Page Splits

Well you don’t need to worry about using undocumented command to track page split because SQL Server provides a DMV to track page splits. Sys.dm_db_index_operationl_stats This link is external to TechNet Wiki. It will open in a new window. DMV provides a method to track page splits. If you refer to Microsoft online documentation for this DMV you will find two columns

leaf_allocation_countbigintCumulative count of leaf-level page allocations in the index or heap. For an index, a page allocation corresponds to a page split.
nonleaf_allocation_countbigintCumulative count of page allocations caused by page splits above the leaf level. 0 = Heap or columnstore

You can see leaf allocation count column value corresponds to page splits which occurred for the index. Although you would not get information about whether this page split was done on right side of index when data was added or was result of row not being able to fit on a page causing extra page to be allocated and thus fragmentation.

T-SQL Script to track Page Split

Please note that there is no page split for HEAP(A table without clustered index). Heaps have forwarding pointers.Below is a simple query which will allow you to tarck page splits

--Script to check page split for index
SELECT

IOS.INDEX_ID,
O.NAME AS OBJECT_NAME,
I.NAME AS INDEX_NAME,
IOS.LEAF_ALLOCATION_COUNT AS PAGE_SPLIT_FOR_INDEX,
IOS.NONLEAF_ALLOCATION_COUNT PAGE_ALLOCATION_CAUSED_BY_PAGESPLIT
FROM SYS.DM_DB_INDEX_OPERATIONAL_STATS(DB_ID(N'DB_NAME'),NULL,NULL,NULL) IOS
JOIN
SYS.INDEXES I
ON
IOS.INDEX_ID=I.INDEX_ID
AND IOS.OBJECT_ID = I.OBJECT_ID
JOIN
SYS.OBJECTS O
ON
IOS.OBJECT_ID=O.OBJECT_ID
WHERE O.TYPE_DESC='USER_TABLE'

Above query will give page splits for all Indexes present in database. You can add specific table name in the query to filter down page splits for indexes belonging to particular table.

You can also use EXTENDED EVENTS This link is external to TechNet Wiki. It will open in a new window. trace to capture page splits but that can be used for SQL server 2012 and above please refer to See Also Section for Link.

See Also

  1. Use Extended events In SQL Server 2012 to Track Page Splits
  2. SQL Server General & Database Engine Resources on the TechNet Wiki
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值