如何在存储执行中,查询某条sql语句的执行计划。

如何在存储执行中,查询某条sql语句的执行计划。


方法很简单就是先在V$SQLAREA中找到这个SQL,然后得到SQL_ID,去V$SQL_PLAN去看它执行的计划
示例如下:

先根据sql语句查找sql_id
select *
  from V$SQLAREA sr
 where sr.SQL_TEXT like 'INSERT INTO T_BILLINVOICEDETAIL%'
 order by sr.FIRST_LOAD_TIME desc;

--再根据sql_id查找执行计划
select * from V$SQL_PLAN pa where pa.SQL_ID = '6c8y8nuysajcf';
或者下面这个更直观些:

select '--------------------------------------------------------------------------------'
from dual
union all
select '| Operation | PHV/Object Name | Rows | Bytes| Cost |' as "Optimizer Plan:"
from dual
union all
select '--------------------------------------------------------------------------------'
from dual
union all
select *
from (select rpad('|' || substr(lpad(' ', 1 * (depth - 1)) || operation ||
decode(options, null, '', ' ' || options),
1,
62),
63,
' ') || '|' ||
rpad(decode(id,
0,
'----- ' || to_char(hash_value) || ' -----',
substr(decode(substr(object_name, 1, 7),
'SYS_LE_',
null,
object_name) || ' ',
1,
20)),
21,
' ') || '|' ||
lpad(decode(cardinality,
null,
' ',
decode(sign(cardinality - 10000),
-1,
cardinality || ' ',
decode(sign(cardinality - 1000000),
-1,
trunc(cardinality / 1000) || 'K',
decode(sign(cardinality - 1000000000),
-1,
trunc(cardinality / 1000000) || 'M',
trunc(cardinality / 1000000000) || 'G')))),
7,
' ') || '|' ||
lpad(decode(bytes,
null,
' ',
decode(sign(bytes - 1024),
-1,
bytes || ' ',
decode(sign(bytes - 1048576),
-1,
trunc(bytes / 1024) || 'K',
decode(sign(bytes - 1073741824),
-1,
trunc(bytes / 1048576) || 'M',
trunc(bytes / 1073741824) || 'G')))),
6,
' ') || '|' ||
lpad(decode(cost,
null,
' ',
decode(sign(cost - 10000000),
-1,
cost || ' ',
decode(sign(cost - 1000000000),
-1,
trunc(cost / 1000000) || 'M',
trunc(cost / 1000000000) || 'G'))),
8,
' ') || '|' as "Explain plan"
from v$sql_plan
where SQL_ID='6c8y8nuysajcf')
union all
select '--------------------------------------------------------------------------------'
from dual;


至于如何强迫变更执行计划,再继续探索!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值