执行计划是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. 安装vim 出现 terminal libary 错误,解决方法

    通过源码安装vim时,提示缺少terminal libary 而在安装ncurses以后,此问题照样出现. 经过查找资料发现.运行例如以下命令就能够正常安装vim <pre name=" ...

  2. 【亲测好用!】shell批量采集百度下拉框关键词

    [亲测好用!]shell批量采集百度下拉框关键词 SEO工具  方法  11个月前 (11-18)  2153浏览 3条评论 百度已收录 一直想写一篇用shell采集百度下拉框关键词的教程,个人感觉用 ...

  3. TCP协议格式

    TCP协议 协议格式 0 16 31 |16位源端口 | 16位目标端口| | 32位序号 | | 32位确认序号 | |4位首部长度|保留(6位)|URG|ACK|PSH|RST|SYN|FIN|1 ...

  4. 解决Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a

    错误:Error:Android Dex: com.android.dex.DexIndexOverflowException: Cannot merge new index 65918 into a ...

  5. Python之美[从菜鸟到高手]--NotImplemented小析

    今天写代码时无意碰到NotImplemented,我一愣.难道是NotImplementedError的胞弟,所以略微研究了一下. NotImplemented故名思议.就是"未实现&quo ...

  6. 大数据(13) - Spark的安装部署与简单使用

    一 .Spark概述 官网:http://spark.apache.org 1.        什么是spark Spark是一种快速.通用.可扩展的大数据分析引擎,2009年诞生于加州大学伯克利分校 ...

  7. mysql 存储过程调用

    CALL  存储过程名('参数值1',‘参数值2',’参数值3')

  8. 记一次线上Kafka消息堆积踩坑总结

    2018年05月31日 13:26:59 xiaoguozi0218 阅读数:2018更多 个人分类: 大数据   年后上线的系统,与其他业务系统的通信方式采用了第三代消息系统中间件Kafka.由于是 ...

  9. 服务器的svnserver修改密码

    VisualSVN Server是一个集成的svn服务端工具,是一款svn服务端不可多得的好工具.可以先安装好VisualSVN Server后,运行VisualSVN Server Manger,然 ...

  10. 使用JAVASCRIPT进行数据完整性验证

    页面输入完整性是编写BS经常遇到的问题,如果那里需要就到那里写,那可是要花不少的时候,并且造成不必要的浪费,下面是一个通过校验脚本,使用非常方便,通过传入FORM名就可以进行校验,通过在页面控件中增加 ...