SQLServer 表 索引 在页中的存储

select * from sys.objects a where a.object_id=OBJECT_ID('aaaa');


select * from sys.partitions b where b.object_id=OBJECT_ID('aaaa'); --index_id=1为聚集索引 index_id=0为堆表  index_id>1为非聚集索引


select * from sys.allocation_units c where c.container_id=72057594042187776; -- 分配单元页


select * from sys.system_internals_allocation_units d where d.container_id=72057594042187776; -- 具体分配单元页
--first_iam_page-->0x 50 00 00 00 01 00-->0x 0001 00000050-->0001=1(文件组编号) 0x00000050=80(页码)
--root_page-->     0x 59 00 00 00 01 00-->0x 0001 00000059-->0001=1(文件组编号) 0x00000059=89(页码)
--first_page-->    0x 78 50 00 00 01 00-->0x 0001 00005078-->0001=1(文件组编号) 0x00005078=20600(页码)
--由此查看出来的信息与 dbcc ind(zws,aaaa,1) 查看出来的信息一致



select * from sys.indexes a where a.object_id=OBJECT_ID('aaaa');    -- index_id=1为聚集索引 index_id=0为堆表  index_id>1为非聚集索引


select * from sys.dm_db_index_physical_stats(DB_ID('zws'),object_id('dbo.aaaa'),1,null,'detailed'); -- 查看B树层数。 


dbcc ind(zws,aaaa,1);    --查看索引的详细信息。


dbcc page('zws',1,89,3);  --由根节点开始,根据 childpageid 和 索引所在列a的值开始下一层的查找。


dbcc page('zws',1,18720,3); -- 中间层,根据 childpageid 和 索引所在列a的值开始下一层的查找。



dbcc traceon(3604);  --打开跟踪标记
Go
dbcc page('zws',1,20602,3);  --叶子节点 
-- 前一页:m_prevPage = (1:20602)              后一页:m_nextPage = (1:20604)  开始地址:Offset 0x4
--Record Type = PRIMARY_RECORD(主记录)   Record Type = INDEX_RECORD(索引记录)   Record Type = GHOST_DATA_RECORD(虚影,sqlserver数据库后台有一个进程会定期清除标记为虚影的数据)
go
dbcc traceoff(3604);  --关闭跟踪标记 
Go




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值