search
HomeDatabaseMysql Tutorial查看执行计划event 10046和tkprof

上篇文章提到了用set autotrace和dbms_xplan去查看执行计划,下面我们将重点看看event 10046和tkprof来查看执行计划。 1 设置10046 event SQL> alter session set events '10046 trace name context forever ,level 12'; Session altered. SQL> select sum(o

上篇文章提到了用set autotrace和dbms_xplan去查看执行计划,下面我们将重点看看event 10046和tkprof来查看执行计划。

1 设置10046 event
SQL> alter session set events '10046 trace name context forever ,level 12';

Session altered.

SQL> select sum(object_id),sum(data_object_id) from t01;

SUM(OBJECT_ID) SUM(DATA_OBJECT_ID)
-------------- -------------------
1283335921 97173652

SQL> alter session set events '10046 trace name context off';

Session altered.

10046 event的raw trace文件:
Dump file g:\oracle\product\10.2.0\admin\ora10g\udump\ora10g_ora_1352.trc
Thu May 22 22:22:16 2014
ORACLE V10.2.0.4.0 - 64bit Production vsnsta=0
vsnsql=14 vsnxtr=3
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Windows NT Version V6.1
CPU : 4 - type 8664, 2 Physical Cores
Process Affinity : 0x0000000000000000
Memory (Avail/Total): Ph:4370M/7889M, Ph+PgF:10433M/15777M
Instance name: ora10g

Redo thread mounted by this instance: 1

Oracle process number: 115

Windows thread id: 1352, image: ORACLE.EXE (SHAD)
。。。
*** 2014-05-22 22:22:35.371
=====================
PARSING IN CURSOR #11 len=50 dep=0 uid=58 oct=3 lid=58 tim=12339600047 hv=887579624 ad='5d666250'
select sum(object_id),sum(data_object_id) from t01
END OF STMT
PARSE #11:c=0,e=1484,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=12339600040
BINDS #11: --10046 trace中还会记录bind value,这里由于没有使用bind,所以下面没有列出
EXEC #11:c=0,e=385,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=12339602189
WAIT #11: nam='SQL*Net message to client' ela= 4 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=12339602537
FETCH #11:c=15601,e=15187,p=0,cr=693,cu=0,mis=0,r=1,dep=0,og=1,tim=12339618068
WAIT #11: nam='SQL*Net message from client' ela= 370 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=12339619256
FETCH #11:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=12339619716
WAIT #11: nam='SQL*Net message to client' ela= 3 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=12339620145
WAIT #11: nam='SQL*Net message from client' ela= 8040398 driver id=1111838976 #bytes=1 p3=0 obj#=-1 tim=12347660914
STAT #11 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=693 pr=0 pw=0 time=15180 us)'
STAT #11 id=2 cnt=50070 pid=1 pos=1 obj=51887 op='TABLE ACCESS FULL T01 (cr=693 pr=0 pw=0 time=84 us)'

下面小鱼将结合部分资料对这个10046 event进行解读:
PARSING IN CURSOR #11 len=50 dep=0 uid=58 oct=3 lid=58 tim=12339600047 hv=887579624 ad='5d666250'
先看上面的的parsing in cursor部分:
其中的parsing in cursor表示的游标编号,这里是11
Len表示的是被解析的sql语句长度
Dep表示的递归sql语句的深度
Uid是user_id,对应于dba_users的user_id
Oct表示oracle command type类型
Lid表示私有用户id
Tim表示时间戳
Hv表示的sql的hash_value
Ad表示的sql的address

BINDS #11: --10046 trace中还会记录bind value,这里由于没有使用bind,所以下面没有列出

再来看parse、exec和fetch部分:
PARSE #11:c=0,e=1484,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,tim=12339600040
EXEC #11:c=0,e=385,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,tim=12339602189
FETCH #11:c=15601,e=15187,p=0,cr=693,cu=0,mis=0,r=1,dep=0,og=1,tim=12339618068
FETCH #11:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,tim=12339619716
C表示消耗的cpu time
E表示消耗的事件
P表示物理读
Cr表示一致性读
Mis表示硬解析次数
R表示处理的行数
Dep表示递归sql的深度
Og optimizer goal表示优化器模式
Time表示时间戳

Stat部分:
STAT #11 id=1 cnt=1 pid=0 pos=1 obj=0 op='SORT AGGREGATE (cr=693 pr=0 pw=0 time=15180 us)'
STAT #11 id=2 cnt=50070 pid=1 pos=1 obj=51887 op='TABLE ACCESS FULL T01 (cr=693 pr=0 pw=0 time=84 us)'
Id表示执行计划id
Cnt表示cardinality
Pid表示行源号的父号
Pos执行计划中的位置
Obj表示的是对象的object_id
Op表示执行计划的中返回方式
Cr表示的一致性读取
Pr表示的物理读
Pw表示的物理写
Time表示消耗的时间,这里的us是微妙,1s=1000ms=1000*1000us

STAT包含了完整的执行计划,10046 event trace也能看见完整的执行计划,还能看见各个执行步骤消耗的步骤,比如一致性读、物理读写,消耗的时间,相比dbms_xplan、autotrace更加清晰和明了。

Level 12 10046 trace文件中还记录了一个比较重要的信息就是等待事件,分别记录了sql解析,执行和获取数据时各自的等待事件,比如上述这个sql语句还记录了sql语句执行的过程(解析-执行-获取数据)的伴随着sql*net message to client和sql*net message from client等待。

大家如果能直接看懂10046 event的trace更好,如果看不懂oracle也推出了tkprof用来简化原始的10046 event trace文件,使用办法也很简单。
C:\Users\Administrator>tkprof
Usage: tkprof tracefile outputfile [explain= ] [table= ]
[print= ] [insert= ] [sys= ] [sort= ]
table=schema.tablename Use 'schema.tablename' with 'explain=' option.
explain=user/password Connect to ORACLE and issue EXPLAIN PLAN.
print=integer List only the first 'integer' SQL statements.
aggregate=yes|no
insert=filename List SQL statements and data inside INSERT statements.
sys=no TKPROF does not list SQL statements run as user SYS.
record=filename Record non-recursive statements found in the trace file.
waits=yes|no Record summary for any wait events found in the trace file.
sort=option Set of zero or more of the following sort options:
prscnt number of times parse was called
prscpu cpu time parsing
prsela elapsed time parsing
prsdsk number of disk reads during parse
prsqry number of buffers for consistent read during parse
prscu number of buffers for current read during parse
prsmis number of misses in library cache during parse
execnt number of execute was called
execpu cpu time spent executing
exeela elapsed time executing
exedsk number of disk reads during execute
exeqry number of buffers for consistent read during execute
execu number of buffers for current read during execute
exerow number of rows processed during execute
exemis number of library cache misses during execute
fchcnt number of times fetch was called
fchcpu cpu time spent fetching
fchela elapsed time fetching
fchdsk number of disk reads during fetch
fchqry number of buffers for consistent read during fetch
fchcu number of buffers for current read during fetch
fchrow number of rows fetched
userid userid of user that parsed the cursor

小鱼一般喜欢加上sys=no和aggregate=no,sys默认是yes,意为也捕捉sys用户的操作,而aggreagte是将相同的sql语句集合评估。
C:\Users\Administrator>tkprof G:\oracle\product\10.2.0\admin\ora10g\udump\ora10g_ora_1352.trc g:\tkprof_10046.txt sys=no aggregate=no explain=xiaoyu/xiaoyu

TKPROF: Release 10.2.0.4.0 - Production on Thu May 22 23:39:57 2014

Copyright (c) 1982, 2007, Oracle. All rights reserved.

生成的tkprof文件如下:

TKPROF: Release 10.2.0.4.0 - Production on Thu May 22 23:39:57 2014

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Trace file: G:\oracle\product\10.2.0\admin\ora10g\udump\ora10g_ora_1352.trc
Sort options: default

********************************************************************************
count = number of times OCI procedure was executed 执行的次数
cpu = cpu time in seconds executing 消耗cpu时间,单位秒
elapsed = elapsed time in seconds executing 消耗的总时间,单位秒
disk = number of physical reads of buffers from disk 物理读
query = number of buffers gotten for consistent read 一致性读
current = number of buffers gotten in current mode (usually for update) 当前读
rows = number of rows processed by the fetch or execute call 返回的rows
********************************************************************************

select sum(object_id),sum(data_object_id)
from
t01

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 2 0.01 0.01 0 693 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 4 0.01 0.01 0 693 0 1

Misses in library cache during parse: 1 --miss in library cache表示的是硬解析
Optimizer mode: ALL_ROWS --优化器模式
Parsing user id: 58 --解析的userid

--执行计划,其中rows表示的每步执行步骤对应的cardinality,cr表示的消耗的一致性读取,pr表示的物理读,pw表示物理写,time表示消耗的时间
Rows Row Source Operation
------- ---------------------------------------------------
1 SORT AGGREGATE (cr=693 pr=0 pw=0 time=15180 us)
50070 TABLE ACCESS FULL T01 (cr=693 pr=0 pw=0 time=84 us)

在sql语句中的等待事件。
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 2 0.00 0.00
SQL*Net message from client 2 8.04 8.04
********************************************************************************

alter session set events '10046 trace name context off'

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 0 0 0
Execute 1 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0
Parsing user id: 58

下面是系统递归sql语句和非递归sql语句的消耗的资源和等待事件,递归sql语句表示的是sql语句执行过程中需要读取一些数据字典而产生的sql语句
********************************************************************************

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.00 0 0 0 0
Execute 2 0.00 0.00 0 0 0 0
Fetch 2 0.01 0.01 0 693 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 6 0.01 0.01 0 693 0 1

Misses in library cache during parse: 1

Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
SQL*Net message to client 3 0.00 0.00
SQL*Net message from client 3 18.54 26.58

OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 0 0.00 0.00 0 0 0 0
Execute 0 0.00 0.00 0 0 0 0
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 0 0.00 0.00 0 0 0 0

Misses in library cache during parse: 0

2 user SQL statements in session.
0 internal SQL statements in session.
2 SQL statements in session.
********************************************************************************
Trace file: G:\oracle\product\10.2.0\admin\ora10g\udump\ora10g_ora_1352.trc
Trace file compatibility: 10.01.00
Sort options: default

1 session in tracefile.
2 user SQL statements in trace file.
0 internal SQL statements in trace file.
2 SQL statements in trace file.
2 unique SQL statements in trace file.
50 lines in trace file.
8 elapsed seconds in trace file.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
windows10怎么查看硬盘序列号windows10怎么查看硬盘序列号Jul 17, 2023 pm 02:21 PM

硬盘序列号相当于是硬盘的身份标识,拥有唯一性的特质,那么在windows10系统中怎么查看硬盘序列号呢?第一种方法是开启电脑机箱,找到硬盘里的纸贴,就能见到一串代码了。嫌这个方法麻烦的用户也可以打开命令提示符窗口,随后运作wmicdiskdrivegetmodel,name,serialnumber这串命令,以后就能见到硬盘序列号了。windows10查询硬盘序列号方法介绍:方法一:查验贴纸标签开启PC机箱,在物理硬盘驱动器上搜索纸贴或标识。序列号列在"序列号"、"

如何快速查看numpy版本如何快速查看numpy版本Jan 19, 2024 am 08:23 AM

Numpy是Python中一个重要的数学库,它提供了高效的数组操作和科学计算函数,被广泛应用于数据分析、机器学习、深度学习等领域。在使用numpy过程中,我们经常需要查看numpy的版本号,以便确定当前环境所支持的功能。本文将介绍如何快速查看numpy版本,并提供具体的代码示例。方法一:使用numpy自带的__version__属性numpy模块自带一个__

学习如何查看Win11的产品密钥学习如何查看Win11的产品密钥Dec 24, 2023 pm 01:35 PM

有些朋友不知道win11密钥怎么查看,其实如果你激活了win11,可以直接在系统中查看到win11密钥,如果你还没有激活,那么在购买的win11盒子或邮件里也可以查看到。win11密钥怎么查看:一、已激活1、如果已经激活,那么只要右键开始菜单,打开“运行”2、在其中输入“regedit”回车打开注册表。3、接着进入“计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion\SoftwareProtectionPlatfo

查看麒麟操作系统版本和内核版本查看麒麟操作系统版本和内核版本Feb 21, 2024 pm 07:04 PM

查看麒麟操作系统版本和内核版本在麒麟操作系统中,了解如何查看系统版本和内核版本是进行系统管理和维护的基础。查看麒麟操作系统版本方法一:使用/etc/.kyinfo文件要查看麒麟操作系统的版本,您可以查看/etc/.kyinfo文件。此文件包含了操作系统的版本信息。执行以下命令:cat/etc/.kyinfo此命令将显示操作系统的详细版本信息。方法二:使用/etc/issue文件另一个查看操作系统版本的方法是通过查看/etc/issue文件。这个文件同样提供了版本信息,但可能不如.kyinfo文件

如何在Windows 10上查看电脑主板型号如何在Windows 10上查看电脑主板型号Jan 08, 2024 pm 07:59 PM

很多小伙伴买了win10系统的新电脑,却不知道电脑的主板型号如何查看。了解电脑的主板型号有助于我们更好的理解电脑,装配更合适电脑的软件。其实我们不必拆开电脑,只要适用鲁大师或者在系统设置里就可以查看了,具体的步骤一起来看看吧。win10查看电脑主板型号的方法第一种方法1、右击此电脑,点击管理2、选择设备管理器。3、右侧找到系统设备。4、就可以查看主板型号了。第二种方法1、使用鲁大师等电脑检测类软件2、可以看见自己电脑的主板型号了。第三种方法1、这个方法是最老土的啦,直接拆开自己的电脑来查看电脑主

如何查看支付宝余额宝的收益?如何查看支付宝余额宝的收益?Dec 27, 2023 pm 07:35 PM

相信很多朋友都知道支付宝和余额宝是阿里巴巴旗下的两个不错的产品,但只有余额宝能够获得预期收益。那么如何在支付宝中查看余额宝的收益呢?我相信很多朋友都想知道。接下来,我将带大家了解一下在支付宝中如何查看余额宝的收益。有兴趣的朋友们,请跟着我一起来看看吧如何查看余额宝收益的方法在支付宝中.首先,打开支付宝并登录后,在主页面下方找到"余额宝"并点击进入。接下来,在余额宝的资金明细界面上,就可以查看个人支付宝的余额宝收益了如何取消支付宝的自动续费?打开支付宝后,进入主界面,点击右下角的"我的",进入我的

如何查找默认网关如何查找默认网关Feb 19, 2024 pm 02:39 PM

默认网关在哪里看默认网关(DefaultGateway)是一个网络术语,用于指代计算机或其他网络设备连接到的主要网络的出口点。它扮演着将网络请求转发到其他网络的角色。默认网关通常由网络管理员或Internet服务提供商(ISP)进行配置,并且对于计算机来说非常重要。当我们需要链接到互联网时,我们需要知道默认网关的IP地址。那么,默认网关的IP地址在哪里查找

如何使用 Linux 查看过去注册用户的记录?如何使用 Linux 查看过去注册用户的记录?Feb 22, 2024 am 08:42 AM

在Linux系统中,用户的登录记录和活动记录通常都会被记录在系统日志文件中。可以通过查看这些日志文件来了解过去注册用户的记录。下面将介绍如何使用Linux命令查看过去注册用户的记录。查看登录记录:登录记录通常会记录在系统的认证日志文件中,常见的认证日志文件包括/var/log/auth.log、/var/log/secure等,不同的Linux发行版可能会有

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),