您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Oracle SQL 执行计划和分析小结

2025/4/6 20:21:44发布90次查看
oracle有多种方式获得一条sql语句的查询计划,比如使用explain plan命令,在plsql developer里面按f5快捷键等,但是作为sql调优,
oracle有多种方式获得一条sql语句的查询计划,比如使用explain plan命令,在plsql developer里面按f5快捷键等,但是作为sql调优,比较简便的方式,还是在sqlplus中使用set autotrace on和set timing on的方式来得到sql的实际运行时间和查询计划;
第一种:sqlplus中的autotrace是分析sql的执行计划,执行效率的一个非常简单方便的工具,使用autotrace不会产生跟踪文件。利用autotrace工具提供的sql执行计划和执行状态可以为优化sql提供依据,以及效果的对比。
在centos 6.4下安装oracle 11gr2(x64)
oracle 11gr2 在vmware虚拟机中安装步骤
debian 下 安装 oracle 11g xe r2
oracle sql引擎体系结构图
oracle sql基础 
oracle sql 高级篇
autotrace用法:
set autot[race] {off | on | trace[only]} |  [exp[lain]] [stat[istics]]
例如:
set autotrace off          停止autotrace
set autotrace on            开启autotrace,显示autotrace信息和sql执行结果
set autotrace traceonly    开启autotrace,仅显示autotrace信息
set autotrace on explain    开启autotrace,仅显示autotrace的explain信息
set autotrace statistics    开启autotrace,仅显示autotrace的statistics信息
autotrace启用:
1、使用dba角色用户sys设置权限,执行脚本plustrce.sql。
oracle10g存放目录为${oracle安装目录}\product\10.2.0\db_1\sqlplus\admin\plustrce.sql
oracle11g存放目录为${oracle安装目录}\product\11.2.0\dbhome_1\sqlplus\admin\plustrce.sql
plustrce.sql脚本用于给sql*plus set autotrace命令创建角色plustrace访问动态性能视图。该脚本必须在dba角色权限下执行,
执行完毕后,,给需要使用autotrace功能的用户赋予权限。
plustrce.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
更多详情见请继续阅读下一页的精彩内容:
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product