2012年4月14日土曜日

V$SQL_PLAN

V$SQLから調査したいSQLを探し出した後、ADDRESS、HASH_VALUEやSQL_IDでV$SQL_PLANから実行計画を取得し、整形するスクリプト(小田さんのページから借用)

【パターン①】
column id format 999 newline
column operation format a20
column options format a15
column object_name format a22 trunc
column optimizer format a3 trunc


select id
, lpad (' ', depth) || operation operation
, options
, object_name
, optimizer
, cost
from v$sql_plan
where hash_value = &hash_value
and address = '&address'
start with id = 0
connect by
(prior id = parent_id
and prior hash_value = hash_value
and prior child_number = child_number
)
order siblings by id, position;


【パターン②】
column id format 999 newline
column operation format a20
column options format a15
column object_name format a22 trunc
column optimizer format a3 trunc


select id
, lpad (' ', depth) || operation operation
, options
, object_name
, optimizer
, cost
from v$sql_plan
where sql_id = &sql_id
start with id = 0
connect by (prior id = parent_id
and prior sql_id = sql_id
and prior child_number = child_number
)
order siblings by id, position;

2012年4月3日火曜日

test (file)

結構忘れているよなー

test expression
[ expression ]

-r  file    fileが「読み取り可」ならば真
-w file    fileが「書き込み可」ならば真
-x file    fileが「実行可」ならば真
-f  file    fileが「普通のファイル」ならば真
-d  file    fileが「ディレクトリ」ならば真
-s  file    fileが「0より大きいサイズ」ならば真

!             NOT(否)の意味。「この直後の判定が偽」なら真
-a          AND(かつ)。「この前後の判定がどちらも真」なら真
-o     OR(または)。「この前後の判定のどちらかが真」なら真

sample

[ -r file -a w file -a ! -x file ]
   fileが読み書き可能で実行不可の場合に真