oracle随笔-Index (B*树索引-1)
来源:互联网 发布:汤凤龙网络课 编辑:程序博客网 时间:2024/05/18 19:38
oracle B*Tree索引是oracle中最为常见的索引。在实际的生产系统中很多的索引就是B*Tree索引。B*Tree索引的创建有以下几个基本特点:
1.创建非唯一性索引
既然是索引肯定都是唯一定位的,但是在实际的生产中我们发现有些列并非是唯一的,但是一样可以建立索引,oracle是如何处理的呢,答案是rowid。oracle针对非唯一性索引首先按照索引键的顺序排序,然后再按照rowid升序排列追加到索引键后,使得当前的索引唯一。
2.创建唯一性索引
在一个或多个数据唯一性的列上建立索引时oracle会直接按照索引键值排序建立索引。
3.是一棵高度平衡的树,所有的叶子节点都在同一层。叶子节点以上的部分为分支节点。一颗典型的B*Tree树的数据结构如下所示
typedef struct Leaf{ void* element;//节点存储的信息 struct Leaf* Head;//当前节点的前一个节点 struct Leaf* Tail;//当前节点的后一个节点}* Leaf-pointer;typedef struct Node{ void* element;//节点存储的信息 struct Node** Nodelist;//节点指向的下一级索引块 Leaf-pointer* Leaflist//指向叶子节点块集}* Node-pointer;
注:以上的数据结构只用一种形式定义,并非真实的oracle内部实现。
可以看出叶子节点是一个双向链表,这样设计有一个很大的好处就是oracle查询的时候在某些情况下不用每次都从根节点依次访问。例如索引区间扫描,当定位到第一个节点后直接在叶子节点上向前或向后访问即可。
以下是本次oracle随笔Index(B*Tree)系列 分析B*Tree索引的初始代码,在后面的一系列的随笔中均需要使用它们。
create table T(optypenum int, recyear int,recnum int,recnumgather varchar2(20));alter table Tadd constraints t_pkprimary key (optypenum,recyear,recnum)using index;CREATE INDEX T_IDX ON T(RECNUM,OPTYPENUM,RECYEAR); --initial demo datadeclare ioptypenum int; irecyear int; irecnum int;begin ioptypenum := 1; irecyear := 0; irecnum := 0; for ioptypenum in 1 .. 10 loop for irecyear in 2011 .. 2013 loop for irecnum in 1 .. 10000 loop insert into t (optypenum, recyear, recnum, recnumgather) values (ioptypenum, irecyear, irecnum, null); end loop; end loop; end loop; commit; update t set recnumgather = 't' || to_char(optypenum) || to_char(recyear) || to_char(recnum); commit;end;
以上的代码执行成功后,我们就可以利用一下语句来查看索引信息了
select INDEX_NAME,BLEVEL,LEAF_BLOCKS,PCT_FREE,CLUSTERING_FACTOR,NUM_ROWS from user_indexes where index_name='T_IDX'
执行后结果如下所示:以上的结果有一个BLEVEL的字段改字段记录的是当前的B*Tree的高度。
- oracle随笔-Index (B*树索引-1)
- oracle随笔-Index (B*树索引-2)
- Oracle B树索引分析(B-Tree Index)
- b树index和bitmap索引
- oracle B树索引
- 【Oracle index】B*Tree索引之NULL统计技巧
- Oracle索引1--B树索引倒序扫描
- Oracle索引index
- Oracle索引index
- oracle 索引(index)
- oracle index 索引总结
- oracle 索引(index)
- Oracle - index (索引)
- oracle index(索引)
- Oracle索引(index)
- Oracle-index索引解读
- Oracle 索引 index
- oracle索引index
- android自定义TabWidget样式
- iptables-selinux设置
- CString用法整理
- python 实现图形界面exe
- Drawable和Bitmap的转换
- oracle随笔-Index (B*树索引-1)
- 机器学习理论与实战(十四)概率图模型02
- 像C++一样写JavaScript
- 每位开发人员都应铭记的10句编程谚语
- js常用函数
- 动态变量vs常量 动态存储vs静态存储
- Running your own CloudFoundry based on your IaaS. Part 1
- LA4670 AC自动机模版题
- Running your own CloudFoundry based on your IaaS. Part 2