[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时,看到的并行执行计划要特别注意.
[20171225]查看并行执行计划注意的问题.txt的更多相关文章
- oracle查看执行计划以及使用场景
文档结构: oracle执行计划使用场景 环境: Centos 6.10 Oracle 18.3.0.0.0 c 11g默认启动了自动统计信息收集的任务,默认运行时间是周一到周五晚上10点和周6,周天 ...
- Mysql查看执行计划-explain
最近生产环境有一些查询较慢,需要优化,于是先进行业务确认查询条件是否可以优化,不行再进行sql优化,于是学习了下Mysql查看执行计划. 语法 explain <sql语句> 例如: e ...
- MySQL 使用explain查看执行计划
使用explain查看执行计划, 下面是针对这两条语句进行分析,其查询结果是一样的. EXPLAIN select n.id,n.title from info n inner join info_t ...
- T-SQL备忘(5):查看执行计划
先理解几个概念:表扫描.聚集索引扫描.聚集索引查找.索引扫描.书签查找. [查看执行计划] 在理解概念之前先得知道如何查看执行计划—Ctrl+L.如下图: 注:SQL Server的执行计划是从右向左 ...
- Oracle数据库查看执行计划
基于ORACLE的应用系统很多性能问题,是由应用系统SQL性能低劣引起的,所以,SQL的性能优化很重要,分析与优化SQL的性能我们一般通过查看该SQL的执行计划,本文就如何看懂执行计划,以及如何通过分 ...
- sqlserver授予用户查看执行计划的权限
sqlserver查看语句的执行计划是非常重要的,可以提高开发人员代码的质量.所以有必要授予开发人员对数据库查看执行计划的权限. 查看执行计划的权限属于数据库一级别的权限,具体例子如下 use ...
- Mysql查看执行计划
EXPLAIN(小写explain)显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句. EXPLAIN + sql语句可以查看mysql的执行 ...
- hive高阶1--sql和hive语句执行顺序、explain查看执行计划、group by生成MR
hive语句执行顺序 msyql语句执行顺序 代码写的顺序: select ... from... where.... group by... having... order by.. 或者 from ...
- [20190416]查看shared latch gets的变化.txt
[20190416]查看shared latch gets的变化.txt 1.环境:SYS@book> @ ver1PORT_STRING VERSION ...
随机推荐
- javascript中的LHS和RHS
最近在拜读<你不知道的javascript>,接触到一个比较陌生的概念,LHS查询和RHS查询. 简单的一句话来讲,当变量出现在赋值操作符的左侧时进行LHS查询,出现在右侧时进行RHS查询 ...
- Http请求-get和post的区别
GET和POST是HTTP请求的两种基本方法. 最直观的区别就是GET把参数包含在URL中,以?的方式来进行拼接,POST通过request body传递参数.并且GET请求在URL中传送的参数是有长 ...
- 深入浅出分析MySQL MyISAM与INNODB索引原理、优缺点分析
本文浅显的分析了MySQL索引的原理及针对主程面试的一些问题,对各种资料进行了分析总结,分享给大家,希望祝大家早上走上属于自己的"成金之路". 学习知识最好的方式是带着问题去研究所 ...
- kubernetes入门之获取私有仓库镜像
一般情况下,我们项目构建的镜像统一会推送至私有仓库,那么这里大家可以参考阿里云的私有仓库搭建教程.那么我们可以通过以下步骤拉取: 1.推送及拉取镜像 1.1. 登录阿里云Docker Registry ...
- Oracle 创建表并设置主键自增
创建数据库 CREATE TABLE STUDENT(ID NUMBER PRIMARY KEY, NAME VARCHAR(200) NOT NULL, SEX VARCHAR(200), CREA ...
- ASP.NET Core 中的 ORM 之 Dapper
目录 Dapper 简介 使用 Dapper 使用 Dapper Contrib 或其他扩展 引入工作单元 Unit of Work 源代码 参考 Dapper 简介 Dapper是.NET的一款轻量 ...
- 获取多个checkbox的选中值
我在这个div中添加了多个input. 拼接一下呢.最老的方法. jquery获取值: var strSel=""; $("[name='jbbm']:checked&q ...
- 金山wps面经
前言: 金山wps笔试是好久之前的了,忘记具体几号了.当时在华师参加的宣讲会,然后线下笔试通过了, 昨天(4月2号通知现场面试).今天是在华工酒店进行面试的,一二面一起进行的 一面: 1: 自我介绍 ...
- TopK
网易面试挂了,伤心. 一面面试官不是搞技术的,二面面试官搞ios,全程不问JVM,并发的知识,运气真差 而且手撸代码硬伤,没得编译 准备先在IDE敲一遍,在再纸上面写一遍. package com.q ...
- [POI2006] PRO-Professor Szu
Description \(n\) 个别墅以及一个主建筑楼,从每个别墅都有很多种不同方式走到主建筑楼,其中不同的定义是(每条边可以走多次,如果走边的顺序有一条不同即称两方式不同). 询问最多的不同方式 ...