Constraints 约束操作不能并行 validate耗时几个小时

GOAL

NOTE: In the images and/or the document content below, the user information and environment data used represents fictitious data from the Oracle sample or bulit-in schema(s), Public Documentation delivered with an Oracle database product or other training material.  Any similarity to actual environments, actual persons, living or dead, is purely coincidental and not intended in any manner.

You want to create the PRIMARY KEY constraint while specifying the name and storage clause for the underlying INDEX in PARALLEL. You used the following compound statement:

SQL> ALTER SESSION ENABLE PARALLEL DDL;
SQL> ALTER TABLE emp ADD CONSTRAINT P_EMP PRIMARY KEY (empno)
USING INDEX (CREATE UNIQUE INDEX I_EMP ON
emp (empno) PARALLEL) ;
SQL> ALTER SESSION DISABLE PARALLEL DDL;

and you find that the execution time takes long time, while creating the index in parallel alone and enabling the constraint only takes much less time.
SQL> ALTER SESSION ENABLE PARALLEL DDL;
SQL> CREATE UNIQUE INDEX I_EMP ON  emp(empno) PARALLEL;

SQL> ALTER TABLE emp ADD CONSTRAINT P_EMP PRIMARY KEY (empno) USING INDEX I_EMP;
SQL> ALTER SESSION DISABLE PARALLEL DDL;

You want to know why this takes place.

Can We Enable or Modify Constraints Using Parallelism?

SOLUTION
 

Enabling or disabling or modifying the constraints cannot be run in parallelism.
As per Oracle Documentation, only the following DDL operations are supported in Parallelism.

The parallel DDL statements for non-partitioned tables and indexes are:


CREATE INDEX
CREATE TABLE AS SELECT
ALTER TABLE MOVE
ALTER INDEX REBUILD

The parallel DDL statements for partitioned tables and indexes are:


CREATE INDEX
CREATE TABLE AS SELECT
ALTER TABLE {MOVE|SPLIT|COALESCE} PARTITION
ALTER INDEX {REBUILD|SPLIT} PARTITION

Since 19.16.0.0.220719 applied, parallel DML is disabled with following message shown in Execution plan note.

"PDML disabled because parent referential constraints are present"

(delete statement and update statements if it modifies a column referenced in a foreign key constraint) disabled because parent

referential constraints are present but not before

Prior to 19.16.0.0.220719 PDML was working as expected.
 

CHANGES

 Patch level 19.16.0.0.220719 applied.

CAUSE

 New restriction is introduced by fix for Bug 32078078 

parallel PDML is disabled on referential integrity tables if the operation
modifies a primary or foreign key column

SOLUTION

Run the dml serially 

or

disable the FK constraint before parallel dml,  then enable when complete.

Parallel DML (PDML) must be explicitly enabled in order for DML to be considered for parallel execution.  In RDBMS versions lower than 12c, you could accomplish this only at the session level by using an ALTER SESSION statement. Assuming restrictions on parallel DML do not apply to your situation, once the session is altered, all further statements in the session will be candidates for execution of DML in parallel.

ALTER SESSION ENABLE PARALLEL DML;
<execute DML statement> 

SOLUTION

NOTE: In the images and/or the document content below, the user information and data used represents fictitious
data from the Oracle sample schema(s) or Public Documentation delivered with an Oracle database product.  
Any similarity to actual persons, living or dead, is purely coincidental and not intended in any manner.

New Hint in 12c: ENABLE_PARALLEL_DML

Starting in 12c, there is a new hint that will let you enable PDML at the statement level: ENABLE_PARALLEL_DML

/*+ enable_parallel_dml parallel(x) */  -- (x) is optional, where x is the requested degree of parallelism

Example 1: PDML is disabled

In this example, the select will run in parallel, but the load will be done serially because PDML is not explicitly enabled.  In 12c, the explain plan will include the reason that PDML was not considered.

insert /*+ parallel */ into t1 select * from t1_staging;

Execution Plan

----------------------------------------------------------
| Id | Operation                          | Name         | 
----------------------------------------------------------
| 0 | INSERT STATEMENT                    |              |
| 1 |  LOAD TABLE CONVENTIONAL            | T1           | <---- LOAD is not under a PX COORDINATOR, so PDML is disabled
| 2 |   PX COORDINATOR                    |              |
| 3 |    PX SEND QC (RANDOM)              | :TQ10000     |
| 4 |     PX BLOCK ITERATOR               |              |
| 5 |      TABLE ACCESS FULL              | <TABLE1>     |
----------------------------------------------------------------------

Note
-----
- dynamic statistics used: dynamic sampling (level=2)
- automatic DOP: Computed Degree of Parallelism is 2
- PDML is disabled in current session   <------

 

Example 2: PDML is enabled

In this example, we see both the select and load are done in parallel.

insert /*+ parallel(8) enable_parallel_dml */ into t1 select * from t1_staging;

----------------------------------------------------------
| Id | Operation                         | Name          | 
----------------------------------------------------------
| 0 | INSERT STATEMENT                   |               |
| 1 |  PX COORDINATOR                    |               |
| 2 |   PX SEND QC (RANDOM)              | :TQ10000      |
| 3 |    LOAD AS SELECT (HYBRID TSM/HWMB)| T1            | <---- LOAD is under a PX COORDINATOR, so PDML is enabled
| 4 |     OPTIMIZER STATISTICS GATHERING |               |
| 5 |      PX BLOCK ITERATOR             |               |
| 6 |       TABLE ACCESS FULL            | <TABLE1>      |
----------------------------------------------------------

Note
-----
- dynamic statistics used: dynamic sampling (level=2)
- - Degree of Parallelism is 8 because of hint

Notes:
1. The "enable_parallel_dml" hint may occur in any order within the /*+  */ delimiters.
2. The hint "disable_parallel_dml" is also new in 12c and disables PDML at the statement level. 
3. This hint is not yet included in the 12.1 documentation. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值