执行计划是SQL获取和处理数据的途径和方法.

执行计划和性能

SQL -- 数据库性能的始作俑者

  1. 所有的数据库性能,几乎全部来自SQL。
  2. 优秀的SQL是数据库最大的福祉。
  3. 一条很烂的SQL,可以搞瘫一台性能极好的服务器。

为什么高效的 SQL 这么难?

  1. 语言的效率,是SQL语言的最难的地方
    1. – tablesan
    2. – index range scan
    3. – index fast scan
    4. – nested loop join
    5. – merge join
    6. – hash join
    7. ... …
  2. 优化器机制开发者无法掌控

如何查看SQL语句的执行计划?

SQL> set autotrace trace exp;

SQL> set autotrace trace exp stat;--------可以查看SQL语句的效率,查看一致性读consistent gets

SQL> set autotrace off;--------关闭

plustrace:set autotrace trace exp stat(SP2-0618、SP2-0611)

1、报错:当前用户不能使用autotrace获得执行计划

、切换为sys用户,

、授予用户scott plustrace Role,报错plustrace角色不存在

、进入$ORACLE_HOME/sqlplus/admin/plustrce.sql目录,通过运行如下SQL:plustrce.sql创建

[root@WHOST admin]# pwd

/u01/app/oracle/product/11.2.4/dbhome_1/sqlplus/admin

[root@WHOST admin]# ls -al

total 28

drwxr-xr-x 3 oracle dba 4096 Jun 4 22:23 .

drwxr-xr-x 7 oracle dba 4096 Jun 4 22:28 ..

-rw-r--r-- 1 oracle dba 368 Apr 10 2011 glogin.sql

drwxr-xr-x 2 oracle dba 4096 Jun 4 22:23 help

-rw-r--r-- 1 oracle dba 226 Jul 17 2013 libsqlplus.def

-rw-r--r-- 1 oracle dba 813 Mar 7 2006 plustrce.sql

-rw-r--r-- 1 oracle dba 2118 Feb 16 2003 pupbld.sql

1)查看$ORACLE_HOME/sqlplus/admin下的plustrce.sql发现如下内容:

--

-- Copyright (c) Oracle Corporation 1995, 2002. All Rights Reserved.

--

-- NAME

--   plustrce.sql

--

-- DESCRIPTION

--   Creates a role with access to Dynamic Performance Tables

--   for the SQL*Plus SET AUTOTRACE ... STATISTICS command.

--   After this script has been run, each user requiring access to

--   the AUTOTRACE feature should be granted the PLUSTRACE role by

--   the DBA.

--

-- USAGE

--   sqlplus "sys/knl_test7 as sysdba" @plustrce

--

--   Catalog.sql must have been run before this file is run.

--   This file must be run while connected to a DBA schema.

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

2)执行该sql创建plustrace角色。

SQL> @./plustrce.sql

SQL>

SQL> drop role plustrace;

drop role plustrace

*

ERROR at line 1:

ORA-01919: role 'PLUSTRACE' does not exist

SQL> create role plustrace;

Role created.

SQL>

SQL> grant select on v_$sesstat to plustrace;

Grant succeeded.

SQL> grant select on v_$statname to plustrace;

Grant succeeded.

SQL> grant select on v_$mystat to plustrace;

Grant succeeded.

SQL> grant plustrace to dba with admin option;

Grant succeeded.

SQL>

SQL> set echo off

SQL>

SQL> grant plustrace to rhys;

Grant succeeded.

5、授予用户 plustrace 角色

SQL> grant plustrace to scott;

Grant succeeded.

启用 autotrace

SQL> set autotrace on

至此问题解决

查看执行计划plustrace:set autotrace trace exp stat(SP2-0618、SP2-0611)的更多相关文章

  1. 使用 10046 查看执行计划并读懂 trace 文件

    查看 sql 执行计划的方法有许多种, 10046 事件就是其中的一种. 与其他查看 sql 执行计划不同, 当我们遇到比较复杂的 sql 语句, 我们可以通过 10046 跟踪 sql 得到执行计划 ...

  2. Oracle数据库查看执行计划

    基于ORACLE的应用系统很多性能问题,是由应用系统SQL性能低劣引起的,所以,SQL的性能优化很重要,分析与优化SQL的性能我们一般通过查看该SQL的执行计划,本文就如何看懂执行计划,以及如何通过分 ...

  3. ORACLE数据库查看执行计划的方法

    一.什么是执行计划(explain plan) 执行计划:一条查询语句在ORACLE中的执行过程或访问路径的描述. 二.如何查看执行计划 1: 在PL/SQL下按F5查看执行计划.第三方工具toad等 ...

  4. oracle如何查看执行计划

    1.在PL/SQL Developer中得到一个SQL的执行计划 输入想要查看执行计划的目标SQL,再按一下快捷键F5就可以了.2.explain plan 命令 explain plan for + ...

  5. oracle执行计划(二)----如何查看执行计划

    目录: (一)六种执行计划  (1)explain plan for  (2)set autotrace on  (3)statistics_level=all  (4)dbms_xplan.disp ...

  6. oracle查看执行计划以及使用场景

    文档结构: oracle执行计划使用场景 环境: Centos 6.10 Oracle 18.3.0.0.0 c 11g默认启动了自动统计信息收集的任务,默认运行时间是周一到周五晚上10点和周6,周天 ...

  7. Mysql查看执行计划-explain

    最近生产环境有一些查询较慢,需要优化,于是先进行业务确认查询条件是否可以优化,不行再进行sql优化,于是学习了下Mysql查看执行计划. 语法 explain <sql语句>  例如: e ...

  8. MySQL 使用explain查看执行计划

    使用explain查看执行计划, 下面是针对这两条语句进行分析,其查询结果是一样的. EXPLAIN select n.id,n.title from info n inner join info_t ...

  9. T-SQL备忘(5):查看执行计划

    先理解几个概念:表扫描.聚集索引扫描.聚集索引查找.索引扫描.书签查找. [查看执行计划] 在理解概念之前先得知道如何查看执行计划—Ctrl+L.如下图: 注:SQL Server的执行计划是从右向左 ...

随机推荐

  1. [svc]linux buffer和cache的区别

    通俗理解buffer,cache Cache:缓存区,是高速缓存,是位于CPU和主内存之间的容量较小但速度很快的存储器,因为CPU的速度远远高于主内存的速度,CPU从内存中读取数据需等待很长的时间,而 ...

  2. pyspark采用python3开发

    现在时间2017-04-17. python版本3.5支持pyspark python3.6目前还不支持 做法简单,只需要在bin/pyspark中增加 export PYSPARK_PYTHON=p ...

  3. Windows 8.1下安装Mac OS X 10.8虚拟机

    转载自http://blog.csdn.net/jordanxinwang/article/details/43637799 1.准备 宿主操作系统:Windows 8.1 64位.特别地,需要CPU ...

  4. VisualStudio“在查找预编译头使用时跳过"解决方案

    解决方案1:确保所有的cpp文件都包含了stdafx.h,且确保stdafx.h是第一个#include指令(经尝试,可行) 解决方案2:去掉预编译头 项目->属性->配置属性->c ...

  5. js 静态方法 静态变量 实例方法 实例变量

    1.静态方法的定义 Js代码   var BaseClass = function() {}; // var BaseClass=new Function(); BaseClass.f1 = func ...

  6. 修复安卓的bug

    一直不明白listview中的复用,为什么会出现,项目多了.点击同一行的按钮,操作的不是指定行的对象. 仔细研读了代码,突然明白了.因为复用了,导致了position改变了. 伪码 if(conver ...

  7. selenium测试环境搭建(一)

    selenium测试环境搭建 下载资源 1.  selenium-java-2.53.0.zip 下载地址:http://pan.baidu.com/s/1dFDf27Z 2. Firefox Set ...

  8. JavaBeans 官方文档学习

    提示,重点:JavaBeans的Property和 Events:PropertyEditor极其注册和查找机制. 从目前来看,JavaBeans 更像是源自GUI的需求. 使用NetBeans新建一 ...

  9. jQuery对象与javaScript对象的互换

    1. jQuery对象-->Dom对象 1) 通过 .[0] 的方式:       var $s = $(.class);  (jQuery对象)       var s = $s.[0];   ...

  10. Linq------错误:EntityType: EntitySet 'Products' is based on type 'Product' that has no keys defined.

    解决方法: [Table("bma_products")] public class Product { //加上[Key]即可 [Key] public int pid{get; ...