How to Obtain Tracing of Optimizer Computations (EVENT 10053) (文档 ID 225598.1)
来源:互联网 发布:nba2konline奥登数据 编辑:程序博客网 时间:2024/06/07 08:05
APPLIES TO:
Oracle Database - Enterprise Edition - Version 8.1.7.4 and laterInformation in this document applies to any platform.
Checked for relevance on 03-Jan-2012
PURPOSE
To provide instructions on obtaining optimizer tracing to enable Oracle Support Engineers to diagnose optimizer decisions and behaviour.
SCOPE
Customers needing to obtain 10053 trace under the direction of Oracle Support Engineers. The article explain a straightforward method of obtaining this trace.
DETAILS
Occasionally, support may wish to examine the internal decisions made by the Cost Based Optimizer (CBO) and will request a trace of optimizer decisions using event 10053. Some methods detailing how to gather this trace are illustrated below.
Please set TRACE_ENABLED=TRUE in order to enable 10053 tracing
Also, make sure that max_dump_file_size=unlimited or the trace file may be truncated
DUMP_TRACE: DBMS_SQLDIAG packaged procedure (11g R2 onwards)
Oracle Database 11g, introduced a new diagnostic events infrastructure, which greatly simplifies the task of generating a 10053 trace for a specific SQL statement.
Starting in 11g Release 2, you can use this to generate an Optimizer trace for any SQL statement in the cursor cache without having to execute it. The DBMS_SQLDIAG package has been extended to include a procedure called DUMP_TRACE. This procedure, just requires SQL_ID of the statement you wish to generate an Optimizer trace for but it doesn’t require you to re-execute the statement. The procedure will automatically trigger a hard parse of the statement to generate the trace.
To use this Package, first find the SQL_ID:
SQL> column sql_text format a30SQL> select '10053_test' from dual;SQL> select sql_id, child_number, sql_text from v$sql where sql_text like '%10053_test%';SQL_ID CHILD_NUMBER SQL_TEXT------------- ------------ ------------------------------cjk13xfm8ybh7 0 select '10053_test' from dual
Then you can use the following syntax using the SQL_ID for your SQL (in my case 'cjk13xfm8ybh7' above):
p_sql_id=>'cjk13xfm8ybh7', -
p_child_number=>0, -
p_component=>'Optimizer', -
p_file_id=>'TEST');
PL/SQL procedure successfully completed.
You can use the following to identify the tracefile produced:
Session altered.
SQL> oradebug setmypid
Statement processed.
SQL> oradebug tracefile_name
/..../v11203_ora_1827_OPTIMIZER_TRACE.trc
For more details see: Capturing 10053 trace files continued
Alter Session Methods
Using New Diagnostic Events Infrastructure (11g Onwards)
The new diagnostic events infrastructure, allows tracing to be enabled for a specific SQL ID instead of turning it on for the entire session. Oracle will then capture a 10053 trace for the corresponding SQL statement when it is issued in that session.
Using the SQL_ID from before:
SQL> ALTER SESSION SET EVENTS 'trace[rdbms.SQL_Optimizer.*][sql:cjk13xfm8ybh7]';
SQL> --Execute the query --
To disable the trace
See: How do I capture a 10053 trace for a SQL statement called in a PL/SQL package?
Traditional Alter Session Methods
Query With Literals
Ensure that a PLAN_TABLE exists in the schema of the user that will be used to trace the query. If the PLAN_TABLE does not exist then it can be created by running the utlxplan.sql script which resides in the rdbms/admin under the Oracle home $ORACLE_HOME/rdbms/admin/utlxplan.sql (on Unix systems).
Connect to Oracle using SQL*Plus as the appropriate user and issue the following series of commands:
SQL> ALTER SESSION SET EVENTS '10053 trace name context forever, level 1';
Session altered.
SQL> EXPLAIN PLAN FOR --SQL STATEMENT--;
Explained.
SQL> exit
Query With Binds
Connect to Oracle using SQL*Plus as the appropriate user and issue the following series of commands. Set up as many binds as are needed by the query:
Session altered.
-- set up binds.
SQL> variable a number
SQL> variable b varchar2(10)
-- assign values to binds
SQL> begin
2 :a:=20;
3 :b:='CLERK';
4 end;
5 /
SQL> select empno, ename, mgr
2 from emp
3 where deptno = :a
4 and job = :b
/
SQL> exit
Finding the trace file
With either case, a trace file will be generated in the default trace location. You can find the location where trace would go if you traced the current sesion using a select such as:
FROM v$diag_info
WHERE name='Default Trace File';
On earlier versions the location is defined by the parameter <Parameter:user_dump_dest>.
To identify the correct trace file, search for the the relevant --SQL STATEMENT--.
This will be followed by a section headed "PARAMETERS USED BY THE OPTIMIZER". e.g:
QUERY
SELECT * FROM EMP
***************************************
PARAMETERS USED BY THE OPTIMIZER
********************************
OPTIMIZER_FEATURES_ENABLE = 8.1.7
OPTIMIZER_MODE/GOAL = Choose
OPTIMIZER_PERCENT_PARALLEL = 0
HASH_AREA_SIZE = 10240
HASH_JOIN_ENABLED = TRUE
HASH_MULTIBLOCK_IO_COUNT = 16
...
Explanation of the PLAN_TABLE requirement:
For a 10053 trace to be produced, the QUERY must be using the CBO and must be re-parsed with the event in place. The PLAN_TABLE is not actually required for this trace to work. It is only there to facilitate the EXPLAIN PLAN command. The EXPLAIN PLAN is the Alter Session Method (Literals)re because it forces a reparse of the statement. EXPLAIN PLAN will fail without presence of the PLAN_TABLE.
Explanation of the behaviour when using binds :
Note that EXPLAIN PLAN and SQL*Plus have limitations in the way they treat certain bind types. With bind variables in general, the EXPLAIN PLAN output might not represent the real execution plan. Additionally, SQL*Plus does not support DATE datatypes. If using binds, use method 2 but bear in mind this might not give the exact same execution plan as when the SQL is run from within in your application.
REFERENCES
NOTE:68735.1 - * Diagnostics for Query Tuning Problems- Oracle Database Products > Oracle Database > Oracle Database > Oracle Database - Enterprise Edition > RDBMS > Generic SQL Performance, SQL Execution, Query Optimizer
- How to Obtain Tracing of Optimizer Computations (EVENT 10053) (文档 ID 225598.1)
- How to Calculate the Number of IOPS and Throughput of a Database (文档 ID 2206831.1)
- EVENT: 10046 "enable SQL statement tracing (including binds/waits)" (文档 ID 21154.1)
- How to Interpret the OS stats section of an AWR report (文档 ID 762526.1)
- How To Add/Increase The Size Of Redo Log Files In Rac Environment? (文档 ID 779306.1)
- How to collect the full path name of the files in ASM diskgroups (文档 ID 888943.1)
- How to collect the full path name of the files in ASM diskgroups (文档 ID 888943.1)
- How to Determine the Blocking Session for Event: 'cursor: pin S wait on X' (文档 ID 786507.1)
- How to Gather Optimizer Statistics on 9i (Doc ID 388474.1)
- How to Gather Optimizer Statistics on 10g (Doc ID 605439.1)
- How to Gather Optimizer Statistics on 11g (Doc ID 749227.1)
- How to Gather Optimizer Statistics on 12c (Doc ID 1445302.1)
- How To: Gather Statistics for the Cost Based Optimizer (Doc ID 1226841.1)
- How to resolve the error:Event ID 1030 occur in conjunction with Event id 1058
- How to obtain asynchronous response synchronously?
- How to obtain iMac full system report
- How to obtain crash dump in win8
- How To Avoid Disk Full Issues Because OPatch Backups Take Big Amount Of Disk Space. (文档 ID 550522.1)
- 友元函数和友元类
- 常使用的正则
- Kruskal算法模板
- 图片轮播器
- 平板电脑能打电话吗?如何让不支持电话功能的平板获得电话功能?
- How to Obtain Tracing of Optimizer Computations (EVENT 10053) (文档 ID 225598.1)
- Java设计模式泛型化之命令模式
- ActionScript 3 单例模式
- 适配器 -- 不兼容结构的协调
- winform登陆后关闭登录窗口跳转到主窗体
- 剖析easyui tree源码(设计原理)来学习easyui
- Redis-API实例
- 翻格子游戏
- Linux下DRBD配置