手机版
你好,游客 登录 注册
背景:
阅读新闻

Oracle Database 中 B*Tree 索引内部维护

[日期:2012-12-28] 来源:Linux社区  作者:renfengjun [字体:大 中 小]

创建b*tree索引


~~~~~~~~~~~~~~~~~~~~~
When a B*tree index is created using the CREATE INDEX statement, the parameter PCTFREE can be specified. PCTFREE specifies the percentage of space to leave free for future updates and insertions to an index block. A value of 0 reserves no space for future inserts and updates. It allows the entire data area of the
block to be filled when the index is created. If PCTFREE is not specified, it defaults to 10. This value reserves 10% of each block for updates to existing key values, and inserts of new key values.


当一个btree 索引使用create index语句创建的时候,可以设置pctfree 参数。pctfree指定index block中为了未来更新或者新增索引数据时预留的存储空间百分比。如果设置为0,表示不会预留存储空间。它允许index block中的data area 所有的空间都填满 索引条目 。如果pctfree 没有被指定,那么它的默认值为10。它意味着每个index block中都会预留10%的存储空间,为未来的插入和更新预留。

Thus PCTFREE is only relevant at initial index creation. It causes optimal splitting of the B*-tree in preparation for subsequent growth. The idea is to do as much splitting as possible during initial creation and avoid having to pay the penalty later during insertion into the table. This is what a high PCTFREE setting on an index gives you. However, if your inserted keys are monotonically increasing (say a date/time field) a PCTFREE=0 is best. Only the rightmost index leaf block will be inserted into, so there's no point leaving room in the other leaf blocks at creation time.

所以pctfree只与创建索引的时候相关。它会影响b tree索引 分裂(因为后面的数据增长)的效率。比较好的办法是让索引分裂发生在索引创建阶段(预留空间多,自然需要更多的索引分裂操作)如果数据不会有增长pctfree设置为0是最好的。但是如果未来会插入大量数据,那么设置pctfree为非零那么就会有效的减少索引分裂的情况。

Following index creation, an index block can accommodate keys up to the full available data area including space for ITLs. Thus an index block will not require splitting until the available data area is fully used. The bottom line is PCTFREE is not looked at once you pass the index creation phase. One thing to remember is that each row in the index has only one correct block it can live in, based on the key value.

索引创建,可以填满它的data area (包括itl)。所以在索引块被填满之前,是不需要分裂的。每一行在 索引中,只在一个block上,基于它的 index key column value 。

Inserting an index entry after index creation

索引创建后插入一条 索引条目

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
After index creation, a new table row will create a new index entry. This entry is inserted into the appropriate index leaf block based on the index key values until the leaf block is full. If on insert the index leaf block is full, then an index block split will occur putting half of the index entries into each new index leaf block. Within an index data block, space is reserved for the index block header. The rest of the block is available for index keys.

在索引创建之后,一个新的行插入到表中,会创建一个新的索引条目。这个条目插入到相关的索引叶块中。如果插入的索引叶块已经满了,那么索引块会发生分裂,将其一半的索引条目 放到新的索引叶块中。在索引数据块内部,空间只为索引块头保留。剩下的block space 都可以用来插入索引数据。

Where an index key value has multiple entries, these entries are made into the leaf block in ROWID order. So all the blocks for the index key value are scanned in turn until an entry is found with a greater ROWID than the new row, and the row is inserted into that block (which may cause extra block splitting).

当一个索引键值拥有多个条目,这些条目内部按照rowid排列。所以拥有相同index key value的block都会被按照顺序被扫描,直到找到了一个大于新行的rowid。


The reason for this is for queries such as:

SELECT some_columns FROM table WHERE COL_A = valueA and COL_B = valueB;


If COL_A and COL_B both have non-unique indexes, then because the entries in each index are stored in ROWID order, it makes it easy to find the ROWID's that occur in both indexes. Otherwise we would have to sort the ROWID's before we could find the ROWID's that occur in both indexes.

如上所示,如果谓词中的列都含有非唯一索引。那么因为每个索引条目中的数据都是按照rowid的顺序排列的。所以可以很简单进行查找操作。换句话说我们必须在使用之前先按照rowid 排序。(这个情况是基于索引数据插入的说明的)

Updating an index entry

linux
相关资讯       Oracle索引  Oracle Database 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款