加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-12 15:28:32 所属栏目:百科 来源:网络整理
导读:一. Rebuild 索引 与 并行度 说明 在之前的Blog里整理了一些列有关索引相关的Blog,如下: Oracle 索引 详解 http://blog.csdn.net/tianlesoftware/article/details/5347098 如何加快建index 索引 的时间 http://www.jb51.cc/article/p-nceubjsy-bmn.html Or

一.Rebuild索引并行度说明

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

Oracle 索引 详解

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

如何加快建index 索引 的时间

http://www.52php.cn/article/p-nceubjsy-bmn.html

Oracle 索引扫描的五种类型

http://www.52php.cn/article/p-radivjsk-bmn.html

Oracle 索引的维护

http://www.52php.cn/article/p-zswedmsb-bmn.html

Oracle alterindex rebuild 与ORA-08104 说明

http://www.52php.cn/article/p-ablgouji-bmn.html

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

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

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

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

Theparallel_clauseletsyou parallelize creation of the table and set the default degree of parallelismfor queries and the DMLINSERT,UPDATE,DELETE,andMERGEafter table creation.

(1)NOPARALLELSpecifyNOPARALLELforserial execution.This is the default,即并行度为1.

2PARALLELSpecifyPARALLELifyou want Oracle to select a degree of parallelism equal to the number of CPUsavailable on all participating instances times the value ofthePARALLEL_THREADS_PER_CPUinitialization parameter.

3PARALLELintegerSpecificationofintegerindicates thedegree 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 specifyinteger.

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;

BANNER

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

Oracle Database 11g Enterprise EditionRelease 11.2.0.1.0 - 64bit Production

--查看并行参数:

SQL> show parameter parallel_max_servers

NAME TYPE VALUE

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

parallel_max_servers integer 20

SQL> show parameter PARALLEL_THREADS_PER_CPU

parallel_threads_per_cpu integer 2

--测试表Dave信息:

SQL> select count(*) from dave;

COUNT(*)

----------

333798

SQL> col segment_name for a15

SQL> l

1*select segment_name,bytes/1024/1024||'M' as "size" from dba_segmentswhere segment_name='DAVE' and owner='SYS'

SQL> /

SEGMENT_NAME size

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

DAVE 38M

--使用默认值创建索引:

SQL> create index idx_dave_id on dave(object_id) ;

Index created.

SQL>

--查看默认值:

SQL> select degree from dba_indexes where index_name='IDX_DAVE_ID';

DEGREE

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

1

--这里默认为noparallel,即为1.

--使用并行度为4,对索引进行rebuild

SQL> ater index idx_dave_id rebuildparallel 4;

Index altered.

--在次查看索引的并行度:

SQL>select degree from dba_indexes where index_name='IDX_DAVE_ID';

4

注意:

这里变成了4,也就是说启用了索引自己的并行,这样在我们使用索引时会影响执行计划,也会消耗很多的资源。所以,我们需要对这个并行度进行修改,改成noparallel。

--修改并行度为noparallel

SQL> alter index idx_dave_id noparallel;

--查看并行度:

这里又变成了1.

使用并行来处理时,我们可以通过v$px_session来查看相关的等待事件:

SQL> select a.sql_id,a.event,count(*)from v$session a,v$px_session b where a.sid=b.sid group by a.sql_id,a.event;

关于并行的更多测试参考:

OracleParallel Execution(并行执行)

http://www.52php.cn/article/p-nsodrjgj-bmn.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读