更新索引条目
~~~~~~~~~~~~~~~~~~~~~~~
There is really no concept of an UPDATE to an index. When a table row is updated, the old index key is deleted and a new key inserted (at the correct location in the B*tree).
更新就是在leaf block中删除老的index entry 并且在新的leaf block中插入新的index entry 。
Deleting an index entry
删除索引条目
~~~~~~~~~~~~~~~~~~~~~~~
When a index entry is to be deleted, the row is deleted from the index leaf block and the space within the index leaf block released to the block for further inserts with the appropriate key range. If a leaf block has even one entry it is still part of the tree, hence only entries that belong in it positionally can be accommodated. Once a leaf block is completely empty it is put on the free list, at which point it can be used to service an index block split.
当一个索引条目被删除,相关的数据会从索引叶块中删除,并且在 索引叶块中的空间 会被释放。如果一个叶块中拥有哪怕一条记录,那么它依然属于这个btree 索引。一旦一个叶块完全空白,那么它会被放置于free list中。
Index Fragmentation
~~~~~~~~~~~~~~~~~~~
To ascertain index fragmentation, the following SQL statement can be used:
ANALYZE INDEX &&index_name VALIDATE STRUCTURE;
col name heading 'Index Name' format a30
col del_lf_rows heading 'Deleted|Leaf Rows' format 99999999
col lf_rows_used heading 'Used|Leaf Rows' format 99999999
col ibadness heading '% Deleted|Leaf Rows' format 999.99999
SELECT name,
del_lf_rows,
lf_rows - del_lf_rows lf_rows_used,
to_char(del_lf_rows / (lf_rows)*100,'999.99999') ibadness
FROM index_stats
where name = upper('&&index_name');
undefine index_name
As a rule of thumb if 10-15% of the table data changes, then you should consider rebuilding the index.
索引碎片。10-15% 就需要考虑重建索引了。
B*Tree Balancing
B*Tree 平衡操作
~~~~~~~~~~~~~~~~
Oracle indexes are implemented as B* Trees which are always balanced.
oracle index btree 通常是平衡的。
In an Oracle B*tree the root of the tree is at level 0. In a very small B*tree the root block can also be a Leaf block.
在oracle btree索引中,tree 的根节点 在level 0 。在一个非常小的b tree索引中,root block 也可能是leaf block 。
In most cases, blocks on levels 0 through N-2 (where N is the height of the tree) are Branch blocks. Branch blocks do not contain data, they simply contain separators which are used to navigate from the root block to the the Leaf blocks.
大多数情况下,level 在 n-2 (n=heigh)之上的都是 branch block (分支块)。分支块不包含rowid。它们只包含分隔符。
All Leaf blocks are at level N-1 in Oracle B*trees. All data stored in a B*tree is stored in the Leaf blocks.
所有的叶块都在 level N-1 。所有的数据存储在leaf block (叶块)中。
The definition of a 'Balanced Tree' is that all the data is on the same level. Which means that the path to all data in the tree is the same length. Since all the data is stored in Leaf blocks and all the Leaf blocks are on the same level the B*trees are always balanced. There is no way to unbalance a B* tree.
“平衡树”的定义为,所有的数据在相同的level。它意味着 所有数据的访问路径,都是大致相同的。因为所有的数据存储在leaf block 并且所有的leaf block 在相同的level 上面,并且btree 通常是平衡的。没有办法去unbalance 一个 btree 。
Deletion of many rows in the B*Tree
