您的位置:首页 > 数据库 > Oracle

Oracle三种table: 堆表Heap Table、索引组织表IOT和聚簇表Cluster

2017-11-15 20:12 411 查看
常用数据库支持情况:

Oracle支持堆表,索引组织表,聚簇表Cluster;

PostgreSQL只支持堆表,不支持索引组织表;

Innodb只支持索引组织表;

MyISAM只支持堆表。

Oracle使用rowid数据类型存储行地址,rowid可以分成两种,分别适于不同的对象,

Physical rowids:存储ordinary table,clustered table,table partition and subpartition,indexe,index partition and subpartition;

Logical rowids :存储IOT的行地址

Heap table:无序的集合存储。表和主键索引分成两个segment。创建的主键索引叶结点存储ROWID。

插入和更新快,结果无序。

从成本上计算,CBO并不是因为回表动作才确定执行计划,而是Clustering Factor的影响。IOT一个突出优势就是直接消灭了Clustering Factor的成本因素。

http://blog.sina.com.cn/s/blog_4b12778b0101cgl9.html
http://blog.sina.com.cn/s/blog_4b12778b0101cglt.html

http://blog.csdn.net/dnnyyq/article/details/5195472
http://blog.csdn.net/lJean/article/details/51360398

IOT: 主键和表合成一个segment。数据是按主键有序的存储在B树索引结构中。叶结点存储了行记录。查询快,不回表,结果有序,插入和更新慢。

    create table t88(
       ID varchar2 ( 10 ),
       NAME varchar2 ( 20 ),
       constraint pk_id primary key ( ID )
      )
    organization index
      PCTTHRESHOLD 20
      overflow tablespace users
      INCLUDING name ;

注意两点:
    ● 创建IOT时,必须要设定主键,否则报错。
    ● 索引组织表实际上将所有数据都放入了索引中。

索引组织表的适用情况:适用于信息检索、空间和OLAP程序。
    1、 代码查找表。
    2、 经常通过主码访问的表。
    3、 构建自己的索引结构。
    4、 加强数据的共同定位,要数据按特定顺序物理存储。
    5、 经常用between…and…对主码或唯一码进行查询。数据物理上分类查询。如一张订单表,按日期装载数据,想查单个客户不同时期的订货和统计情况。

经常更新的表当然不适合IOT。 如果不是经常使用主键访问表,就不要使用IOT。

http://m.blog.itpub.net/17203031/viewspace-774405      聊聊Oracle聚簇Cluster

Cluster table:多个表合成一个segment存储,多个数据表按照连接键的顺序保存在一起。经常和另外一个数据表进行连接查询(Join)显示。

create cluster emp_dept (deptno number) size 600;

create table emp (empno number, empname varchar2(10), deptno number) cluster emp_dept(deptno);

create table dept (deptno number primary key, deptname varchar2(10)) cluster emp_dept(deptno);

create index idx_emp_dept on cluster emp_dept;

insert into dept select deptno, dname from scott.dept;

insert into emp select empno, ename, deptno from scott.emp;

drop cluster emp_dept including tables;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Database Oracle