通過等待事件來獲得查詢SQl的執行計劃

oracle_ace發表於2008-01-17

網上找了一個SQL挺好用的特此記錄如下:
---------------------------------------------------------
set linesize 132
break on hash_value skip 1 dup
col child_number format 9999    heading 'CHILD'
col operation    format a55
col cost         format 99999
col kbytes       format 999999
col object       format a25
select hash_value,
       child_number,
       lpad(' ',2*depth)||operation||' '||options||decode(id, 0, substr(optimizer,1,6)||' Cost='||to_char(cost)) operation,
       object_name object,
       cost,
       cardinality,
       round(bytes / 1024) kbytes
from   v$sql_plan
where  hash_value in (select  a.sql_hash_value
                      from v$session a, v$session_wait b
                      where a.sid   = b.sid
                      and b.event = '&waitevent')
order by hash_value, child_number, id;
這樣我們可以根據等待事件來獲得具體SQl的執行計劃,在runtime的時候用比較方便。

以下是我生產環境裡的一個輸出計劃:
HASH_VALUE CHILD OPERATION                                               OBJECT                      COST CARDINALITY  KBYTES
---------- ----- ------------------------------------------------------- ------------------------- ------ ----------- -------
3267427106     0 UPDATE STATEMENT ALL_RO Cost=7231                                                   7231
3267427106     0   UPDATE                                                TS_FLPLNCMPNT
3267427106     0     TABLE ACCESS FULL                                   TS_FLPLNCMPNT               7231           1       0

那麼如果我想要查一下當前全表掃描的表都有那些,怎麼查呢?
select distinct object_name,object_owner from v$sql_plan p
where p.operation='TABLE ACCESS' and p.options='FULL'
and object_owner='&schema_owner';
這樣我們可以通過查詢v$sql_plan指定schema_owner來獲得那些進行過full table scan的表

如何獲得全索引掃描的物件呢?
select distinct object_name,object_owner from v$sql_plan p
where p.operation='INDEX' and p.options='FULL SCAN'
and object_owner='&schema_owner';

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12361284/viewspace-150441/,如需轉載,請註明出處,否則將追究法律責任。

相關文章