local 索引和global 索引记载

最近发觉自己有个一直很不好的习惯,上pub 看问题碰见自己不会的总是避开,而且喜欢逃避问题,虽然自己现在还没有碰见,但是不代表以后不会遇见。而且有些问题其实并不是去寻求绝对的对错,在思考的过程中真的要养成自己会思考,会用实际的测试来验证某个结论,会把以前的不懂联合起来,然后慢慢地把以前的知识也有更深的理解,成为一个会学习的学习者!

全局索引和本地索引:

全局索引以整个表的数据为对象创建索引,其实也就是脱离了表分区键值,只考虑索引键值,索引中的索引条目可能有相同的键值但是来自不同的分区。

创建一张分区表

Create table test15(

Id number,

Name varchar2(10))

Partitionby range(id)

(

partition p1 values less than(10),

Partition p2 values less than(20),

Partition p3 values less than(30),

Partition p4 values less than(maxvalue)

)

创建键值ID的全局索引

Create index index_global_test15

On test15(id)

Global partition by range(id)

这里的global索引可以分区也可以不分区,如果是global分区索引必须是前缀索引,也就是说必须把全局索引分区创建在分区键值上,就是创建在test15的分区表键值ID上。

Create index index_global_test15

On test15(id)

Global partition by range(id)

(

partition global_p1 values less than(10),

Partition p2 values less than(20),

Partition p3 values less than(30),

Partition p4 values less than(maxvalue)

)

本地索引的分区和其对应的表分区数量要一致,因此相应的表分区对应相应的索引分区。此时不需要指定索引分区范围。

Local索引

Create table test16(

Id number,

Name varchar2(10))

Partition by range(id)

(

partition p1 values less than(10),

Partition p2 values less than(20),

Partition p3 values less than(30)

)

Create index index_local_test16

On test16(id)

Local

(

Partition local1,

Partition local2,

Partition local3,

)

Or

Create inde index_local_test16 on test16(id) local;

Local索引下如果增加表分区,会自动创建一个同名的索引分区

Alter table test16 add partition p4 values less than(40);

本地分区索引oracle会自动对其维护,而全局索引增加表分区时则分区索引不会动态调整。

user_part_indexes描述的是分区索引的概要信息,dba_ind_partition是每个分区的索引信息。

那么何时使用local索引何时使用global索引了,在document中提到了

If the table partitioning column is a subset of the index keys, use a local index. If this is the case, you are finished. If this is not the case, continue to guideline 2.

If the index is unique, use a global index. If this is the case, you are finished. If this is not the case, continue to guideline 3.

If your priority is manageability, use a local index. If this is the case, you are finished. If this is not the case, continue to guideline 4.

If the application is an OLTP one and users need quick response times, use a global index. If the application is a DSS one and users are more interested in throughput, use a local index.

对于上述的第一种情况,如果表分区的键是索引的分区键或者一部分,很显然使用local索引,对于document别的三种情况持保留态度!

摘自http://tech.techweb.com.cn/thread-511193-1-1.html的一点总结,很受益!

使用LOCAL索引较为方便,而且维护代价较低,并且LOCAL索引是在分区的基础上去创建索引,类似于在一个子表内部去创建索引,这样开销主要是区分分区上,很规范的管理起来,在OLAP系统中应用很广泛;而相对的GLOBAL索引是全局类型的索引,根据实际情况可以调整分区的类别,而并非按照分区结构一一定义,相对维护代价较高一些,在OLTP环境用得相对较多,这里所谓OLTPOLAP也是相对的,不是特殊的项目,没有绝对的划分概念,在应用过程中依据实际情况而定,来提高整体的运行性能。) {6 L N3 U) Y3 S2 d/ f6 X0 S5 C

你必须很努力,才能看起来毫不费劲。

[@more@]

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

转载于:http://blog.itpub.net/25362835/viewspace-1056273/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值