zoukankan      html  css  js  c++  java
  • oracle 索引扫描类型的分类与构造

    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';

  • 相关阅读:
    关注底层:IL部分
    腾讯与敏捷开发(zz)
    关于腾讯敏捷框架TAPD (ZZ)
    最新苹果官方iphone sdk 与 xcode 下载网址汇总
    松山湖之行
    [zz]在C#程序中实现插件架构
    华为与敏捷(zz)
    OK6410 tftp下载内核、文件系统以及nand flash地址相关整理、总结
    T400换风扇解决开机fan error问题
    校园故事一个非典型工科男的电子设计之路(整理版)
  • 原文地址:https://www.cnblogs.com/ss-33/p/9077479.html
Copyright © 2011-2022 走看看