• 定位表和索引使用的Page


    数据存储的基本单元是Page,每个Page是8KB,数据文件(mdf和ndf)占用的硬盘空间,逻辑上按照PageNumber进行划分,也就是说,可以把数据文件看作是PageNumber 从0到n的连续Page。硬盘IO的基本单元是Page,这意味着,SQL Server对整个Page执行读写操作。一个Page只属于一个对象(表或index),不会出现一个Page属于两个对象的情况。

    每8个物理地址连续的Page构成一个区(Extent),区是空间分配和管理的基本单元,数据库把文件按照区(Extent)进行分配,也就是说,数据库文件的大小的区的倍数。

    一,非正式的DBCC IND命令

    DBCC IND是一个非正式的命令,用于定位到表或索引使用的Page,该命令的语法结构是:

    DBCC IND ( ['database name'|database id], table_name,index_id)

    参数index_id的有效值是:

    • 1:表示表的聚集索引
    • 非聚集索引的index_id
    • 0:代表堆(没有创建聚集索引的表)
    • -1:表示跟表相关的所有类型的Page(in row data, row over flow data, IAM, all indexes)
    • -2:只显示IAM类型的Page

    该命令返回的结果如下所示:

    结果集中各个字段的含义:

    • PageFID — the file ID of the page
    • PagePID — the page number in the file
    • IAMFID — the file ID of the IAM page that maps this page (this will be NULL for IAM pages themselves as they’re not self-referential)
    • IAMPID — the page number in the file of the IAM page that maps this page
    • ObjectID — the ID of the object this page is part of
    • IndexID — the ID of the index this page is part of
    • PartitionNumber — the partition number (as defined by the partitioning scheme for the index) of the partition this page is part of
    • PartitionID — the internal ID of the partition this page is part of
    • iam_chain_type — see IAM chains and allocation units in SQL Server 2005
    • PageType — the page type. Some common ones are:
      • 1 – data page  
      • 2 – index page 
      • 3 and 4 – text pages 
      • 8 – GAM page 
      • 9 – SGAM page 
      • 10 – IAM    page
      • 11 – PFS page
    • IndexLevel — what level the page is at in the index (if at all). Remember that index levels go from 0 at the leaf to N at the root page
    • NextPageFID and NextPagePID — the page ID of the next page in the doubly-linked list of pages at this level of the index
    • PrevPageFID and PrevPagePID — the page ID of the previous page in the doubly-linked list of pages at this   level of the index

     二,系统管理函数 sys.dm_db_database_page_allocations

    该DMF用于返回跟表或索引相关的所有Page,可以用于调查索引的结构(调查索引是如何创建的),研究损坏的页面(查看损坏页面的前一个Page和后一个Page),调查空间的利用情况(查看为表分配的Page类型)。
    sys.dm_db_database_page_allocations (@DatabaseId , @TableId , @IndexId , @PartionID , @Mode)

    对于@IndexId 和 @PartitionID,如果传递NULL值,表示返回所有索引或分区的信息。

    参数 @Mode 是定义返回数据的模式,有效值是:DETAILED 和 LIMITED。
    • LIMITED:   表示只返回Page的元数据
    • DETAILED :表示返回Page的详细数据
    该DMF为每一个Page返回一行,每一行都表示表或索引占用的一个Page:
    • partition_id:对应于分区的Partition Number
    • rowset_id:对应于分区的PartitionID
    • allocation_unit_id:分区单元(allocation unit)的ID
    • allocation_unit_type、allocation_unit_type_desc:分区单元的类型
    • extent_file_id:extent所在的file_id
    • extent_page_id:extent包含的page_id
    • allocated_page_iam_file_id:跟Page相关联的IAM Page所在的file_id
    • allocated_page_iam_page_id:跟Page相关联的IAM Page所在的page_id
    • allocated_page_file_id:Page的file_id
    • allocated_page_page_id:Page的page_id
    • is_allocated:指示该Page是否已分配
    • is_iam_page:指示该Page是否是IAM Page
    • is_mixed_page_allocation:指示该Page是否位于混合区
    • page_free_space_percent:该Page中空闲空间的占比
    • page_type、page_type_desc:该Page的类型
    • page_level:该Page在索引结构中的Level,叶子节点的Level是0。
    • next_page_file_id:下一个Page的file_id
    • next_page_page_id:下一个Page的page_id
    • previous_page_file_id:前一个Page的file_id
    • previous_page_page_id:前一个Page的page_id
    • is_page_compressed:指示该Page是否被压缩
    • has_ghost_records:指示该Page是否由幽灵记录(ghost record)
     
     
     
    参考文档:
     
  • 相关阅读:
    跳台阶问题
    最大连续子数组和
    寻找和为定值的若干个数
    MySQL- 用Navicat通过隧道连接到远程数据库
    CDH- 测试mr
    Sqoop- sqoop将mysql数据表导入到hive报错
    CDH- CDH大数据集群运维
    Spring- 异常org.xml.sax.SAXParseException; systemId: http://www.springframework.org/schema/context/; lineNumber: 1; columnNumber: 55; 在 publicId 和 systemId 之间需要有空格。
    Spring- 通过Xml的方式完成Bean的实例化
    Spring- Bean的命名
  • 原文地址:https://www.cnblogs.com/ljhdo/p/11969915.html
Copyright © 2020-2023  润新知