ITPub博客

首页 > 数据库 > Oracle > 【学习】SQL基础-018-索引

【学习】SQL基础-018-索引

原创 Oracle 作者:Kevin_Weig 时间:2018-04-10 11:29:22 0 删除 编辑
1、概念
    是数据库对象,通过指针加速查询数据,减少磁盘IO
    类似书的目录
    自动使用和维护索引    --primary key 和unique列上自动创建

2、创建
    基本语法
         create index emp_ename_idx  on emp(ename);
    B树索引
        1)唯一索引,指键值不重复。SQL> create unique index empno_idx on emp1(empno);
        2)非唯一索引  SQL> create index empno_idx on emp1(empno);
        3)组合索引(Composite):基于两个或多个列的索引。 SQL> create index job_deptno_idx on emp1(job,deptno);
        4)反向键索引(Reverse):将字节倒置后组织键值。当使用序列产生主键索引时,可以防止叶节点出现热块现象。缺点是无法提供索引范围扫描。
            SQL> create index mgr_idx on emp1(mgr) reverse;
       5)函数索引(Function base):以索引列值的函数值为键值去组织索引  SQL> create index fun_idx on emp1(lower(ename));
       6)压缩(Compress):重复键值只存储一次,就是说重复的键值在叶块中就存一次,后跟所有与之匹配的 rowid 字符串。
             SQL> create index comp_idx on emp1(sal) compress;
       7)升序或降序( Ascending or descending):叶节点中的键值排列默认是升序的。
            SQL> create index deptno_job_idx on emp1(deptno desc, job asc);
    函数索引

3、重建、删除
    alter index ind_test_id rebuild online;
    drop index

4、不可用、不可见
    unusable 不可用
         alter index ind_test_id unusable;
         如需使用得重建:alter index ind_test_id rebuild;

    invisible 不可见
         alter index ind_test_id invisible;
        alter index ind_test_id visible;
         11g新特性,只对优化器不可见,但索引维护还是正常进行

5、索引监控(查看索引是否被使用)
     alter index pk_dept monitoring usage;
     select * from v$object_usage;
     alter index pk_dept nomonitoring usage;

    
6、注意事项
    

7、视图
    user_indexes
    user_ind_columns

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31476473/viewspace-2152750/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2017-07-17

  • 博文量
    43
  • 访问量
    15380