日期:2014-05-16 浏览次数:20368 次
SQL> select count(*) from dba_objects; COUNT(*) ---------- 11345 Execution Plan ---------------------- Plan hash value: 2598313856 -------------------------------------------- --------------- | Id | Operation | Name | Rows | Bytes | Cost (%C PU)| Time | -------------------------------------------- --------------- | 0 | SELECT STATEMENT | | 1 | | 38 (6)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | | | | | 2 | VIEW | DBA_OBJECTS | 10010 | | 38 (6)| 00:00:01 | | 3 | UNION-ALL | | | | | | |* 4 | FILTER | | | | | | |* 5 | HASH JOIN | | 11645 | 398K| 35 (6)| 00:00:01 | | 6 | TABLE ACCESS FULL | USER$ | 32 | 96 | 2 (0)| 00:00:01 | |* 7 | TABLE ACCESS FULL | OBJ$ | 11645 | 363K| 32 (4)| 00:00:01 | |* 8 | TABLE ACCESS BY INDEX ROWID| IND$ | 1 | 8 | 2 (0)| 00:00:01 | |* 9 | INDEX UNIQUE SCAN | I_IND1 | 1 | | 1 (0)| 00:00:01 | | 10 | NESTED LOOPS | | 3 | 18 | 3 (0)| 00:00:01 | | 11 | INDEX FULL SCAN | I_LINK1 | 3 | 9 | 1 (0)| 00:00:01 | | 12 | TABLE ACCESS CLUSTER | USER$ | 1 | 3 | 1 (0)| 00:00:01 | |* 13 | INDEX UNIQUE SCAN | I_USER# | 1 | | 0 (0)| 00:00:01 | doc的前半句话不能很好的理解,不知道它要表述什么意思? 反正我们只需要看第三列"|"和语句对比,看哪个语句动作缩的 越靠右侧就先执行它,如果存在相同的则谁在前面就执行谁,根据这个 指导原则,计划的执行顺序如下: 6,7,5,9,8,4,11,13,12,10,3,2,1,0 --=============================== SQL> select sql_id,sql_text from v$sql where sql_text like '%select count(*) fro m dba_objects%'; SQL_ID ------------- SQL_TEXT -------------------------------------------- gxk8zvq0j02z8 select sql_id,sql_text from v$sql where sql_text like '%select count(*) from dba _objects%' 1jhx4zbub8uw3 select * from v$sql where sql_text like '%select count(*) from dba_objects%' 8vcrngun00v6g select sql_id,sql_text from v$sql where sql_text like '%select count(*) from dba SQL_ID ------------- SQL_TEXT -------------------------------------------- _objects%' g4pkmrqrgxg3b select count(*) from dba_objects 08bm3s8hxudu7 EXPLAIN PLAN SET STATEMENT_ID='PLUS886' FOR select count(*) from dba_objects SQL> --=============================== SQL> select id,parent_id from v$sql_plan where sql_id='g4pkmrqrgxg3b'; ID PARENT_ID ---------- ---------- 0 1 0 2 1 3 2 4 3 5 4 6 5 7 5 8 4 9 8 10 3 ID PARENT_ID ---------- ---------- 11 10 12 10 13 12 14 rows selected. SQL> 9i的执行计划显示出来的是2列数字: 看起来就更容易了: 先从最上面看id,之后赵它的parent_id,如此下去直到找不到 parent_id,那么就先执行这个id,遇到具有相同parent_id的则谁 在前面执行谁,按照这种方法排列的顺序如下 6,7,5,9,8,4,11,13,12,10,3,2,1,0 其实我们可以根据id和parent_id画一颗树,然后按照中序(应该是中序吧) 遍历这颗树即可?