码迷,mamicode.com
首页 > 其他好文 > 详细

008_文件_对象_分区_单元_页

时间:2015-02-10 23:01:54      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

008_文件_对象_分区_单元_页

 

 

 

/*

allocation_unit_id       --分配单元的 ID。在数据库中是唯一的。

container_id         与分配单元关联的存储容器的 ID。

partition_id        分区的 ID。在数据库中是唯一的。

hobt_id    包含此分区的行的数据堆或 B 树的 ID。

 

Index_id: 1为聚集索引,2为非聚集索引

Partition_id, hobt_id:由于表存在聚集索引和非聚集索引,所以有两个分区标识

Allocation_unit_id: 聚集索引分区包含3个分配单元,非聚集索引分区包含1个分配单元

 

SELECT TOP 100 * FROM sys.system_internals_allocation_units --页与分区关系(包括IAM页的信息)

SELECT TOP 100 * FROM sys.allocation_units  --页与分区关系

SELECT TOP 100 * FROM  sys.partitions --分区与索引,表 关系

SELECT TOP 100 * FROM sys.filegroups  --文件组相关信息

SELECT TOP 100 * FROM sys.indexes

SELECT * FROM sys.objects

select * FROM sys.filegroups

*/

 

 

--查询页的相关属性

--版本一:

select

         a.data_space_id  文件id

         ,b.name   文件名称

         ,c.partition_id  分区id

         ,OBJECT_NAME(c.object_id)   表名称

         ,a.allocation_unit_id 分配单元id

         ,a.container_id 单元容器id

         ,a.type_desc  数据页类型

         ,a.type 页标识

         ,e.name  索引名称

         ,e.type_desc  索引类型

         ,e.type  索引类型标志

         ,a.total_pages   总页数

         ,a.used_pages   已使用页数

         ,a.data_pages  已使用数据页数

from

         sys.allocation_units a

inner join sys.filegroups b --文件组相关信息

         on a.data_space_id=b.data_space_id

inner join sys.partitions c

         on c.hobt_id=a.container_id --type为1或3

inner join sys.objects d

         on d.object_id=c.object_id

inner JOIN sys.indexes e

         on e.index_id=c.index_id AND e.object_id=c.object_id

WHERE a.type IN (1,3)

UNION ALL

select

         a.data_space_id  文件id

         ,b.name   文件名称

         ,c.partition_id  分区id

         ,OBJECT_NAME(c.object_id)   表名称

         ,a.allocation_unit_id 分配单元id

         ,a.container_id 单元容器id

         ,a.type_desc  数据页类型

         ,a.type 页标识

         ,e.name  索引名称

         ,e.type_desc  索引类型

         ,e.type  索引类型标志

         ,a.total_pages   总页数

         ,a.used_pages   已使用页数

         ,a.data_pages  已使用数据页数

from

         sys.allocation_units a

inner join sys.filegroups b --文件组相关信息

         on a.data_space_id=b.data_space_id

inner join sys.partitions c

         on c.partition_id=a.container_id --type为1或3

inner join sys.objects d

         on d.object_id=c.object_id

inner JOIN sys.indexes e

         on e.index_id=c.index_id AND e.object_id=c.object_id

WHERE a.type IN (2)

        

 

--版本二:

SELECT  so.name ,

        so.object_id ,

        sp.index_id ,

        sp.partition_id ,

        sp.hobt_id ,

        sa.container_id ,

        internals.total_pages ,

        internals.used_pages ,

        internals.data_pages ,

        first_page ,

        root_page ,

        first_iam_page

FROM    sys.objects so

        INNER JOIN sys.partitions sp ON so.object_id = sp.object_id

        INNER JOIN sys.allocation_units sa ON sa.container_id = sp.hobt_id

        INNER JOIN sys.system_internals_allocation_units internals ON internals.container_id = sa.container_id

WHERE   so.name NOT LIKE ‘sys%‘

 

 

 

 

 

 

 

        

008_文件_对象_分区_单元_页

标签:

原文地址:http://www.cnblogs.com/heibaitan/p/4284985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!