码迷,mamicode.com
首页 > 数据库 > 详细

oracle 索引

时间:2016-05-31 23:47:15      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

★索引分类:

------------------------------

逻辑上=>
  Single column 单行索引
  Concatenated 多行索引
  Unique 唯一索引
  NonUnique 非唯一索引
  Function-based函数索引
  Domain 域索引
物理上=>
  Partitioned 分区索引
  NonPartitioned 非分区索引
  B-tree:
    Normal 正常型B树
    Rever Key 反转型B树
    Bitmap 位图索引


索引结构------------------------------------------
  B-tree:
    适合与大量的增、删、改(OLTP);
    不能用包含OR操作符的查询;
    适合高基数的列(唯一值多)
    典型的树状结构;
    每个结点都是数据块;
    大多都是物理上一层、两层或三层不定,逻辑上三层;
    叶子块数据是排序的,从左向右递增;
    在分支块和根块中放的是索引的范围;
  Bitmap:
    适合与决策支持系统;
    做UPDATE代价非常高;
    非常适合OR操作符的查询;
    基数比较少的时候才能建位图索引;
  树型结构:
    索引头
    开始ROWID,结束ROWID(先列出索引的最大范围)
    BITMAP
    每一个BIT对应着一个ROWID,它的值是1还是0,如果是1,表示着BIT对应的ROWID有值

 

★怎样建立最佳索引?

 -----------------------------------------------------------------------
1、明确地创建索引
  create index index_name on table_name(field_name)
  tablespace tablespace_name
  pctfree 5
  initrans 2
  maxtrans 255
  storage
  (
  minextents 1
  maxextents 16382
  pctincrease 0
  );
 
2、创建基于函数的索引
  常用与UPPER、LOWER、TO_CHAR(date)等函数分类上,例:
  create index idx_func on emp(UPPER(ename)) tablespace tablespace_name;
 
3、创建位图索引
  对基数较小,且基数相对稳定的列建立索引时,首先应该考虑位图索引,例:
  create bitmap index idx_bitm on class (classno) tablespace tablespace_name;
 
4、明确地创建唯一索引
  可以用create unique index语句来创建唯一索引,例:
  create unique index dept_unique_idx on dept(dept_no) tablespace idx_1;
 
5、创建与约束相关的索引
  可以用using index字句,为与unique和primary key约束相关的索引,例:
  alter table table_name
  add constraint PK_primary_keyname primary key(field_name)
  using index tablespace tablespace_name;
 
如何创建局部区索引?
  1)基础表必须是分区表
  2)分区数量与基础表相同
  3)每个索引分区的子分区数量与相应的基础表分区相同
  4)基础表的自分区中的行的索引项,被存储在该索引的相应的自分区中,例如
  create index TG_CDR04_SERV_ID_IDX on TG_CDR04(SERV_ID)
  Pctfree 5
  Tablespace TBS_AK01_IDX
  Storage(
  MaxExtents 32768
  PctIncrease 0
  FreeLists 1
  FreeList Groups 1
  )
  local
  /

oracle 索引

标签:

原文地址:http://www.cnblogs.com/big-xuzhou/p/5547899.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!