1
我已經劃分在一個MSSQLSERVER數據庫表。我可以檢查一個表中的數據如何分佈在每個文件組和分區上嗎?表磁盤空間使用情況的文件組,分區MSSQLSERVER
我已經劃分在一個MSSQLSERVER數據庫表。我可以檢查一個表中的數據如何分佈在每個文件組和分區上嗎?表磁盤空間使用情況的文件組,分區MSSQLSERVER
我發現這是一個很好的腳本:
SELECT
DB_NAME() AS 'DatabaseName'
,OBJECT_NAME(p.OBJECT_ID) AS 'TableName'
,p.index_id AS 'IndexId'
,CASE
WHEN p.index_id = 0 THEN 'HEAP'
ELSE i.name
END AS 'IndexName'
,p.partition_number AS 'PartitionNumber'
,prv_left.VALUE AS 'LowerBoundary'
,prv_right.VALUE AS 'UpperBoundary'
,CASE
WHEN fg.name IS NULL THEN ds.name
ELSE fg.name
END AS 'FileGroupName'
,CAST(p.used_page_count * 0.0078125 AS NUMERIC(18,2)) AS 'UsedPages_MB'
,CAST(p.in_row_data_page_count * 0.0078125 AS NUMERIC(18,2)) AS 'DataPages_MB'
,CAST(p.reserved_page_count * 0.0078125 AS NUMERIC(18,2)) AS 'ReservedPages_MB'
,CASE
WHEN p.index_id IN (0,1) THEN p.ROW_COUNT
ELSE 0
END AS 'RowCount'
,CASE
WHEN p.index_id IN (0,1) THEN 'data'
ELSE 'index'
END 'Type'
FROM sys.dm_db_partition_stats p
INNER JOIN sys.indexes i
ON i.OBJECT_ID = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.data_spaces ds
ON ds.data_space_id = i.data_space_id
LEFT OUTER JOIN sys.partition_schemes ps
ON ps.data_space_id = i.data_space_id
LEFT OUTER JOIN sys.destination_data_spaces dds
ON dds.partition_scheme_id = ps.data_space_id
AND dds.destination_id = p.partition_number
LEFT OUTER JOIN sys.filegroups fg
ON fg.data_space_id = dds.data_space_id
LEFT OUTER JOIN sys.partition_range_values prv_right
ON prv_right.function_id = ps.function_id
AND prv_right.boundary_id = p.partition_number
LEFT OUTER JOIN sys.partition_range_values prv_left
ON prv_left.function_id = ps.function_id
AND prv_left.boundary_id = p.partition_number - 1
WHERE
OBJECTPROPERTY(p.OBJECT_ID, 'ISMSSHipped') = 0
--AND p.index_id in (0,1)
這裏的數據列的快速解釋拉進,根據筆者:
默認情況下數據在MSSQL頁是8KB,就是這樣 我與此查詢作出假設。
Used_Pages: the number of pages actually used by the table including non-leaf B-tree pages and IAM pages. Reserved_Pages: is the number of pages being reserved in total for the object, whether used or not. Data_Pages: the number of pages being used excluding non-leaf B-tree pages.
這裏向BOL頁面的鏈接,介紹了這些: msdn.microsoft.com/en-us/library/ms187737.aspx
鏈接無效 – vesuvious