执行计划
程序员文章站
2022-05-07 12:09:37
...
如果你知道要查看那一条SQL语句的执行计划,可以直接查询V$sql视图,比如: select a.SQL_ID, a.CHILD_NUMBER from v$sql a where a.SQL_TEXT like '%cm_cost where pk_cost%' 查询到这两字段之后,
直接通过一个dbms_xplan包的display_cursor函数就能查看这条SQL的执行计划,
如下所示:
select * from table(dbms_xplan.display_cursor('7ngvh44anxzx1', 0))
mehod 2:
set pagesize 20;
set linesize 100;
set autotrace on explain 只显示查询结果和执行计划
set autotrace on statistic 只显示查询结果统计信息
set autotrace on 显示前两者
set autotrace traceonly 不显示查询结果,只显示执行计划和统计信息
set autotrace off 关闭跟踪
set feedback on
set trimspool on
set pool c:/text.txt
set pool off;
之所以说这个视图很重要,是因为该视图中有一列是在awrsqrpt报告中没有的。这一列就是 filter_predicates列。
SELECT plan_hash_value,
TO_CHAR(RAWTOHEX(child_address)),
TO_NUMBER(child_number),
id,
LPAD(' ', DEPTH) || operation operation,
options,
object_owner,
object_name,
optimizer,
cost,
access_predicates,
filter_predicates
FROM V$SQL_PLAN
WHERE sql_id = 'bkcyk7bf380t6'
ORDER BY 1, 3, 2, 4;
重点关注optimizer列,filter_predicates列。
若是该sql不在shared pool中时,改为执行如下的sql:
set linesize 500
set pagesize 500
col plan_hash_value format 9999999999
col id format 999999
col operation format a30
col options format a15
col object_owner format a15
col object_name format a20
col optimizer format a15
col cost format 9999999999
col access_predicates format a15
col filter_predicates format a15
SELECT plan_hash_value,
id,
LPAD (' ', DEPTH) || operation operation,
options,
object_owner,
object_name,
optimizer,
cost,
access_predicates,
filter_predicates
FROM dba_hist_sql_plan
WHERE sql_id = 'fahv8x6ngrb50'
ORDER BY plan_hash_value, id