oracle如何产生sql 执行计划(二)
2013-09-23 23:43
513 查看
oracle如何产生sql 执行计划(二)
今天是2013-09-23,之前写过一篇笔记是《oracle如何产生sql执行计划(一)》,那么除了这一种方法以外其实还有两种(据我所知)。今天就看看另外另种:
一、explain plan sql
该语句可以对sql直接执行计划,执行的计划存储在表plan_table这张表中,但这太繁琐了,每个表的字段需要自己定义。
我习惯使用dbms_xplan这个软件包,
看一下这个包的介绍:
The
DBMS_XPLANpackage provides an easy way to display the output of the
EXPLAIN
PLANcommand in several, predefined formats. You can also use the
DBMS_XPLANpackage to display the plan of a statement stored in the Automatic Workload Repository (AWR) or stored in a SQL tuning set. It further provides a way to display
the SQL execution plan and SQL execution runtime statistics for cached SQL cursors based on the information stored in the
V$SQL_PLANand
V$SQL_PLAN_STATISTICS_ALLfixed views. Finally, it displays plans from a SQL plan baseline.
然后看一下这个包的函数有哪些:
DISPLAY- to format and display the contents of a plan table.
DISPLAY_AWR- to format and display the contents of the execution plan of a stored SQL statement in the AWR.
DISPLAY_CURSOR- to format and display the contents of the execution plan of any loaded cursor.
DISPLAY_SQL_PLAN_BASELINE- to display one or more execution plans for the SQL statement identified by SQL handle
DISPLAY_SQLSET- to format and display the contents of the execution plan of statements stored in a SQL tuning set.
我常用的两个如下。
1)displan :格式化然后显示执行计划
eg:
SQL> explain plan for 2 select * from amy_emp; Explained. SQL> SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------ Plan hash value: 320686012 ----------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 14 | 532 | 3 (0)| 00:00:01 | | 1 | TABLE ACCESS FULL| AMY_EMP | 14 | 532 | 3 (0)| 00:00:01 | ----------------------------------------------------------------------------- 8 rows selected. SQL>
2)、DISPLAY_CURSOR:这个函数显示了在加载到内存中的所有cursor执行计划,除此之外还有一些统计信息如(i/0,memory,timing):
该函数定义:
DBMS_XPLAN.DISPLAY_CURSOR( sql_id IN VARCHAR2 DEFAULT NULL, cursor_child_no IN NUMBER DEFAULT 0, format IN VARCHAR2 DEFAULT 'TYPICAL');
eg:
参考:http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_xplan.htm#CACFJGHG
我可以在执行完一条语句之后直接使用该函数:
QL> select * from amY_dept where deptno>20; DEPTNO DNAME LOC ---------- -------------- ------------- 30 SALES CHICAGO 40 OPERATIONS BOSTON SQL> select * from table(dbms_xplan.display_cursor); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- SQL_ID 8rpwwabhbasvn, child number 0 ------------------------------------- select * from amY_dept where deptno>20 Plan hash value: 3336059312 ------------------------------------------------------------------------------ | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------ | 0 | SELECT STATEMENT | | | | 4 (100)| | |* 1 | TABLE ACCESS FULL| AMY_DEPT | 3 | 60 | 4 (0)| 00:00:01 | ------------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("DEPTNO">20) 18 rows selected. SQL>
相关文章推荐
- oracle如何产生sql 执行计划(一)
- 【转】如何查看oracle sql执行计划
- Oracle 数据库如何搜集指定SQL的执行计划和解决过程中的ORA-00904错误
- ORACLE的执行计划之如何产生执行计划
- oracle如何分析sql执行计划
- [Oracle]如何查看SQL的执行计划 - DBMS_XPLAN Package
- Oracle如何查看SQL实际执行计划
- 如何查看oracle sql执行计划 .
- Oracle 11g如何清除share pool中某条SQL的执行计划
- 如何分析ORACLE的SQL执行计划
- 如何查看oracle sql执行计划
- Oracle技术之如何使用ordered提示改变SQL执行计划
- 如何查看oracle sql执行计划
- oracle sql的执行计划如何查看
- Oracle 如何根据动态性能视图来查看某条SQL语句的执行计划
- oracle如何获得客户端sql执行计划以便优化sql(三)
- 查看Oracle执行计划的几种方法 / oracle中DateTime类型的字段,建立索引后,查寻时索引如何生效?/ oracle 中sql语句怎么加多个强制索引
- oracle sql_plan 执行计划
- Oracle查看SQL语句的执行计划
- 多种方法查看Oracle SQL执行计划