想用SCOTT用戶做執(zhí)行計劃的實驗,發(fā)現(xiàn)無法使用;按理說任何可以使用sqlplus 的用戶都可以在session下啟用autotrace 功能,不過有的需要做下設(shè)置;
鎮(zhèn)江網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)建站自2013年創(chuàng)立以來到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
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 用戶登錄
SQL> set autotrace on //提示檢查PLUSTRACE角色是否開啟,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,數(shù)據(jù)庫啟用autotrace功能的安裝腳本,主要是創(chuàng)建plustrace角色,并且授權(quán) ,擁有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>
設(shè)置Autotrace的命令
序號 | 命令 | 解釋 |
1 | SET AUTOTRACE OFF | 此為默認值,即關(guān)閉Autotrace |
2 | SET AUTOTRACE ON | 產(chǎn)生結(jié)果集和解釋計劃并列出統(tǒng)計 |
3 | SET AUTOTRACE ON EXPLAIN | 顯示結(jié)果集和解釋計劃不顯示統(tǒng)計 |
4 | SET AUTOTRACE TRACEONLY | 顯示解釋計劃和統(tǒng)計,盡管執(zhí)行該語句但您將看不到結(jié)果集 |
5 | SET AUTOTRACE TRACEONLY STATISTICS | 只顯示統(tǒng)計 |
PS:SET AUTOTRACE ON, set timing on, alter session set time_statistics=true;
Autotrace執(zhí)行計劃的各列的涵義
序號 | 列名 | 解釋 |
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的數(shù)量 |
2 | consistent gets | 從buffer cache中讀取的undo數(shù)據(jù)的block的數(shù)量 |
3 | physical reads | 從磁盤讀取的block的數(shù)量 |
4 | redo size | DML生成的redo的大小 |
5 | sorts (memory) | 在內(nèi)存執(zhí)行的排序量 |
6 | sorts (disk) | 在磁盤上執(zhí)行的排序量 |