`

执行计划里statistics数据的解释

阅读更多
SQL> set autotrace on statistics
SQL> select * from tss;

        ID
----------
         1
         2
         3


Statistics
----------------------------------------------------------
          0 recursive calls
          0 db block gets
          4 consistent gets
          0 physical reads
          0 redo size
        572 bytes sent via SQL*Net to client
        487 bytes received via SQL*Net from client
          2 SQL*Net roundtrips to/from client
          0 sorts (memory)
          0 sorts (disk)
          3 rows processed

现在来解释一下每一个statistics:

1、DB Block Gets(当前请求的块数目)当前模式块意思就是在操作中正好提取的块数目,而不是在一致性读的情况下而产生的块数。正常的情况下,一个查询提取的块是在查询开始的那个时间点上存在的数据块,当前块是在这个时刻存在的数据块,而不是在这个时间点之前或者之后的数据块数目。

2、Consistent Gets(数据请求总数在回滚段Buffer中的数据一致性读所需要的数据块)这里的概念是在处理你这个操作的时候需要在一致性读状态上处理多少个块,这些块产生的主要原因是因为由于在你查询的过程中,由于其他会话对数据块进行操 作,而对所要查询的块有了修改,但是由于我们的查询是在这些修改之前调用的,所以需要对回滚段中的数据块的前映像进行查询,以保证数据的一致性。这样就产 生了一致性读。

3、Physical Reads(物理读)就是从磁盘上读取数据块的数量,其产生的主要原因是: 1、 在数据库高速缓存中不存在这些块 2、 全表扫描 3、 磁盘排序

它们三者之间的关系大致可概括为:逻辑读指的是Oracle从内存读到的数据块数量。一般来说是'consistent gets' + 'db block gets'。当在内存中找不到所需的数据块的话就需要从磁盘中获取,于是就产生了'phsical reads'。

关于physical reads ,db block gets 和consistent gets这三个参数之间有一个换算公式:
数据缓冲区的使用命中率=1 - ( physical reads / (db block gets + consistent gets) )。

select 1-physical_reads/(db_block_gets+consistent_gets) Buffer Cache
from
   (select value physical_reads from v$sysstat where name='physical reads'),
   (select value consistent_gets from v$sysstat where name='consistent gets'),
   (select value db_block_gets from v$sysstat where name='db block gets')

查询出来的结果Buffer Cache的命中率应该在90%以上,否则需要增加数据缓冲区的大小。

4、Recursive Calls. Number of recursive calls generated at both the user and system level.
Oracle Database maintains tables used for internal processing. When it needs to change these tables, Oracle Database generates an internal SQL statement, which in turn generates a recursive call.
In short, recursive calls are basically SQL performed on behalf of your SQL. So, if you had to parse the query, for example, you might have had to run some other queries to get data dictionary information. These would be recursive calls. Space management, security checks, calling PL/SQL from SQL—all incur recursive SQL calls.

5、Sorts (disk). Number of sort operations that required at least one disk write. Sorts that require I/O to disk are quite resource intensive. Try increasing the size of the initialization parameter SORT_AREA_SIZE.

最后我们看下db block gets和consistent gets的区别

buffer_gets=db block gets + consistent gets = LOGIC IO(逻辑读次数)(as opposed to physical io)

consistent gets : 通过不带for update的select 读的次数
db block gets : 通过update/delete/select for update读的次数.


consistent get :在一致读模式下所读的快数,包括从回滚段读的快数。
db block gets :在当前读模式下所读的快数,比较少和特殊,例如数据字典数据获取,在DML中,更改或删除数据是要用到当前读模式。

consistent gets:consistent_gets是从回滚段中读到的前映(或叫读取一致性影象), 看见的数据是查询开始的时间点的,所以若存在block在查询开始后发生了变化的情况,则必须产生 before image 然后读数据,这就是一致读的含义
查询就是表示 consistent gets (query mode),因为查询要保证所获取的数据的时间点的一致性,所以叫一致读,即使是从当前 buffer 获得的数据,也叫 consistent gets ,这仅仅表达一种模式一种期望,并不表示真实的是从 当前buffer 获得 还是从回滚段获取数据产生的 bufore image 。

db block gets:current mode , 不管这个块上的数据是否可能存在 before image ,也就是说不管是否存在回滚中数据可以 回滚,只看见当前最新块的数据,即使别人正在更新,也看见别人更新状态的数据,比如dml的时候就不需要看见别人更改前的数据,而是看见正在更改的,当然同时,若操作相同数据则被lock住。也就是说一次查询中看见的数据可能不在同一个时间点上,比如一个大的dml,当dml 开始更新一个非常大的表后,这个表更新的过程中,有一个进程去把该表末尾的一个记录更新了,然后这个大更新抵达该记录的时候会被阻塞的,若该进程事物提交,则大更新会覆盖该事务的更新,也就是说,这个大更新所看见的数据是当前的,不具有时间点的一致性,所以叫 current mode,个人认为db block gets这个词用的不好, 容易让人误解. 如果改成inconsistent gets可能会更准确一些。

转自:http://hi.baidu.com/learnfordba/blog/item/0dcb9858ef756b232934f022.html

英文原文:
· Recursive Calls. Number of recursive calls generated at both the user and system level.
Oracle Database maintains tables used for internal processing. When it needs to change these tables, Oracle Database generates an internal SQL statement, which in turn generates a recursive call.
In short, recursive calls are basically SQL performed on behalf of your SQL. So, if you had to parse the query, for example, you might have had to run some other queries to get data dictionary information. These would be recursive calls. Space management, security checks, calling PL/SQL from SQL—all incur recursive SQL calls.
· DB Block Gets. Number of times a CURRENT block was requested.
Current mode blocks are retrieved as they exist right now, not in a consistent read fashion.
Normally, blocks retrieved for a query are retrieved as they existed when the query began. Current mode blocks are retrieved as they exist right now, not from a previous point in time.
During a SELECT, you might see current mode retrievals due to reading the data dictionary to find the extent information for a table to do a full scan (because you need the "right now" information, not the consistent read). During a modification, you will access the blocks in current mode in order to write to them.
· Consistent Gets. Number of times a consistent read was requested for a block.
This is how many blocks you processed in "consistent read" mode. This will include counts of blocks read from the rollback segment in order to roll back a block.
This is the mode you read blocks in with a SELECT, for example.
Also, when you do a searched UPDATE/DELETE, you read the blocks in consistent read mode and then get the block in current mode to actually do the modification.
· Physical Reads. Total number of data blocks read from disk. This number equals the value of "physical reads direct" plus all reads into buffer cache.
· Sorts (disk). Number of sort operations that required at least one disk write. Sorts that require I/O to disk are quite resource intensive. Try increasing the size of the initialization parameter SORT_AREA_SIZE.
分享到:
评论

相关推荐

    解剖SQL执行计划

    1. **使用SET STATISTICS XML ON**:在查询前加上此语句,可以在查询结果后看到XML格式的执行计划。 2. **使用SQL Profiler**:捕获包含执行计划的跟踪事件。 3. **使用Actual Execution Plan视图**:在SSMS中执行...

    ORACLE数据库查看执行计划

    执行计划揭示了Oracle如何处理一个SQL查询,包括数据的访问路径、使用的索引、排序方式以及表之间的连接顺序等。本文将深入探讨如何查看执行计划,并提供优化SQL的策略。 一、执行计划的概念 执行计划是Oracle...

    oracle获取执行计划全部方法

    - **User-Mem**: 语句最后一次执行中,当前操作所使用的内存工作区大小,括号里显示的是发生磁盘交换的次数,1次即为 One-Pass,大于1次则为 Multi-Pass。 #### 方法四与方法六:适用于观察多条执行计划的情况 - ...

    获取SQL语句的执行计划v1

    - `set autotrace traceonly statistics`:仅显示统计数据,不包括查询结果或执行计划。 ```sql select * from emp; ``` - **关闭autotrace**:可以通过命令`set autotrace off`来关闭autotrace功能。 #### ...

    oracle执行计划建立与阅读

    Oracle执行计划是数据库管理系统在处理SQL语句时的预估工作流程,它是Oracle优化器根据当前数据分布、索引情况和系统资源等信息选择的最佳执行策略。了解和分析执行计划对于提升SQL语句的性能至关重要。 一、生成...

    SQL_Server执行计划

    - **使用SET STATISTICS XML**:在查询执行前设置`SET STATISTICS XML ON`,可以在查询结果后看到XML格式的执行计划。 #### 五、解读执行计划 执行计划通常包含以下元素: 1. **操作符**:每个节点代表一个操作符...

    Oracle执行计划介绍与测试.pdf

    在Oracle中,执行计划是数据库优化器根据SQL语句特性生成的一系列步骤,用于指导数据库如何执行查询以获取数据。一个高效的执行计划能够显著提升查询性能,降低资源消耗,对于数据库性能优化至关重要。 #### 查看...

    Oracle数据库关于SQL的执行计划

    它倾向于选择那些能够快速获取前几条记录的执行计划,即使这些计划在处理大量数据时效率不高。 - **All_Rows 模式**:相比之下,All_Rows 模式关注的是尽可能快地返回所有结果,适合于需要检索大量数据的场景。在...

    oracle 执行计划

    执行计划是指数据库根据SQL语句的特点和表的数据分布情况,选择的最佳执行路径。不同的执行计划会导致完全不同的执行效率。因此,当遇到SQL语句执行效率下降时,首先需要检查的是执行计划是否发生了变化。 #### 二...

    怎样看懂Oracle的执行计划

    下面将对执行计划的定义、层次关系和查看方法进行详细解释。 一、什么是执行计划 执行计划是Oracle数据库在执行查询时的内部机制,它决定了数据库如何访问和处理数据。执行计划包括了多个操作,如全表扫描、索引...

    SQL SERVER 图形执行计划中的图标学习

    - 通过在T-SQL语句中包含`SET SHOWPLAN_ALL ON`或`SET STATISTICS IO ON/TIME ON`,可以获取查询的实际执行计划,这对性能调优至关重要。 9. **实际应用**: - 在实际工作中,了解这些图标和运算符的意义,可以...

    EXP-00091 Exporting questionable statistics

    标题“EXP-00091 Exporting questionable statistics”似乎是指在数据库管理或者数据导出过程中遇到的一个特定问题,可能是关于Oracle数据库中的一个错误代码或警告。这个问题涉及到数据的统计信息,这在数据库管理...

    SQL Server Statistics Primer

    当查询优化器检测到没有现有的统计数据能够准确地描述查询所涉及的列时,它会自动创建这类统计数据来辅助执行计划的选择。 #### 查看统计数据 为了有效地管理和维护统计数据,了解如何查看统计数据的内部结构是...

    oracle执行计划

    **Oracle执行计划**是指数据库管理系统在执行SQL查询时,为了高效地检索数据所选择的一系列步骤。这些步骤由Oracle优化器决定,它会评估多种可能的执行路径,并选择一个预计成本最低的方法。理解并能够控制执行计划...

    Statistics教程(英文版)

    统计学是研究数据收集、分析、解释和展示的科学,是科学研究和社会决策中的关键工具。在这个教程中,你将能够了解到统计学的基本概念,如描述性统计(平均数、中位数、众数、方差、标准差等)和推断性统计(假设检验...

    IBM Statistics SPSS 19.0 中文版教程

    - SPSS Statistics 能够从各种格式的文件中导入数据,并利用这些数据执行统计分析。 - 软件能够生成分布和趋势、描述统计以及提供复杂统计分析的报告、图表和图形。 - 用户通过图形用户界面进行操作,但对于高级...

    Mysql利用profiles来查看SQL语句执行计划.doc

    - **init**, **optimizing**, **statistics**:初始化、优化和统计分析过程。 - **preparing** 和 **executing**:准备和执行 SQL 语句。 - **Sending data**:发送数据至客户端。 - **end** 和 **query end**:结束...

Global site tag (gtag.js) - Google Analytics