Skip to content

Oracle在12.2版本使用IMPDP并行导入数据时未并行建索引的分析

使用IMPDP导入数据时,通常我们会设置并行,希望数据库在导入数据、创建索引等耗时间长的动作中能够使用并行技术来加快导入动作的执行速度;但是在12.2版本上,IMPDP已经设置了并行,但是在trace中发现索引创建始终使用串行,而不是并行。

SQL> conn test/test@PDB1
SQL> create table a(m number,n number) parallel 4;
SQL> create index a_ind on a(m) parallel 3;
SQL> !expdp test/test@PDB1 dumpfile=b.dmp directory=my_dir
SQL> !impdp test/test@PDB1 directory=my_dir dumpfile=b.dmp parallel=2 TRACE=480301

DW trace显示index创建使用的是parallel=1,而不是parallel=2!。

CDB2_dw00_6658.trc
=====================
PARSING IN CURSOR #140037561274968 len=170 dep=2 uid=79 oct=1 lid=79
tim=841576694 hv=1135291776 ad=’61d1c0b0′ sqlid=’apjngud1uqbc0′
CREATE TABLE “TEST”.”A” (“M” NUMBER, “N” NUMBER) SEGMENT CREATION DEFERRED
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE “USERS” PARALLEL 4
END OF STMT

=====================
PARSING IN CURSOR #140037558550112 len=114 dep=2 uid=79 oct=9 lid=79
tim=842113538 hv=68235534 ad=’6374e7a8′ sqlid=’0u96wjh212c8f’
CREATE INDEX “TEST”.”A_IND” ON “TEST”.”A” (“M”) PCTFREE 10 INITRANS 2
MAXTRANS 255 TABLESPACE “USERS” PARALLEL 1 <=======PARALLEL 1, even if parallel=3 was set during index creation phase
END OF STMT

但是在12.1.0.2却没有这个问题,该并行并行:

R1201_dw00_29326.trc :
=====================
PARSING IN CURSOR #140427279060200 len=115 dep=2 uid=111 oct=9 lid=111
tim=8385394705 hv=1693801083 ad=’77900cf8′ sqlid=’3t4ktqdkgaqmv’
CREATE INDEX “TEST”.”A_IND” ON “TEST”.”A” (“M”) PCTFREE 10 INITRANS 2
MAXTRANS 255 TABLESPACE “SYSTEM” PARALLEL 2 <========PARALLEL 2
END OF STMT

这是ORACLE bug,ORACLE开发的解释是,这是期待的行为,因为,“我们发现这样更快”!

BUG 26091146 – IMPDP CREATE INDEX WITH PARALLEL 1 IGNORING COMMAND LINE PARALLEL=2, Development explained that this is an expected behavior supplying the following explanation:

“General support for parallel import of most object type, including indexes, is a 12.2 feature, which led to study of parallel creation of individual indexes. What was found was that using parallel index creation was generally slower than non-parallel. That led to a decision to backport the change to not use parallel index creation.”

因为在12.2新feature的开发过程中,我们研究了一下impdp时的index的创建,发现“一般情况下”串行比并行建索引更快,所以我们决定把impdp时的索引都改成串行创建,并且在创建完成后,再使用’ALTER INDEX … PARALLEL n’ 设置索引的并行度,以实现查询时的并行效果。

所以,ORACLE开发不认为是BUG;因此在导入数据时,需要注意这个地方,如果时间紧急,要考虑其他方式的并行建索引(如IMPDP导入不建索引,导出建索引SQL文本并人工并行执行等方式灵活处理)。