Heim > Datenbank > MySQL-Tutorial > Hauptteil

Oracle SQL 执行计划和分析小结

WBOY
Freigeben: 2016-06-07 16:49:31
Original
1116 Leute haben es durchsucht

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

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!