oracle 索引掃描類型的分類與構造

來源:互聯網
上載者:User

標籤:stat   comm   create   size   _id   trace   exe   aaa   order by   

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 索引掃描類型的分類與構造

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.