DBMS_XPLAN包的使用
测试使用:
1. 首先我们以SYS用户建立PLUSTRACE角色(具体脚本位于$ORACLE_HOME\E:\oracle\ora92\sqlplus\admin\Plustrce.sql)因为这个角色有一些对系统视图查看的权限,因此必须以SYS用户创建。
2. 把该角色授予相应的SCHEMA用户
GRANT PLUSTRACE TO songyk WITH ADMIN OPTION
3. 建立plan_table(规划表)ORACLE_HOME/rdbms/admin/下的utlxplan.sql
4. 比较使用:下面我们来举例说明
SQL> create table sys_log_access as select * from hangan.sys_log_access;
表已创建。
SQL> select count(*) from sys_log_access;
COUNT(*)
----------
132424
下面用常规的analyze命令对表进行分析
SQL> analyze table sys_log_access compute statistics;
表已分析。
SQL> set autotrace traceonly
SQL> select ip,accesspage,count(*) from sys_log_access group by ip,accesspage;
已选择6150行。
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4612 Card=132424 Byt
es=8077864)
1 0 SORT (GROUP BY) (Cost=4612 Card=132424 Bytes=8077864)
2 1 TABLE ACCESS (FULL) OF 'SYS_LOG_ACCESS' (Cost=183 Card=1
32424 Bytes=8077864)
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
1853 consistent gets
1177 physical reads
0 redo size
398925 bytes sent via SQL*Net to client
4994 bytes received via SQL*Net from client
411 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
6150 rows processed
下面用DBMS_XPLAN进行分析
首先删除规划表中的数据: delete from plan_table;
SQL> explain plan for select ip,accesspage,count(*) from sys_log_access group by ip,accesspage;
已解释。
SQL> select * from table( dbms_xplan.display );
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 132K| 7888K| | 4612 |
| 1 | SORT GROUP BY | | 132K| 7888K| 18M| 4612 |
| 2 | TABLE ACCESS FULL | SYS_LOG_ACCESS | 132K| 7888K| | 183 |
--------------------------------------------------------------------------------
Note: cpu costing is off
已选择10行。
SQL> select * from table( dbms_xplan.display('PLAN_TABLE',null,'BASIC'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
------------------------------------------------
| Id | Operation | Name |
------------------------------------------------
| 0 | SELECT STATEMENT | |
| 1 | SORT GROUP BY | |
| 2 | TABLE ACCESS FULL | SYS_LOG_ACCESS |
------------------------------------------------
已选择8行。
参考pub论坛上的帖子
好了对于该包的使用就到此,但对于具体分析出来的信息如何正确的理解,还要继续学习~