【问题标题】:INSERT Parallel DML with column list使用列列表插入并行 DML
【发布时间】:2015-01-12 14:28:12
【问题描述】:

首先,我使用的是 11gR2

SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production

我正在尝试使用 PARALLEL DML 并行化一个非常大的 INSERT 语句,它会批量加载数百万行。为此,我通过ALTER SESSION ENABLE PARALLEL DML 启用并行 DML。我的插入看起来像这样-

INSERT INTO TAB_NEW (COL1, COL2, COL3, COL4, ...)  --32 columns                
 SELECT COL1,
        COL2,
        COL3,
        ....
        ....  --32 columns selected
   FROM TAB_A a, TAB_B b,...
   WHERE ....; --A bunch of joins here

我正在尝试语句级并行 DML,就像这样-

尝试 1-

INSERT /*+ PARALLEL(16) */ TAB_NEW (COL1, COL2, COL3, COL4, ...)  --32 columns
 SELECT COL1,
        COL2,
        COL3,
        ....
        ....  --32 columns selected
   FROM TAB_A a, TAB_B b,...
   WHERE ....; --A bunch of joins here

但是,上述不会并行运行。下面那个是-

尝试 2-

INSERT /*+ PARALLEL(16) */ TAB_NEW (COL1, COL2, COL3, COL4, ...)  --32 columns
 SELECT /*+ PARALLEL(16) */
        COL1,
        COL2,
        COL3,
        ....
        ....  --32 columns selected
   FROM TAB_A a, TAB_B b,...
   WHERE ....; --A bunch of joins here

尝试 3-

INSERT /*+ PARALLEL(16) */  INTO TAB_NEW
 SELECT COL1,
        COL2,
        COL3,
        ....
        ....  --32 columns selected
   FROM TAB_A a, TAB_B b,...
   WHERE ....; --A bunch of joins here

这是由于尝试 1 中 INSERT 语句中的列列表导致的吗?

【问题讨论】:

    标签: sql oracle performance oracle11g dml


    【解决方案1】:

    这适用于下面的简单示例,适用于 11.2.0.3(EE,64 位,Solaris)和 12.1.0.1(EE,64 位,Windows)。

    这意味着您遇到了一个非常具体的错误,可能与您的对象、语句或环境的一些次要细节有关。你的下一步是 修改您的查询直到它与我的查询匹配的痛苦过程,寻找使其停止工作的微不足道的不同。

    示例表

    --drop table tab_new;
    --drop table tab_a;
    --drop table tab_b;
    --drop table tab_c;
    
    create table tab_new(col01 number,col02 number,col03 number,col04 number,col05 number,col06 number,col07 number,col08 number,col09 number,col10 number,col11 number,col12 number,col13 number,col14 number,col15 number,col16 number,col17 number,col18 number,col19 number,col20 number,col21 number,col22 number,col23 number,col24 number,col25 number,col26 number,col27 number,col28 number,col29 number,col30 number,col31 number,col32 number) nologging;
    create table tab_a  (col01 number,col02 number,col03 number,col04 number,col05 number,col06 number,col07 number,col08 number,col09 number,col10 number,col11 number,col12 number,col13 number,col14 number,col15 number,col16 number,col17 number,col18 number,col19 number,col20 number,col21 number,col22 number,col23 number,col24 number,col25 number,col26 number,col27 number,col28 number,col29 number,col30 number,col31 number,col32 number) nologging;
    create table tab_b  (col01 number,col02 number,col03 number,col04 number,col05 number,col06 number,col07 number,col08 number,col09 number,col10 number,col11 number,col12 number,col13 number,col14 number,col15 number,col16 number,col17 number,col18 number,col19 number,col20 number,col21 number,col22 number,col23 number,col24 number,col25 number,col26 number,col27 number,col28 number,col29 number,col30 number,col31 number,col32 number) nologging;
    create table tab_c  (col01 number,col02 number,col03 number,col04 number,col05 number,col06 number,col07 number,col08 number,col09 number,col10 number,col11 number,col12 number,col13 number,col14 number,col15 number,col16 number,col17 number,col18 number,col19 number,col20 number,col21 number,col22 number,col23 number,col24 number,col25 number,col26 number,col27 number,col28 number,col29 number,col30 number,col31 number,col32 number) nologging;
    

    声明

    rollback;
    alter session enable parallel dml;
    explain plan for
    INSERT /*+ PARALLEL(16) */ INTO TAB_NEW (col01,col02,col03,col04,col05,col06,col07,col08,col09,col10,col11,col12,col13,col14,col15,col16,col17,col18,col19,col20,col21,col22,col23,col24,col25,col26,col27,col28,col29,col30,col31,col32)
    SELECT a.col01,a.col02,a.col03,a.col04,a.col05,a.col06,a.col07,a.col08,a.col09,a.col10,a.col11,a.col12,a.col13,a.col14,a.col15,a.col16,a.col17,a.col18,a.col19,a.col20,a.col21,a.col22,a.col23,a.col24,a.col25,a.col26,a.col27,a.col28,a.col29,a.col30,a.col31,a.col32
      FROM TAB_A a, TAB_B b, TAB_C c
     WHERE a.col01 = b.col01
       AND b.col01 = c.col01;
    
    select * from table(dbms_xplan.display(format => 'basic'));
    

    说明计划

    LOAD AS SELECT 操作及其在PX 操作下方的位置意味着数据是并行插入的。

    Plan hash value: 1632580283
    
    -------------------------------------------------------
    | Id  | Operation                          | Name     |
    -------------------------------------------------------
    |   0 | INSERT STATEMENT                   |          |
    |   1 |  PX COORDINATOR                    |          |
    |   2 |   PX SEND QC (RANDOM)              | :TQ10003 |
    |   3 |    LOAD AS SELECT                  | TAB_NEW  |
    |   4 |     OPTIMIZER STATISTICS GATHERING |          |
    |   5 |      HASH JOIN                     |          |
    |   6 |       HASH JOIN                    |          |
    |   7 |        PX RECEIVE                  |          |
    |   8 |         PX SEND HASH               | :TQ10000 |
    |   9 |          PX BLOCK ITERATOR         |          |
    |  10 |           TABLE ACCESS FULL        | TAB_A    |
    |  11 |        PX RECEIVE                  |          |
    |  12 |         PX SEND HASH               | :TQ10001 |
    |  13 |          PX BLOCK ITERATOR         |          |
    |  14 |           TABLE ACCESS FULL        | TAB_B    |
    |  15 |       PX RECEIVE                   |          |
    |  16 |        PX SEND HASH                | :TQ10002 |
    |  17 |         PX BLOCK ITERATOR          |          |
    |  18 |          TABLE ACCESS FULL         | TAB_C    |
    -------------------------------------------------------
    

    【讨论】:

    • 谢谢,我仍然无法使用 Attempt1 使其并行运行,尽管它与 Attempt2 一起工作,但问题是从属 (PX) 一直在等待主 (QC)真的很久了。不确定这是 IO 争用问题还是其他问题,但最后我们不再使用并行。 Parallel 适用于较小的数据集,但对于较大的数据集(超过 1000 万),该程序从未结束并运行了很长时间。
    【解决方案2】:

    所以并行 DML 不会在 PARALLEL 中执行查询的原因是因为表 TAB_NEW 上有一个启用的触发器。 PARALLEL DML 存在限制,并且由于触发器,对该表的任何并行 DML 尝试都只会串行运行。一旦触发器被禁用,INSERT 就会并行运行。

    可以在here找到完整的限制列表。

    【讨论】:

      猜你喜欢
      • 2014-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多