我用range left func做了一個分區表。我然後插入一些行到只有一個分區。結果:SQL Server中爲什麼行鎖存在完全空分區?
select partition_id, partition_number, rows from sys.partitions where object_id = object_id('ptest')
結果:
partition_id partition_number rows
72057594464436224 1 8000
72057594464501760 2 0
72057594464567296 3 0
72057594464632832 4 0
然後我更新這個表和查詢sys.dm_tran_locks的某些行,然後我找到partition4一些RID鎖是這樣的:
select * from sys.dm_tran_locks where resource_type = 'RID'
結果是這樣的:
Resource_type Resource_description
RID 3:13:192
RID 1:153496:257
當我使用DBCC頁覈實3:13包含哪些頁面,我得到什麼:
dbcc traceon(3604)
dbcc page(db, 3, 13, 3)
結果是這樣的:
PAGE: (3:13)
BUFFER:
BUF @0x03E98BCC
bpage = 0x5A622000 bhash = 0x00000000 bpageno = (3:13)
bdbid = 11 breferences = 0 bUse1 = 38298
bstat = 0x1c0010b blog = 0x79797979 bnext = 0x00000000
PAGE HEADER:
Page @0x5A622000
m_pageId = (3:13) m_headerVersion = 1 m_type = 1
m_typeFlagBits = 0x4 m_level = 0 m_flagBits = 0xa008
m_objId (AllocUnitId.idObj) = 6973 m_indexId (AllocUnitId.idInd) = 256
Metadata: AllocUnitId = 72057594494910464
Metadata: PartitionId = 72057594464501760 Metadata: IndexId = 0
Metadata: ObjectId = 1967398128 m_prevPage = (0:0) m_nextPage = (0:0)
pminlen = 12 m_slotCnt = 1 m_freeCnt = 8094
m_freeData = 5867 m_reservedCnt = 0 m_lsn = (25294:376:199)
m_xactReserved = 0 m_xdesId = (0:0) m_ghostRecCnt = 0
m_tornBits = -252731581
Allocation Status
GAM (3:2) = ALLOCATED SGAM (3:3) = ALLOCATED
PFS (3:1) = 0x60 MIXED_EXT ALLOCATED 0_PCT_FULL DIFF (3:6) = CHANGED
ML (3:7) = NOT MIN_LOGGED
因此,DBCC頁確認沒有什麼在頁面3:13。 有我的問題,爲什麼RID鎖存在於文件3:13,而什麼也沒有存在?
或者,問題也可以這樣:**爲什麼SQL Server在一個完全空的分區上分配頁面?** – chenwq
Can你也發佈你的分區功能了嗎? – JNK
@JNK:'CREATE PARTITION FUNCTION PFUNC(INT) 作爲值的左值(1,10000,20000); GO' – chenwq