(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);