`

Oracle AUTOTRACE Explained

阅读更多

Oracle AUTOTRACE Explained

 

 

AUTOTRACE is a beautiful utility in Oracle that can help you gather vital performance statistics for a SQL Query. You need to understand and use it for SQL Query Tuning. Here is how!

When you fire an SQL query to Oracle, database performs a lot of tasks like PARSING the query, Sorting the result and physically reading the data from the data files. AUTOTRACE provides you a summary statistics for these operations which are vital to understand how your query works.

What is AUTOTRACE?

AUTOTRACE is a utility in SQL* PLUS, that generates a report on the execution path used by SQL optimizer after it successfully executes a DML statement. It instantly provides an automatic feedback that can be analyzed to understand different technical aspects on how Oracle executes the SQL. Such feedback is very useful for Query tuning.

AUTOTRACE Explained

We will start with a very simple SELECT statement and try to interpret the result it produces.First we will require, SQL* PLUS software (Or any other Interface software that supports AUTOTRACE, e.g. SQL Developer etc.) and connectivity to Oracle database. We need to have either autotrace or DBA role enabled on the user using the AUTOTRACE command. I will use Oracle “emp” table to illustrate AUTOTRACE result.

AUTOTRACE Example

We can turn on AUTOTRACE by firing the following command,

SQL> set autotrace on

Next, fire the following simple SQL,

SQL> select ename from emp where empno = 9999;

no rows selected

Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'EMP'
2 1 INDEX (UNIQUE SCAN) OF 'PK_EMP' (UNIQUE)


Statistics
----------------------------------------------------------
83 recursive calls
0 db block gets
21 consistent gets
3 physical reads
0 redo size
221 bytes sent via SQL*Net to client
368 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed

 

Off course, it shows a lot of details which we need to understand now. I will not be talking about the “Execution Plan” part here, since that will be dealt separately in different article. So let’s concentrate on the “Statistics” part of the result shown above. All these statistics are actually recorded in Server when the statement is executed and AUTOTRACE utility only digs out this information in presentable format.

Recursive Calls

This is the number of SQL calls that are generated in User and System levels on behalf of our main SQL. Suppose in order to execute our main query, Oracle needs to PARSE the query. For this Oracle might generate further queries in data dictionary tables etc. Such additional queries will be counted as recursive calls.

Db Block Gets and Consistent Gets

This is somewhat bigger subject to discuss. But I will not go to all the details of “db block gets”. I will try to put it as simply as possible without messing up the actual article. To understand this properly, first we need to know how Oracle maintains read consistency.

When a table is being queried and updated simultaneously, Oracle must provide a (read-) consistent set of table’s data to the user. This is to ensure that, unless the update is committed, any user who queries the table’s data, see only the original data value and not the updated one (uncommitted update). For this, when required, Oracle takes the original values of the changed data from the Roll-back segment and unchanged data (un-updated rows) from the SGA buffer to generate the full set of output.

This (read-consistency) is what is ensured in consistent gets. So a consistent get means block read in consistent mode (point in time mode) for which Oracle MAY or MAY NOT involve reconstruction from roll-back segment. This is the most normal get for Oracle and you may see some additional gets if Oracle at all needs to access the rollback data (which I generally rare, because not always table data will get updated and read simultaneously)

But in case of “db block get” Oracle only shows data from blocks read as-of-now (Current data). It seems Oracle uses db block get only for fetching internal information, like for reading segment header information for a table in FULL TABLE SCAN.

Normally one can not do much to reduce the db block gets.

Physical Reads

Oracle Physical Read means total number of data blocks read directly or from buffer cache.

Redo Size

This is total number of Redo Log generated sized in bytes.

Sorts

Sorts are performed either in memory (RAM) or in disk. These sorts are often necessary by Oracle to perform certain search algorithm. In memory sort is much faster than disk sort.

While tuning the performance of Oracle query, the basic thing we should concentrate on reducing the Physical IO, Consistent Gets and Sorts. Off course the less the values for these attributes, the better is the performance.

One last thing, if you use SET AUTOTRACE TRACEONLY, the result will only show the trace statistics and will not show the actual query results.

 

 

分享到:
评论

相关推荐

    oracle 的Autotrace介绍

    Oracle Autotrace 介绍 Oracle Autotrace 是 Oracle 10g 中的一项新技术,用于自动跟踪 SQL 语句的执行计划并提供与该语句的处理有关的统计。Autotrace 是 SQL*Plus 的一项功能,可以用来替代 SQL Trace 使用。...

    oracle使用autotrace 功能

    Oracle的Autotrace是SQL*Plus中的一个强大工具,它主要用于帮助数据库管理员和开发人员分析SQL查询的执行计划,并收集执行时的性能统计数据。通过这些信息,可以有效地进行SQL查询优化,提高数据库的性能。下面是...

    Oracle性能分析——使用set_autotrace_on和set_timing_on来分析select语句的性能.doc

    Oracle 性能分析——使用 set_autotrace_on 和 set_timing_on 来分析 select 语句的性能 Oracle 数据库性能分析是数据库优化的重要步骤之一,通过对 SQL 语句的执行计划和运行时间的分析,可以了解数据库的性能瓶颈...

    oracle怎么查看执行计划

    ### Oracle如何使用AUTOTRACE查看执行计划 在Oracle数据库管理中,查看SQL语句的执行计划是一项重要的技能,这有助于优化查询性能、诊断性能问题等。AUTOTRACE是Oracle提供的一种强大的工具,用于自动展示SQL语句的...

    Oracle默认用户名与密码速查表.doc

    Oracle 默认用户名与密码速查表和 AutoTrace 工具使用指南 Oracle 默认用户名与密码速查表是 Oracle 数据库管理系统中一个非常重要的组件。 Oracle 默认用户名与密码速查表提供了 Oracle 数据库中各种默认用户名和...

    AutoTrace 0.31.1

    矢量化,包含执行程序与C++源码。 a program for converting bitmap to vector graphics. Inputformats BMP, TGA, PNM, PPM, PGM, PBM and those supported by ImageMagick. Exportformat Postscript, svg, xfig, ...

    oracle explain plan总结

    ### Oracle Explain Plan 总结 #### 一、Oracle 执行计划的重要性 在Oracle数据库中,为了提高查询效率和系统性能,我们需要对SQL语句进行优化。优化的第一步就是理解SQL语句的执行计划。执行计划是指Oracle数据库...

    oracle的索引学习

    总之,Oracle的索引学习涵盖了从索引创建、选择合适的索引类型、理解数据操作对索引的影响,到使用Autotrace和DBMS_XPLAN进行性能分析等多个方面。深入理解和实践这些知识点,能帮助我们更好地管理和优化Oracle...

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

    ### Oracle执行计划深入解析 #### 引言 在数据库领域,尤其对于大型企业级应用,Oracle数据库因其强大的功能和稳定性而被广泛采用。在Oracle中,执行计划是数据库优化器根据SQL语句特性生成的一系列步骤,用于指导...

    Oracle执行计划.ppt

    * Autotrace 工具:Autotrace 是 Oracle 提供的一种工具,可以自动跟踪执行计划。 * 其他工具:还有其他工具可以获取执行计划,例如 Oracle Enterprise Manager 等。 四、执行计划的优化 执行计划的优化是指 ...

    Oracle数据库连接与会话

    Oracle数据库连接与会话 Oracle数据库连接与会话是Oracle数据库管理系统中的两个核心概念。它们之间存在一定的关系,但又有着明显的区别。 连接是一种从客户端到数据库实例的物理通道,可以通过网络或IPC机制建立...

    大牛出手Oracle SQL优化实例讲解

    1.Oracle如何得到一个很大的表 2.loop insert 实例 3.autotrace验证索引的性能到底有多大? 4.EXPLAIN验证SQL是否走索引 5.结合autotrace创建并验证函数索引 6.sql trace分析工具--TKPROF详细讲解 7.V$SQL视图详解加...

    oracle dba 面试题总结

    使用 set autotrace on 语句可以查看 SQL 的执行计划,并且可以使用 explain plan 语句来查看执行计划的详细信息。在优化器模式为 CHOOSE 时,如果表有统计信息,优化器将选择 Cost-Based Optimizer(CBO),否则...

    Apress_Expert one on one Oracle

    本书还提供了Oracle开发环境的设置指南,包括如何配置SQL\*PLUS环境、启用AUTOTRACE功能、选择合适的C编译器等。此外,还提出了一套Oracle代码编写规范,以确保代码的可读性和维护性。 ### 六、案例分析与实践建议 ...

    Oracle中SQL语句执行效率的查找与解决

    Oracle提供了多种工具来分析SQL执行计划,包括EXPLAIN PLAN和AUTOTRACE。通过这些工具,可以详细查看SQL语句如何访问表和索引,以及执行过程中涉及的操作类型。 #### 二、执行计划优化 Oracle数据库的执行计划选择...

    oracle数据库开发规范.pdf

    2. Oracle的自动跟踪(autotrace)用于跟踪SQL语句的执行情况。 3. Oracle的SQL优化器(CBO)使用统计信息来选择最优的执行计划。 4. Oracle的行级锁定(row-level locking)用于保证并发事务的正确性。 5. ...

    oracle性能监控_oracle_维护_日常_性能_监控_

    通过工具如`sqlplus`、` tkprof` 或 `autotrace`,我们可以分析SQL的执行计划,找出慢查询并进行优化。例如,使用`EXPLAIN PLAN`可以查看SQL的执行计划,`DBMS_X PLAN DISPLAY`用于获取已执行的计划,而`v$session_...

    Oracle执行计划1.ppt

    Oracle 执行计划的生成方式有三种:Explain、Autotrace 和其他工具。其中,Explain 是通过 Execute Plan 语句生成执行计划的,Autotrace 是通过设置 autotrace 参数生成执行计划的。 在 Oracle 中,生成执行计划...

    Oracle连接和使用.pdf

    autotrace是Oracle数据库中一个非常实用的工具,它可以生成SQL的执行计划,提供执行时间、缓冲区获取次数等统计信息,帮助优化SQL性能。尽管本文仅介绍了autotrace的基本使用,但实际它还包含更多高级功能,如...

    Oracle优化常用概念.pptx

    可以使用 Pl/sql 中按 F5、Explain plan、Sql trace 和 Sql/plus autotrace 等方式生成执行计划。要看懂执行计划,需要多看执行计划,网上查一下具体含义。 统计信息和柱状图 统计信息是 Oracle 优化器计算成本所...

Global site tag (gtag.js) - Google Analytics