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

news/2024/7/5 4:03:55

[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时,看到的并行执行计划要特别注意.

转载于:https://www.cnblogs.com/lfree/p/8116717.html


http://lihuaxi.xjx100.cn/news/248263.html

相关文章

一个技术总监的忠告:精通那么多技术,你为何还是受不到重用?

这篇文章我们继续说架构师大刘的故事&#xff1a; 老田升职了&#xff0c;年薪涨到了百万级别&#xff01;这时大刘在加班搞技术攻坚的时候&#xff0c;听别的同事聊了那么一嘴。大刘心里不是滋味儿。老田和大刘其实在这家公司之前就是同事了&#xff0c;老田能到这家公司&…

论文: Data-Driven Evolutionary Optimization: An Overview and Case Studies(2):五个实例分析

Blast Furnace Optimization ---高炉优化 涉及的问题&#xff1a; 在炼化的过程中是由大概100多种复杂的物质&#xff0c;怎么样找出合理的决策向量&#xff1f;最终确立了12个决策量子向量&#xff0c;8个目标&#xff0c;下一步就是优化约束条件&#xff0c;最后选择合适的算…

异常The Struts dispatcher cannot be found. This is

2019独角兽企业重金招聘Python工程师标准>>> 原因&#xff1a;struts2的过滤器映射路径写错 解决方案&#xff1a;在web.xml中配置struts2的过滤器如下&#xff1a; <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*&…

DevExpress v17.2新版亮点—WPF篇(四)

2019独角兽企业重金招聘Python工程师标准>>> DevExpress年终击穿底价&#xff0c;单套授权低至67折&#xff01;仅剩最后6天&#xff01;查看详情>>> 用户界面套包DevExpress v17.2终于正式发布&#xff0c;本站将以连载的形式为大家介绍各版本新增内容。本…

PyCharm使用笔记

1. 解释器配置 PyCharm并不知道本地Python解释器的位置。即使知道一般会放在默认位置/usr/bin/python&#xff0c;也不知道用户运行Python脚本时想使用解释器的哪个版本&#xff0c;例如Python 2.6或者Python 3.8&#xff0c;所以需要用户配置解释器。 寻找Python的安装位置 …

论文: Data-Driven Evolutionary Optimization : An Overview and Case Studies(3) 总结部分以及自己的想法

感悟&#xff1a; 一篇论文看完了&#xff0c;就觉得行业数据的而获取以及最初的一些对数据的操作&#xff0c;无论是预处理&#xff0c;数据挖掘&#xff0c;还是人为的制造一些数据进行辅助模型的优化&#xff0c;都有很重要的作用&#xff0c;而且也让我觉得这个EA其实再再应…

java使用uploadify上传文件

一、简介Uploadify是JQuery的一个上传插件&#xff0c;实现的效果非常不错&#xff0c;带进度显示&#xff1b;可以上传多个文件&#xff1b;详细的使用方法网上有很多&#xff0c;建议到官网参考&#xff0c;这里仅仅展示其使用的效果&#xff1b;官网&#xff1a;www.uploadi…

将ubuntu系统设置静态ip及ssh

2019独角兽企业重金招聘Python工程师标准>>> sudo vim /etc/network/interfaces 输入以下&#xff1a;auto lo iface lo inet loopback auto eno1 iface eno1 inet static address 192.168.1.197 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameserver 192.168…