oracle 索引掃瞄型別的分類與構造

2022-06-22 12:09:10 字數 3819 閱讀 1507

1. index range scan

--請記住這個index range scan掃瞄方式

drop table t purge;

create table t as select * from dba_objects;

update t set object_id=rownum;

commit;

create  index idx_object_id on t(object_id);

set autotrace traceonly

set linesize 1000

exec dbms_stats.gather_table_stats(ownname => 'ljb',tabname => 't',estimate_percent => 10,method_opt=> 'for all indexed

columns',cascade=>true) ;

select * from t where object_id=8;

2. index unique scan

--請注意這個index unique scan掃瞄方式,在唯一索引情況下使用。

drop table t purge;

create table t as select * from dba_objects;

update t set object_id=rownum;

commit;

create unique index idx_object_id on t(object_id);

set autotrace traceonly

set linesize 1000

select * from t where object_id=8;

3. table access by user rowid

--請注意這個table access by user rowid掃瞄方式,直接根據rowid來訪問,最快的訪問方式!

drop table t purge;

create table t as select * from dba_objects;

update t set object_id=rownum;

commit;

--注意,這裡連索引都沒建!

--create  index idx_object_id on t(object_id);

set autotrace off

select rowid from t where object_id=8;

rowid

-----

aaazxiaagaaab07aah

set autotrace traceonly

set linesize 1000

select * from t where object_id=8 and rowid='aaazxiaagaaab07aah';

4. index full scan

--請記住這個index full scan掃瞄方式,並體會與index fast full scan的區別

drop table t purge;

create table t as select * from dba_objects;

update t set object_id=rownum;

commit;

alter table t modify object_id not null;

create  index idx_object_id on t(object_id);

set autotrace traceonly

set linesize 1000

select * from t  order by object_id;

5. index fast full scan

---請記住這個index fast full scan掃瞄方式,並體會與index full scan的區別

drop table t purge;

create table t as select * from dba_objects ;

update t set object_id=rownum;

commit;

alter table t modify object_id not null;

create  index idx_object_id on t(object_id);

set autotrace traceonly

set linesize 1000

select count(*) from t;

6. index full scan (minmax)

--請注意這個index full scan (min/max)掃瞄方式

drop table t purge;

create table t as select * from dba_objects;

update t set object_id=rownum;

commit;

create  index idx_object_id on t(object_id);

set autotrace traceonly

set linesize 1000

select max(object_id) from t;

7. index skip scan

--請記住這個index skip scan掃瞄方式

drop table t purge;

create table t as select * from dba_objects;

update t set object_type='table' ;

commit;

update t set object_type='view' where rownum<=30000;

commit;

create  index idx_type_id on t(object_type,object_id);

exec dbms_stats.gather_table_stats(ownname => 'ljb',tabname => 't',estimate_percent => 10,method_opt=> 'for all indexed

columns',cascade=>true) ;

set autotrace traceonly

set linesize 1000

select * from t where object_id=8;

8. table access by index rowid

--好好地體會前後兩個試驗,記住這個table access by index rowid

drop table t purge;

create table t as select * from dba_objects;

update t set object_id=rownum;

commit;

create  index idx_object_id on t(object_id);

set autotrace traceonly explain

set linesize 1000

select object_id from t where object_id=2 and object_type='table';

--在接下來的試驗中,你會看到,哇塞,table access by index rowid消失了。

create  index idx_id_type on t(object_id,object_type);

select object_id from t where object_id=2 and object_type='table';

Oracle 索引的分類

看到 itpub 論壇上的乙個帖子,對 oracle 的索引分類總結得言簡意賅,於是收藏過來。又最近一直看rac,就補充了一點反向索引的東西。邏輯上 single column 單列索引 concatenated 多列索引 unique 唯一索引 nonunique 非唯一索引 function b...

oracle索引分類

邏輯上 single column 單列索引 concatenated 多列索引 unique 唯一索引 nonunique 非唯一索引 function based函式索引 domain 域索引 物理上 partitioned 分割槽索引 nonpartitioned 非分割槽索引 b tree ...

oracle索引分類

b tree index,b樹索引 在建立索引時他是預設的索引型別,b樹索引可以使單一列 簡單 的索引,也可以是多個列 組合 復合 的索引。最多可以包括32列。適合 1,訪問表中佔很小比例的行,這樣就可以使用索引快速定位。2,根本不訪問表,所需查詢的資料全部在索引中,比如查詢的列就是索引,這樣直接訪...