本文的编写得到枯荣长老的大力帮助,在此表示感谢。
本文适用的Oracle db版本为oracle 10g或者更高版本.
之所以说这个视图很重要,是因为该视图中有一列是在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 a15SELECT 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;
重点关注filter_predicates列。--这一列能帮助判断不走索引的原因。这一列的查询结果若是为null,那就是正常的。若是不为null,那就需要额外关注不为空的原因,如下图所示: