Oracle SQL 执行计划和分析小结

WBOY
Release: 2016-06-07 16:49:31
Original
1080 people have browsed it

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

更多详情见请继续阅读下一页的精彩内容:

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!