有关Oracle 的执行计划说明,参考我的Blog:
Oracle Explain Plan
一. 查看当前session 的SID
SYS@anqing1(rac1)> SELECT USERENV('SID') FROM DUAL;
USERENV('SID')
--------------
137
SYS@anqing1(rac1)> SELECT SID FROM V$MYSTAT WHERE ROWNUM =1;
SID
----------
137
二. 查看缓存中的Explain Plan
1)根据SID,从v$sql中找到相应SQL的HASH_VALUE和ADDRESS
/* Formatted on 2011/6/20 17:38:20 (QP5 v5.163.1008.3004) */
SELECT a.sql_text, a.address, a.hash_value
FROM v$sql a, v$session b
WHERE a.hash_value = b.sql_hash_value AND b.sid = &sid;
2)根据hash_value和address的值,从v$sql_plan中找到真实的执行计划
/* Formatted on 2011/6/20 17:39:22 (QP5 v5.163.1008.3004) */
SET LINE 200;
COL oper FORMAT a100;
SELECT LPAD (oper, LENGTH (oper) + LEVEL * 2, ' ') oper, cost
FROM (SELECT object_name || ':' || operation || ' ' || options AS oper,
cost,
id,
parent_id
FROM v$sql_plan
WHERE hash_value = '&hash_value' AND address = '&address')
START WITH id = 0
CONNECT BY PRIOR id = parent_id;
如: