您好,登錄后才能下訂單哦!
想用SCOTT用戶做執行計劃的實驗,發現無法使用;按理說任何可以使用sqlplus 的用戶都可以在session下啟用autotrace 功能,不過有的需要做下設置;
sys 用戶
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> select username,account_status from dba_users where username='SCOTT';
USERNAME ACCOUNT_STATUS
------------------------------ --------------------------------
SCOTT EXPIRED & LOCKED
SQL> alter user scott account unlock identified by tiger;
User altered.
SQL>
SQL> select username,account_status from dba_users where username='SCOTT';
USERNAME ACCOUNT_STATUS
------------------------------ --------------------------------
SCOTT OPEN
SCOTT 用戶登錄
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report
解決過程
1、以SYS用戶登錄,運行utlxplan.sql. 建立plan 表;
SQL> @?/rdbms/admin/utlxplan.sql
Table created.
2、以sys用戶登錄,運行plustrce.sql,數據庫啟用autotrace功能的安裝腳本,主要是創建plustrace角色,并且授權 ,擁有plustrace最主要的目的是為了訪問下面幾個VIEW :v_$sesstat;v_$statname;v_$mystat;
SQL> @?/sqlplus/admin/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> grant plustrace to scott;
Grant succeeded.
3、以SCOTT 登錄
SQL> set autotrace on
SQL>
SQL> select * from dept;
DEPTNO DNAME LOC
---------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Execution Plan
----------------------------------------------------------
Plan hash value: 3383998547
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4 | 80 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| DEPT | 4 | 80 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------
Statistics
----------------------------------------------------------
2 recursive calls
0 db block gets
10 consistent gets
4 physical reads
0 redo size
802 bytes sent via SQL*Net to client
523 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
4 rows processed
SQL>
設置Autotrace的命令
序號 | 命令 | 解釋 |
1 | SET AUTOTRACE OFF | 此為默認值,即關閉Autotrace |
2 | SET AUTOTRACE ON | 產生結果集和解釋計劃并列出統計 |
3 | SET AUTOTRACE ON EXPLAIN | 顯示結果集和解釋計劃不顯示統計 |
4 | SET AUTOTRACE TRACEONLY | 顯示解釋計劃和統計,盡管執行該語句但您將看不到結果集 |
5 | SET AUTOTRACE TRACEONLY STATISTICS | 只顯示統計 |
PS:SET AUTOTRACE ON, set timing on, alter session set time_statistics=true;
Autotrace執行計劃的各列的涵義
序號 | 列名 | 解釋 |
1 | ID_PLUS_EXP | 每一步驟的行號 |
2 | PARENT_ID_PLUS_EXP | 每一步的Parent的級別號 |
3 | PLAN_PLUS_EXP | 實際的每步 |
4 | OBJECT_NODE_PLUS_EXP | Dblink或并行查詢時才會用到 |
Autotrace Statistics常用列解釋
序號 | 列名 | 解釋 |
1 | db block gets | 從buffer cache中讀取的block的數量 |
2 | consistent gets | 從buffer cache中讀取的undo數據的block的數量 |
3 | physical reads | 從磁盤讀取的block的數量 |
4 | redo size | DML生成的redo的大小 |
5 | sorts (memory) | 在內存執行的排序量 |
6 | sorts (disk) | 在磁盤上執行的排序量 |
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。