Chinaunix首页 | 论坛 | 博客
  • 博客访问: 972365
  • 博文数量: 358
  • 博客积分: 8185
  • 博客等级: 中将
  • 技术积分: 3751
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 16:27
个人简介

The views and opinions expressed all for my own,only for study and test, not reflect the views of Any Company and its affiliates.

文章分类

全部博文(358)

文章存档

2012年(8)

2011年(18)

2010年(50)

2009年(218)

2008年(64)

我的朋友

分类: Oracle

2010-01-17 10:29:32


■Execution Plan:
An execution plan is a set of steps that are performed by the optimizer in executing a SQL statement and performing an operation.

■Methods for Viewing Execution Plans:
①The EXPLAIN PLAN command
it outlines the plan that the optimizer may use and inserts it in a table called PLAN_TABLE without executing the SQL statement. 

②The trace utility SQL Trace 
It helps identify potential bottlenecks. 
It provides statistics about a query that has been executed.

③Statspack

④The Automatic Workload Repository (AWR) 
At regular intervals, the Oracle Database makes a snapshot of all its vital statistics and workload information and stores this in the AWR. 

⑤V$SQL_PLAN
The V$SQL_PLAN view contains information about executed SQL statements and their execution plan.

⑥The AUTOTRACE command 
The AUTOTRACE command available in SQL*Plus generates the PLAN_TABLE output and statistics about the performance of a query. 

You can use the DBMS_XPLAN package methods to display the execution plan generated by the EXPLAIN PLAN command and query from V$SQL_PLAN and AWR.

■Using Execution Plans

There are several uses for viewing execution plans:
・Determining the current execution plan
・Identifying the effect of creating an index on a table
・Finding cursors containing a certain access path (for example, full table scan or index range scan)
・Identifying indexes that are, or are not, selected by the optimizer
・Determining whether the optimizer selects the particular execution plan (for example, nested loops join) expected by the developer
You can use an execution plan to make decisions such as:
・Dropping or creating indexes
・Generating statistics on the database objects
・Modifying initialization parameter values
・Migrating the application or the database to a new release

EXPLAIN PLAN Command


****************************************************************
设置SQL*Plus 的AUTOTRACE
(from Oracle.Database.Architecture.9i.and.10g)

AUTOTRACE 是SQL*Plus 中一个工具,可以显示所执行查询的解释计划(explain plan)以及所用的资源。
配置AUTOTRACE 的方法不止一种,以下是我采用的方法:
(1)cd [ORACLE_HOME]/rdbms/admin;
(2)作为SYSTEM 登录SQL*Plus;
(3)运行@utlxplan;(create table PLAN_TABLE)
(4)运行CREATE PUBLIC SYNONYM PLAN_TABLE FOR PLAN_TABLE;
(5)运行GRANT ALL ON PLAN_TABLE TO PUBLIC。
如果愿意,可以把GRANT TO PUBLIC 中的PUBLIC 替换为某个用户。通过将PLAN_TABLE 置为public,任何人都可以使用SQL*Plus 进行跟踪(在我看来这并不是件坏事)。这么一来,就不需要每个用户都安装自己的计划表。
还有一种做法是,在想要使用AUTOTRACE 的每个模式中分别运行@utlxplan。

下一步是创建并授予PLUSTRACE 角色:
(1)cd [ORACLE_HOME]/sqlplus/admin;
(2)作为SYS 或SYSDBA 登录SQL*Plus;
(3)运行@plustrce;
(4)运行GRANT PLUSTRACE TO PUBLIC。
重申一遍,如果愿意,可以把GRANT 命令中PUBLIC 替换为每个用户。

关于AUTOTRACE
你会自动得到一个AUTOTRACE 报告,其中可能列出SQL 优化器所用的执行路径,以及语句的执行统计信息。
成功执行SQL DML(即SELECT、DELETE、UPDATE、MERGE 和INSERT)语句后就会生成这个报告。它对于监视并调优这些语句的性能很有帮助。

控制报告
通过设置AUTOTRACE 系统变量可以控制这个报告:
 SET AUTOTRACE OFF:不生成AUTOTRACE 报告,这是默认设置。
 SET AUTOTRACE ON EXPLAIN:AUTOTRACE 报告只显示优化器执行路径。
 SET AUTOTRACE ON STATISTICS:AUTOTRACE 报告只显示SQL 语句的执行统计信息。
 SET AUTOTRACE ON:AUTOTRACE 报告既包括优化器执行路径,又包括SQL 语句的执行统计信息。
 SET AUTOTRACE TRACEONLY:这与SET AUTOTRACE ON 类似,但是不显示用户的查询输出(如果有的话)。

阅读(1283) | 评论(0) | 转发(0) |
0

上一篇:2_Optimizer Operation

下一篇:4_Gathering Statistics

给主人留下些什么吧!~~