您的位置:首页 > 数据库

sqlplus中显示sql执行计划和统计信息

2013-06-26 23:59 387 查看
31 ,32 , 33 ,34 keywords : oracle storage structure

最详细讲解:

1: doc 1 logical storage structure

2: doc 2 physical storage structure

打开oracle sqlplus trace 的方法

打开后可以看到执行过程中的统计信息:

首先用dba登录:

drop role plustrace;
Role dropped.
create role plustrace;
Role created.
.
grant plustrace to dba with admin option;
Grant succeeded.


然后授权给HR;

GRANT PLUSTRACE TO HR;
Grant succeeded.
然后用HR用户登录:

SQL> conn HR/HR
已连接。
SQL> set auto trace
SP2-0158: 未知的 SET autocommit 选项 "trace"
用法: SET AUTO[COMMIT] { OFF | ON | IMM[EDIATE] | n }
SQL> set autot trace
SP2-0618: 无法找到会话标识符。启用检查 PLUSTRACE 角色
SP2-0611: 启用 STATISTICS 报告时出错


报了以上错误: 以上错误解决方法:

1: 用oracle dba用户登录

2:执行如下授权命令:

SQL> conn /as sysdba
已连接。
SQL> grant select on v_$sesstat to plustrace;

授权成功。

SQL>  grant select on v_$statname to plustrace;

授权成功。

SQL>  grant select on v_$mystat to plustrace;

授权成功。

SQL>  grant plustrace to dba with admin option;

授权成功。

SQL> grant plustrace to HR;

授权成功。

SQL> exit


授权完成后用oracle 普通用户HR登录: 打开 autotrace on 即可: 就能看到执行计划和 统计信息了。

SQL> conn HR/HR
已连接。
SQL> select count(*) from employees;

COUNT(*)
----------
107

SQL> set autotrace on
SQL> select count(*) from employees;

COUNT(*)
----------
107

执行计划
----------------------------------------------------------
Plan hash value: 3580537945

-------------------------------------------------------------------------
| Id  | Operation        | Name         | Rows  | Cost (%CPU)| Time     |
-------------------------------------------------------------------------
|   0 | SELECT STATEMENT |              |     1 |     1   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE  |              |     1 |            |          |
|   2 |   INDEX FULL SCAN| EMP_EMAIL_UK |   107 |     1   (0)| 00:00:01 |
-------------------------------------------------------------------------

统计信息
----------------------------------------------------------
0  recursive calls
0  db block gets
1  consistent gets
0  physical reads
0  redo size
420  bytes sent via SQL*Net to client
416  bytes received via SQL*Net from client
2  SQL*Net roundtrips to/from client
0  sorts (memory)
0  sorts (disk)
1  rows processed
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: