You are on page 1of 1

AWR - historical execution plan investigation

Sometimes you will receive complains from users that something that has been run
ning ok for ages on a production server, suddenly is running very very slowly.
In 10g, AWR gives you the ability to go and check and possibly compare the execu
tion path of a query at different times in the past.
select DBID, SQL_ID, SQL_TEXT from dba_hist_sqltext where sql_text like %your que
ry%;
DBID | SQL_ID | SQL_TEXT |
-+-++1234567890|12345xxxxxxxx|UPDATE STAGING SET BLAH |
We know that yesterday it was running fine, but today its not, and users have con
firmed that data volumes are identical between the two dates
select s.begin_interval_time, s.end_interval_time , q.snap_id, q.dbid, q.sql_id,
q.plan_hash_value, q.optimizer_cost, q.optimizer_mode
from dba_hist_sqlstat q, dba_hist_snapshot s
where q.dbid =
and q.sql_id =
and q.snap_id = s.snap_id
and s.begin_interval_time between sysdate-2 and sysdate
order by s.snap_id desc;
When you find this, take note of the PLAN_HASH_VALUE from the 2 different times
that you want to compare
Actually the 3 parameters that you need are:
DBID
SQL_ID
PLAN_HASH_VALUE
And to check the execution plan, run the following query:
select id, operation, options, object_name, cost
from dba_hist_sql_plan
where dbid =
and sql_id =
and plan_hash_value =
compare that with the second one
select id, operation, options, object_name, cost
from dba_hist_sql_plan
where dbid =
and sql_id =
and plan_hash_value =

You might also like