日期:2014-05-16  浏览次数:20501 次

Oracle rebuild index 使用 parallel 时 与 并行度 的注意事项

 

 

一.Rebuild 索引 与 并行度 说明

在之前的Blog里整理了一些列有关索引相关的Blog,如下:

 

Oracle 索引 详解

http://blog.csdn.net/tianlesoftware/article/details/5347098

 

如何加快建index 索引 的时间

http://blog.csdn.net/tianlesoftware/article/details/5664019

 

Oracle 索引扫描的五种类型

http://blog.csdn.net/tianlesoftware/article/details/5852106

 

Oracle 索引的维护

http://blog.csdn.net/tianlesoftware/article/details/5680706

 

Oracle alterindex rebuild 与ORA-08104 说明

http://blog.csdn.net/tianlesoftware/article/details/6538928

 

在索引create 和rebuild的时候,在CPU 允许的情况下,我们可以使用parallel来加快操作的速度。但是这里有一个注意的问题,有关索引的并行度,这个对表同样要注意。

 

对于OLTP类型的数据库,除非只用于做统计、报表类的表或索引,建议不对相关表或索引调置并行度。在数据库有开启并行查询的情况下,在表或索引上存在默认并行度,将导致数据库优先采用全表或全索引扫描的执行计划,另外将生成多个并行子进程,对于OLTP类应用将反而降低相关SQL的执行效率。

 

       有关parallel,官网的说明如下:

http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_7002.htm#i2159323

 

The parallel_clause letsyou parallelize creation of the table and set the default degree of parallelismfor queries and the DML INSERT, UPDATE, DELETE,andMERGE after table creation.

 

(1)    NOPARALLEL Specify NOPARALLEL forserial execution. This is the default,即并行度为1.

 

2PARALLEL  Specify PARALLEL ifyou want Oracle to select a degree of parallelism equal to the number of CPUsavailable on all participating instances times the value ofthe PARALLEL_THREADS_PER_CPU initialization parameter.

 

3PARALLEL integer Specificationof integer indicates the degree of parallelism, which is thenumber of parallel threads used in the parallel operation. Each parallel threadmay use one or two parallel execution servers. Normally Oracle calculates the optimumdegree of parallelism, so it is not necessary for you to specify integer.

 

       Oracle在并行处理时,会启动多少个并行进程来同时执行任务,并行度越高, 并行进程越多,执行速度 会越快,默认是noparallel,如果我们设置并行度为default值,那么此时的并行度是:

服务器CPU数*每个CPU启用的线程数(PARALLEL_THREADS_PER_CPU)

 

       所以一般我们建议使用Noparallel,或者将并行度设置为1,而不是default。

 

       可以通过dba_tables 和 dba_indexes 视图的degree 字段来查看相关对象的并行度。

 

       要注意的就是在我们用并行来rebuild索引的时候,rebuild结束后,我们索引的并行度也会改成我们rebuild的并行度,所以在我们rebuild 结束之后还需要对索引的并行度进行一个修改操作。

 

 

二.示例

测试环境: win7 +oracle 11.2.0.1

 

SQL> select * from v$version where rownum=1;