INDEX and PCTFREE

[复制链接]
查看11 | 回复4 | 2015-3-6 11:57:31 | 显示全部楼层 |阅读模式
  pctfree 用于插入排序在这个数据块中数据的 index。比如原来是 a ,b , e, f , g 保存在这个数据块中, 这时插入一个索引值为 c ,pctfree 就是为插入 c 准备的 。 如果留下的free 空间不够, 那么会出现index分裂的情况, 即 a ,b ,c 作为一个数据块被存储,而 e ,f ,g  作为另一个数据块被存储, 这也是OLTP系统需要定期重建INDEX的原因之一吧 。 

  索引分裂的规律不知道是不是平衡分裂规则。 即当有10个值,当第11个值需要插入到这个数据块,那么一个数据块会保留原来的 6 个值,新的一个数据块会存储另外5个数据值 ?
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
最初由 tolywang 发布
[B] 
  pctfree 用于插入排序在这个数据块中数据的 index。比如原来是 a ,b , e, f , g 保存在这个数据块中, 这时插入一个索引值为 c ,pctfree 就是为插入 c 准备的 。 如果留下的free 空间不够, 那么会出现index分裂的情况, 即 a ,b ,c 作为一个数据块被存储,而 e ,f ,g  作为另一个数据块被存储, 这也是OLTP系统需要定期重建INDEX的原因之一吧 。 

  索引分裂的规律不知道是不是平衡分裂规则。 即当有10个值,当第11个值需要插入到这个数据块,那么一个数据块会保留原来的 6 个值,新的一个数据块会存储另外5个数据值 ?  [/B]

大部分都是5:5,但也有1:9分
select * from v$sysstat where name like '%split%';
STATISTIC# NAME
CLASSVALUE
---------- ------------------------------------------------------ ---------- ----------
195 leaf node splits
12826501
196 leaf node 90-10 splits
128 8593
197 branch node splits
128 67
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
最初由 tolywang 发布
[B] 
  pctfree 用于插入排序在这个数据块中数据的 index。比如原来是 a ,b , e, f , g 保存在这个数据块中, 这时插入一个索引值为 c ,pctfree 就是为插入 c 准备的 。 如果留下的free 空间不够, 那么会出现index分裂的情况, 即 a ,b ,c 作为一个数据块被存储,而 e ,f ,g  作为另一个数据块被存储, 这也是OLTP系统需要定期重建INDEX的原因之一吧 。 

  索引分裂的规律不知道是不是平衡分裂规则。 即当有10个值,当第11个值需要插入到这个数据块,那么一个数据块会保留原来的 6 个值,新的一个数据块会存储另外5个数据值 ?  [/B]


这种分裂并不是需要rebuild index的原因之一。
所面的例子不能说什么“平衡分裂规则”。
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
最初由 logzgh 发布
[B]

这种分裂并不是需要rebuild index的原因之一。
所面的例子不能说什么“平衡分裂规则”。 [/B]


不好意思,自己起的名字



有什么高见写出来与大家分享一下吧 。 定期重建index 应该是和经常delete 数据有关系 。
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
How Indexes Grow
Indexes are always balanced and they grow from the bottom up. As rows are added, the leaf block fills. When the leaf block is full, the Oracle server splits it into two blocks and puts 50% of the block’s contents into the original leaf block and 50% into a new leaf block.
If another block is added to the index, this newly added block must be added to the directory entry in the parent branch block. If this parent branch block is full, the parent branch block is split in a similar way to the leaf block, with 50% of the existing contents being divided between the existing and new branch blocks. If required, this pattern is repeated until the place where the root block becomes a branch block and a new root block is added.
索引从下往上增长的时候总是会被平衡,当一个行增加时,leaf block被填充,当leaf block被填满后,oracle server 把该block一分为二并各放50%的数据。当有新的块被增加到索引时,这个新增的块必须在父的branch block中增加一条directory entry,当父的branch block被填满后,branch block就像leaf block一样,分成两个branch block并各有50%的数据,如果需要的话,这样模式会一直被重复,直到root block成为一个branch block并有一个新的root block被增加。
The more levels an index has, the less efficient it may be. Additionally, an index with many rows deleted might not be efficient. Typically, if 15% of the index data is deleted, then you should consider rebuilding the index.
如果索引的层次较多,那么它的效率就不那么好了,另外一个被删除很多列的索引也不会那么有效,如果一个索引的15%的数据被删除,那么就需要考虑重建索引了。重建索引比先删除索引再建立索引效率要高的多。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行