快速查询sql的执行计划的方法
方法一:使用autotrace的方法
SQL> conn scott/scott
Connected.
SQL> set autotrace trace explain
SQL> select count(*) from emp;
Execution Plan
----------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id
| Operation
| Name
| Rows
| Cost (%CPU)| Time
|
-------------------------------------------------------------------
|
0 | SELECT STATEMENT |
|
1 |
1
(0)| 00:00:01 |
|
1 |
SORT AGGREGATE
|
|
1 |
|
|
|
2 |
INDEX FULL SCAN| PK_EMP |
14 |
1
(0)| 00:00:01 |
-------------------------------------------------------------------
SQL> set autotrace off
方法二:使用dbms_xplan包
SQL> explain plan for select count(1) from emp;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id
| Operation
| Name
| Rows
| Cost (%CPU)| Time
|
-------------------------------------------------------------------
|
0 | SELECT STATEMENT |
|
1 |
1
(0)| 00:00:01 |
|
1 |
SORT AGGREGATE
|
|
1 |
|
|
|
2 |
INDEX FULL SCAN| PK_EMP |
14 |
1
(0)| 00:00:01 |
-------------------------------------------------------------------
9 rows selected.
总结:以上两种方法都能够快速查看sql的执行计划,set autotrace方法要求每次查询以后设置为off,否则下次想得到查询结果时,会出现只给出执行计划。如果只是查看执行计划,个人觉得dbms_xplan包的方法更方便;至于读者喜欢哪种方法,那就仁者见仁,智者见智啦。
方法一:使用autotrace的方法
SQL> conn scott/scott
Connected.
SQL> set autotrace trace explain
SQL> select count(*) from emp;
Execution Plan
----------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id
-------------------------------------------------------------------
|
|
|
-------------------------------------------------------------------
SQL> set autotrace off
方法二:使用dbms_xplan包
SQL> explain plan for select count(1) from emp;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 2937609675
-------------------------------------------------------------------
| Id
-------------------------------------------------------------------
|
|
|
-------------------------------------------------------------------
9 rows selected.
总结:以上两种方法都能够快速查看sql的执行计划,set autotrace方法要求每次查询以后设置为off,否则下次想得到查询结果时,会出现只给出执行计划。如果只是查看执行计划,个人觉得dbms_xplan包的方法更方便;至于读者喜欢哪种方法,那就仁者见仁,智者见智啦。