Oracle索引并行度

一.Rebuild索引与并行度说明

在索引create和rebuild的时候,在CPU允许的情况下,我们可以使用parallel来加快操作的速度。但是这里有一个注意的问题,有关索引的并行度,这个对表对象同样值得注意。
对于OLTP类型的数据库,除非只用于做统计、报表类的表或索引,不建议对相关表、索引设置并行度。
在数据库有开启并行查询的情况下,在表或索引上存在默认并行度,将导致数据库优先采用全表或全索引扫描的执行计划,另外将生成多个并行子进程,对于OLTP类应用将反而降低相关SQL的执行效率。

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

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.

(2)PARALLEL: 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.

(3)PARALLEL 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结束之后还需要对索引的并行度进行一个修改操作。

posted @ 2022-09-22 22:35  JaxYoun  阅读(1169)  评论(0编辑  收藏  举报