查询不使用指定的并行度

时间:2017-09-29 09:01:26

标签: oracle performance parallel-processing oracle12c sql-execution-plan

在我的Oracle 12c数据库中,我希望在没有使用提示的情况下以并行度2执行语句。 注意:这是一个示例表,因此成本或时间没有任何改善。

具有并行性的执行计划1

PLAN_TABLE_OUTPUT
-----------------
Plan hash value: 2671887276

-----------------
| Id  | Operation           | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------
|   0 | SELECT STATEMENT        |             | 1 |   674 | 2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EVENT   | 1 |   674 | 2   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN     | EVENT_PK |    1 |   | 1   (0)| 00:00:01 |
--------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("EVENT_PK"='zjmtzhjrth')

Note
-----
   - automatic DOP: Computed Degree of Parallelism is 1 because of parallel threshold

具有提示/*+parallel(2) */的执行计划,其中DoP正常工作

PLAN_TABLE_OUTPUT
---------------
Plan hash value: 2851389777

----------------
| Id  | Operation             | Name        | Rows  | Bytes | Cost (%CPU)| Time |    TQ  |IN-OUT| PQ Distrib |
---------------
|   0 | SELECT STATEMENT          |         |     1 |   674 |     2   (0)| 00:00:01 |    |  |        |
|   1 |  PX COORDINATOR           |         |   |   |        |      |    |  |        |
|   2 |   PX SEND QC (RANDOM)         | :TQ10001        |     1 |   674 |     2   (0)| 00:00:01 |  Q1,01 | P->S | QC (RAND)  |
|   3 |    TABLE ACCESS BY INDEX ROWID    | EVENT   |     1 |   674 |     2   (0)| 00:00:01 |  Q1,01 | PCWP |        |
|   4 |     BUFFER SORT           |         |   |   |        |      |  Q1,01 | PCWC |        |
|   5 |      PX RECEIVE           |         |     1 |   |     1   (0)| 00:00:01 |  Q1,01 | PCWP |        |
|   6 |       PX SEND HASH (BLOCK ADDRESS)| :TQ10000        |     1 |   |     1   (0)| 00:00:01 |  Q1,00 | S->P | HASH (BLOCK|
|   7 |        PX SELECTOR        |         |   |   |        |      |  Q1,00 | SCWC |        |
|*  8 |     INDEX UNIQUE SCAN     | EVENT_PK |     1 |  |     1   (0)| 00:00:01 |  Q1,00 | SCWP |        |
--------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   8 - access("EVENT_PK"='zjmtzhjrth')

Note
-----
   - Degree of Parallelism is 2 because of hint

然后我执行了以下陈述

alter system set parallel_degree_policy=MANUAL;
alter table event parallel 2;

但是当我在没有提示的情况下执行语句时,它并没有使用并行性。它甚至没有给我关于执行计划中的DoP的注释。

PLAN_TABLE_OUTPUT
----------------
Plan hash value: 2671887276

-----------------
| Id  | Operation           | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT        |             | 1 |   674 | 2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EVENT   | 1 |   674 | 2   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN     | EVENT_PK |    1 |   | 1   (0)| 00:00:01 |
-------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("EVENT_PK"='zjmtzhjrth')

有谁可以告诉我为什么这不起作用?

关于评论中的问题:

PARALLEL_DEGREE_LIMIT=CPU

当我将PARALLEL_DEGREE_POLICY设置回AUTO时,它会再次给我注释:

Note
-----
   - automatic DOP: Computed Degree of Parallelism is 1 because of parallel threshold

我为测试发出的声明是

select * from event where event_pk = 'swdfklwe';

根据Cyrille的评论,我尝试了where子句中所选列和列的每个组合。当使用索引唯一扫描时,该声明只是不使用DoP 2。

select event_pk, result form event where event_pk = 'swdfklwe'
select event_pk form event where event_pk = 'swdfklwe'
select event_pk, result form event where event_pk = 'swdfklwe' and result = 0
select event_pk form event where event_pk = 'swdfklwe' and result = 0

2 个答案:

答案 0 :(得分:3)

并行执行用于加速遍历大量记录的查询。它将要搜索的总记录集分成较小的集合并同时处理多个集合。这样可以减少系统资源(主要是CPU)的消耗,缩短总响应时间。

您的表在搜索列上有唯一索引。因此,只能有一个匹配'EVENT_PK"='zjmtzhjrth'的记录。并行性无法使速度更快。

优化器选择了最有效的访问路径来检索一行。很高兴它有。

为什么不会

答案 1 :(得分:0)

它的工作方式与我一样:

SQL> create table t1 (id number);

Table created.

SQL> alter table t1 parallel 2;

Table altered.

SQL> explain plan for select * from t1;

Explained.

SQL> @?/rdbms/admin/utlxpls

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2494645258

---------------------------------------------------------------------------------
| Id  | Operation            | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |          |     1 |    13 |     2   (0)| 00:00:01 |
|   1 |  PX COORDINATOR      |          |       |       |            |          |
|   2 |   PX SEND QC (RANDOM)| :TQ10000 |     1 |    13 |     2   (0)| 00:00:01 |
|   3 |    PX BLOCK ITERATOR |          |     1 |    13 |     2   (0)| 00:00:01 |
|   4 |     TABLE ACCESS FULL| T1       |     1 |    13 |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------------
Note
-----
- dynamic statistics used: dynamic sampling (level=2)
- Degree of Parallelism is 2 because of table property

以下是我拥有的参数(所有默认值)

SQL> show parameter parallel

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
containers_parallel_degree           integer     65535
fast_start_parallel_rollback         string      LOW
parallel_adaptive_multi_user         boolean     FALSE
parallel_degree_limit                string      CPU
parallel_degree_policy               string      MANUAL
parallel_execution_message_size      integer     16384
parallel_force_local                 boolean     FALSE
parallel_instance_group              string
parallel_max_servers                 integer     40
parallel_min_percent                 integer     0
parallel_min_servers                 integer     4

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
parallel_min_time_threshold          string      AUTO
parallel_servers_target              integer     16
parallel_threads_per_cpu             integer     2
recovery_parallelism                 integer     0
SQL>