(转)Index-Organized Tables

来源:互联网 发布:乐聘网络 编辑:程序博客网 时间:2024/06/15 17:29

 

 

(1) 在oracle中,当我们用下面的语句建一个表时:
create table emp
as
select object_id   empno,
       object_name ename,
       created     hiredate,
       owner       job
from all_objects
这是emp称为堆组织表。
然后为emp表加上主键:alter table emp add constraint emp_pk primary key(empno)
此时emp仍称为堆组织表。但是这些oracle会为emp表建立基于B+树的索引,不过只对empno这一列的数据进行索引,这点同sql server不一样,在sql server中,当为一个表建立主键,相当于对主键列进行索引,同时将非主键列的数据也带到了索引中。
(2) 在oracle 中,还有一类IOT(index organization table)表。例如:
CREATE TABLE iot_emp
( "EMPNO" NUMBER PRIMARY KEY,
"ENAME" VARCHAR2(30),
"HIREDATE" DATE,
"JOB" VARCHAR2(30)
)
organization index --指定表为IOT表
    IOT表是将表中的行按索引列的顺序组织,注意IOT表不会像sql server中的聚簇索引那样,会占一些空间,除此以前,IOT同SQL Server的簇索引是一样的,它们都是通过B+树来组织。
    IOT必须要有主键列,不然不能创建成IOT表。
    IOT表的rowid是逻辑上的,因为IOT表中的行的位置是在不断变化的(例如插入新的行,有可能带来其它行的位置移动)



PCTTHRESHOLD 在数据块中 超过此百分比部分将存储到overflow指定存储空间
OVERFLOW 指定的超过pctthreshold部分的存储空间
INCLUDING 指定列后的数据将存储到overflow data segment;

SQL> create table test(empno number(4) primary key,
2 ename varchar2(10),job varchar2(9),
3 deptno number(2))
4 organization index
5 pctthreshold 20
6 including ename
7 overflow tablespace example;
Table created.
SQL> select index_name, index_type
2 from user_indexes
3 where table_name='TEST';
INDEX_NAME INDEX_TYPE
------------------------------ ---------------------------
SYS_IOT_TOP_30429 IOT - TOP
SQL> alter table test initrans 3 overflow initrans 5;
Table altered.
SQL> alter table test pctthreshold 15 including job;
Table altered.
SQL> desc test;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
DEPTNO NUMBER(2)
SQL> insert into test
2 values(1002,'aaaa','dba',10);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
EMPNO ENAME JOB DEPTNO
---------- ---------- --------- ----------
1002 aaaa dba 10
SQL> alter table test move online;
Table altered.
SQL>

 

另:

--创建IOT表,没有建mapping table:
CREATE TABLE admin_docindex(
        token char(20),
        doc_id NUMBER,
        token_frequency NUMBER,
        token_offsets VARCHAR2(512),
        CONSTRAINT pk_admin_docindex PRIMARY KEY (token, doc_id))
    ORGANIZATION INDEX
    TABLESPACE ecic
    PCTTHRESHOLD 20
    OVERFLOW TABLESPACE ecic;

--创建 mapping table    (先)
alter table admin_docindex ORGANIZATION INDEX mapping table;
--创建bitmap index.        (后)
CREATE BITMAP INDEX bix_ad
ON admin_docindex(token_frequency);

原创粉丝点击