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

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博客 ” ,链接:http://blog.itpub.net/31476473/viewspace-2152750/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31476473/viewspace-2152750/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值