`

Oracle index

 
阅读更多

索引:

1、一般索引:

create index index_name on table(col_name);

2 Oracle 分区索引详解

语法: Table Index

CREATE [UNIQUE|BITMAP] INDEX [schema.]index_name

ON [schema.]table_name [tbl_alias]

(col [ASC | DESC]) index_clause index_attribs

 

index_clauses:

分以下两种情况

 

1. Local Index

就是索引信息的存放位置依赖于父表的 Partition信息,换句话说创建这样的索引必须保证父表是 Partition

1.1 索引信息存放在父表的分区所在的表空间。但是仅可以创建在父表为 HashTable或者 composite分区表的。

LOCAL STORE IN (tablespace)

1.2 仅可以创建在父表为 HashTable或者 composite分区表的。并且指定的分区数目要与父表的分区数目要一致

LOCAL STORE IN (tablespace) (PARTITION [partition [LOGGING|NOLOGGING] [TABLESPACE {tablespace|DEFAULT}] [PCTFREE int] [PCTUSED int] [INITRANS int] [MAXTRANS int] [STORAGE storage_clause] [STORE IN {tablespace_name|DEFAULT] [SUBPARTITION [subpartition [TABLESPACE tablespace]]]])

 

1.3 索引信息存放在父表的分区所在的表空间,这种语法最简单,也是最常用的分区索引创建方式。

Local

1.4 并且指定的 Partition 数目要与父表的 Partition要一致

LOCAL (PARTITION [partition

[LOGGING|NOLOGGING]

[TABLESPACE {tablespace|DEFAULT}]

[PCTFREE int]

[PCTUSED int]

[INITRANS int]

[MAXTRANS int]

[STORAGE storage_clause]

[STORE IN {tablespace_name|DEFAULT]

[SUBPARTITION [subpartition [TABLESPACE tablespace]]]])

 

Global Index

索引信息的存放位置与父表的 Partition信息完全不相干。甚至父表是不是分区表都无所谓的。语法如下:

GLOBAL PARTITION BY RANGE (col_list)

( PARTITION partition VALUES LESS THAN (value_list)

[LOGGING|NOLOGGING]

[TABLESPACE {tablespace|DEFAULT}]

[PCTFREE int]

[PCTUSED int]

[INITRANS int]

[MAXTRANS int]

[STORAGE storage_clause] )

但是在这种情况下,如果父表是分区表,要删除父表的一个分区都必须要更新 Global Index ,否则索引信息不正确

ALTER TABLE TableName DROP PARTITION PartitionName Update Global Indexes

 

 

--查询索引

select object_name,object_type,tablespace_name,sum(value)

from v$segment_statistics

where statistic_name IN ('physical reads','physical write','logical reads')and object_type='INDEX'

group by object_name,object_type,tablespace_name

order by 4 desc

 

 

oracle的索引分为5种:唯一索引,组合索引,反向键索引,位图索引,基于函数的索引

创建索引的标准语法:

CREATE INDEX 索引名 ON 表名 (列名)

     TABLESPACE 表空间名;

创建唯一索引:

CREATE unique INDEX 索引名 ON 表名 (列名)

     TABLESPACE 表空间名;

创建组合索引:

CREATE INDEX 索引名 ON 表名 (列名1,列名2)

     TABLESPACE 表空间名;

创建反向键索引:

CREATE INDEX 索引名 ON 表名 (列名) reverse

     TABLESPACE 表空间名;

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics