[20171225]查看并行执行计划注意的问题.txt

[20171225]查看并行执行计划注意的问题.txt

--//如果使用dbms_xplan.display_cursor查看并行执行计划注意一些问题,通过例子说明:

1.环境:

SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.测试:
SCOTT@book> create table t1 as select * from dba_objects ;
Table created.

SCOTT@book> alter session set statistics_level=all;
Session altered.

--//分析表略.

SCOTT@book> select /*+ parallel(t1,4) */ count(*) from t1;
  COUNT(*)
----------
     87016

SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6yhkc72j9mnnt, child number 0
-------------------------------------
select /*+ parallel(t1,4) */ count(*) from t1
Plan hash value: 3110199320
-----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers | Reads  |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      1 |        |    96 (100)|          |        |      |            |      1 |00:00:00.02 |       5 |      1 |
|   1 |  SORT AGGREGATE        |          |      1 |      1 |            |          |        |      |            |      1 |00:00:00.02 |       5 |      1 |
|   2 |   PX COORDINATOR       |          |      1 |        |            |          |        |      |            |      4 |00:00:00.02 |       5 |      1 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |          |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |      0 |
|   4 |     SORT AGGREGATE     |          |      0 |      1 |            |          |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |
|   5 |      PX BLOCK ITERATOR |          |      0 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWC |            |      0 |00:00:00.01 |       0 |      0 |
|*  6 |       TABLE ACCESS FULL| T1       |      0 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   6 - SEL$1 / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)

--//全表扫描,但是注意看A-Rows实际上根本不对.看到是0行.而E-Rows看到是正确的.

SCOTT@book> select * from table(dbms_xplan.display_cursor('6yhkc72j9mnnt',NULL,'ALLSTATS LAST PEEKED_BINDS cost partition -projection -outline parallel'));
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6yhkc72j9mnnt, child number 0
-------------------------------------
select /*+ parallel(t1,4) */ count(*) from t1
Plan hash value: 3110199320
---------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)|    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers |
---------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      1 |        |    96 (100)|        |      |            |      1 |00:00:00.11 |       5 |
|   1 |  SORT AGGREGATE        |          |      1 |      1 |            |        |      |            |      1 |00:00:00.11 |       5 |
|   2 |   PX COORDINATOR       |          |      1 |        |            |        |      |            |      4 |00:00:00.11 |       5 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |
|   4 |     SORT AGGREGATE     |          |      0 |      1 |            |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |
|   5 |      PX BLOCK ITERATOR |          |      0 |  87016 |    96   (0)|  Q1,00 | PCWC |            |      0 |00:00:00.01 |       0 |
|*  6 |       TABLE ACCESS FULL| T1       |      0 |  87016 |    96   (0)|  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |
---------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)
--//加入parallel提示也是一样.
--//链接:raajeshwaran.blogspot.com/2017/12/gatherplanstatistics-hint-for-parallel.html
In a parallel execution the last process to execute the cursor is the Query coordinator (QC), typically this QC will
execute a small number of operations in the execution plan, while the majority of the operations in the plan was done by
the parallel execution server process. So when we issue the DBMS_XPLAN.DISPLAY_CURSOR and ask for the last execution we
only get the information about the operations in the plan that the QC actually executed. In this case the only operation
that QC did was return the final result to our SQL*Plus session, which is why the line 0 and 1 and 2 have entries in the
A-rows column.

In order to see A-rows values for all the operations in the plan, we have to use the FORMAT value as ALLSTATS ALL, which
will show you the execution statistics for ALL executions of the cursor.

SCOTT@book> select * from table(dbms_xplan.display_cursor('6yhkc72j9mnnt',NULL,'ALLSTATS ALL PEEKED_BINDS cost partition -projection -outline parallel'));
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6yhkc72j9mnnt, child number 0
-------------------------------------
select /*+ parallel(t1,4) */ count(*) from t1
Plan hash value: 3110199320
-----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers | Reads  |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      2 |        |    96 (100)|          |        |      |            |      2 |00:00:00.13 |      10 |      1 |
|   1 |  SORT AGGREGATE        |          |      2 |      1 |            |          |        |      |            |      2 |00:00:00.13 |      10 |      1 |
|   2 |   PX COORDINATOR       |          |      2 |        |            |          |        |      |            |      8 |00:00:00.13 |      10 |      1 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |          |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |      0 |
|   4 |     SORT AGGREGATE     |          |      7 |      1 |            |          |  Q1,00 | PCWP |            |      7 |00:00:00.10 |    2265 |   2179 |
|   5 |      PX BLOCK ITERATOR |          |      8 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWC |            |    152K|00:00:00.09 |    2590 |   2486 |
|*  6 |       TABLE ACCESS FULL| T1       |    104 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWP |            |    174K|00:00:00.04 |    2590 |   2486 |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   6 - SEL$1 / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)

--//而这里看到的A-Rows实际上多次执行后的累积,并不能反应真实的情况.使用参数all的情况导致的结果.

--//加入提示,生成新的执行计划:
SCOTT@book> select /*+ parallel(t1,4) test */ count(*) from t1;
  COUNT(*)
----------
     87016

SCOTT@book> select * from table(dbms_xplan.display_cursor(NULL,NULL,'ALLSTATS ALL PEEKED_BINDS cost partition -projection -outline parallel'));
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6a3vj021614ft, child number 0
-------------------------------------
select /*+ parallel(t1,4) test */ count(*) from t1
Plan hash value: 3110199320
-----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers | Reads  |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      1 |        |    96 (100)|          |        |      |            |      1 |00:00:00.11 |       5 |      0 |
|   1 |  SORT AGGREGATE        |          |      1 |      1 |            |          |        |      |            |      1 |00:00:00.11 |       5 |      0 |
|   2 |   PX COORDINATOR       |          |      1 |        |            |          |        |      |            |      4 |00:00:00.11 |       5 |      0 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |          |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |      0 |
|   4 |     SORT AGGREGATE     |          |      4 |      1 |            |          |  Q1,00 | PCWP |            |      4 |00:00:00.06 |    1295 |   1243 |
|   5 |      PX BLOCK ITERATOR |          |      4 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWC |            |  87016 |00:00:00.05 |    1295 |   1243 |
|*  6 |       TABLE ACCESS FULL| T1       |     52 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWP |            |  87016 |00:00:00.02 |    1295 |   1243 |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   6 - SEL$1 / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)

--//这样看到的执行计划才是比较真实的数值.

--//我的dpc.sql脚本如下:
select * from table(dbms_xplan.display_cursor(NVL('&1',NULL),NULL,'ALL ALLSTATS LAST PEEKED_BINDS cost partition -projection -outline &2'));
--//我写的脚本也存在问题,不过最后的last掩盖前面all参数的设置.^_^.

3.总结:
--//在设置statistics_level=all;或者提示gather_plan_statistics时,看到的并行执行计划要特别注意.

时间: 2024-07-30 10:52:59

[20171225]查看并行执行计划注意的问题.txt的相关文章

[20120112]谨慎使用set autotrace traceonly查看执行计划.txt

自己经常在优化sql语句是经常使用set autotrace traceonly来优化sql语句.这样的好处是如果输出记录很多,可以不受干扰,直接查看执行计划以及执行计划的统计信息.但是在一些特殊情况要注意也许执行计划是不真实的. SQL> select * from v$version;BANNER--------------------------------------------------------------------------------Oracle Database 11g

使用Oracle脚本查看执行计划

声明:脚本来自<Pro Oracle SQL>一书,pln.sql 下面只是一个查看执行计划一种方法,就是通过加上备注表示唯一SQL语句: [oracle@maa3 ~]$ cat pln.sql SELECT xplan.* FROM     (   select max(sql_id) keep  (dense_rank last order by last_active_time) sql_id , max(child_number) keep  (dense_rank last ord

【显示执行计划】在普通用户下使用set autot 查看执行计划

在普通用户下查看执行计划 时 ,会遇到如下问题: SQL> CONN SCOTT/SCOTT 已连接. SQL> SET AUTOT TRACE搜集统计信息时出错 ORA-942 SP2-0611: 启用 STATISTICS 报告时出错 SQL> SET AUTOT ON 搜集统计信息时出错 ORA-942 SP2-0611: 启用 STATISTICS 报告时出错 SQL> SET AUTOT OFF SQL> SET AUTOT ON 搜集统计信息时出错 ORA-942

ORACLE数据库查看执行计划

基于ORACLE的应用系统很多性能问题,是由应用系统SQL性能低劣引起的,所以,SQL的性能优化很重要,分析与优化SQL的性能我们一般通过查看该SQL的执行计划,本文就如何看懂执行计划,以及如何通过分析执行计划对SQL进行优化做相应说明. 一.什么是执行计划(explain plan) 执行计划:一条查询语句在ORACLE中的执行过程或访问路径的描述. 二.如何查看执行计划 1: 在PL/SQL下按F5查看执行计划.第三方工具toad等. 很多人以为PL/SQL的执行计划只能看到基数.优化器.耗

ORACLE数据库查看执行计划的方法_oracle

一.什么是执行计划(explain plan) 执行计划:一条查询语句在ORACLE中的执行过程或访问路径的描述. 二.如何查看执行计划 1: 在PL/SQL下按F5查看执行计划.第三方工具toad等. 很多人以为PL/SQL的执行计划只能看到基数.优化器.耗费等基本信息,其实这个可以在PL/SQL工具里面设置的.可以看到很多其它信息,如下所示 2: 在SQL*PLUS(PL/SQL的命令窗口和SQL窗口均可)下执行下面步骤 复制代码 代码如下: SQL>EXPLAIN PLAN FOR SEL

[20161230]查看父游标中sql语句.txt

[20161230]查看父游标中sql语句.txt --上午巡检完,无聊,测试使用oradebug下查看sql语句在父游标中的内容.sql语句在执行第一次硬解析时生成父子游标,其中父游标chunk --中保存sql语句,测试通过oradebug下如何查看: 1.环境: SCOTT@book> select * from dept where deptno=10;     DEPTNO DNAME          LOC ---------- -------------- -----------

[20120307]查看v$session视图的定义.txt

[20120307]查看v$session视图的定义.txt 今天查看v$session的原始定义,查询GV$FIXED_VIEW_DEFINITION SQL> column VIEW_DEFINITION format a100 SQL> select * from GV$FIXED_VIEW_DEFINITION where view_name='GV$SESSION';    INST_ID VIEW_NAME                      VIEW_DEFINITION

Oracle查看执行计划的几种方法

Oracle查看执行计划的几种方法   一般来说,有如下几种获取执行计划的方式: 1.AUTOTRACE方式 AUTOTRACE是Oracle自带的客户端工具SQL*Plus的一个特性.启用AUTOTRACE后,SQL*Plus会自动收集执行过的SQL语句的执行计划.性能统计数据等,并在语句执行结束后显示在SQL*Plus中. DBA用户可以直接使用AUTOTRACE功能,但是如果用户没有DBA权限,那么需要在SYS用户下执行plustrce.sql脚本,自动创建PLUSTRACE角色,再把PL

[20121212]谨慎使用set autotrace traceonly查看执行计划[补充].txt

使用toad自带sqlmonitor,toad10以上版本现在叫sqltrace. 12:00:24 SQL> set autotrace traceonly ;12:01:23 SQL> select * from t2 where id=45; 10000 rows selected. Execution Plan----------------------------------------------------------Plan hash value: 1513984157 ---