sqlplus中查看执行计划分析
对于oracle9i,需要手工设置plustrace角色,步骤如下:
1、在SQL>connect sys/密码 as sysdba (密码为:数据库所在的那台服务器的密码)
在sys用户下运行$ORACLE_HOME/sqlplus/admin/plustrce.sql SQL>@$ORACLE_HOME/sqlplus/admin/plustrce.sql
这段sql的实际内容如下: set echo on drop role plustrace; create role plustrace;
grant select on v_$sesstat to plustrace; grant select on v_$statname to plustrace; grant select on v_$mystat to plustrace; grant plustrace to dba with admin option; set echo off
以上产生plustrace角色
2、在sys用户下把此角色赋予一般用户
SQL> grant PLUSTRACE to 用户名; (用户名为:当前你登陆数据库的用户名,如:bbass)
3、然后在当前用户下运行$ORACLE_HOME/rdbms/admin/utlxplan.sql
SQL>@$ORACLE_HOME/rdbms/admin/utlxplan.sql 它会创建一个plan_table,用来存储分析SQL语句的结果。 4、SQL> set timing on 可查看SQL语句执行的用时 SQL> set autotrace on; 可查看SQL执行计划分析。
关于Autotrace几个常用选项的说明:
SET AUTOTRACE OFF ---------------- 不生成AUTOTRACE 报告,这是缺省模式
SET AUTOTRACE ON EXPLAIN ------ AUTOTRACE只显示优化器执行路径报告 SET AUTOTRACE ON STATISTICS -- 只显示执行统计信息 SET AUTOTRACE ON ----------------- 包含执行计划和统计信息
SET AUTOTRACE TRACEONLY ------ 同set autotrace on,但是不显示查询
5,关闭以上功能,在SQL/PLUS的窗口运行以下命令
set time off; set autotrace off;
(说明:关闭时间显示)