Question

Hello I found strange situation with some sql_ids statistics in a view dba_hist_sqlstat. Those seem to have nonzero elapsed time values when execution values are equal zero. I don't understand how it is possible. Maybe during situations when session is inactive or there is a wait event. Have you ever have similar situation and what can this mean ?

select sql_id, plan_hash_value, snap_id, sum(executions_delta), sum(elapsed_time_delta) from dba_hist_sqlstat group by sql_id, plan_hash_value, snap_id having sum(executions_delta) = 0;

SQL_ID        PLAN_HASH_VALUE SNAP_ID SUM(EXECUTIONS_DELTA) SUM(ELAPSED_TIME_DELTA)
------------- --------------- ------- --------------------- -----------------------        
0v3dvmc22qnam               0   14212                     0                     116 
cfz686a6qp0kg                   14223                     0                       0 
7ng34ruy5awxq                   14203                     0                       0 
b07vcvuxryvg9      2129701755   14219                     0                       0 
czvfg1255s5zg       775635102   14202                     0                       0 
b07vcvuxryvg9                   14209                     0                       0 
cfz686a6qp0kg                   14201                     0                       0 
b07vcvuxryvg9      2129701755   14201                     0                       0 
5rxbazwmcdfaz               0   14202                     0                    1263 
Was it helpful?

Solution

A long-running query that spans multiple snapshots will appear to have execution time without any executions, if you only look at a single snapshot. Otherwise the sum of EXECUTIONS_DELTA would be incorrect.

In one session, create a table and start a long-running query:

create table test3 as
select level a from dual connect by level <= 100000;

select count(*) from test3 cross join test3 cross join test3;

While that's running, open another session and create multiple snapshots:

begin
    dbms_workload_repository.create_snapshot;
    dbms_lock.sleep(5);
    dbms_workload_repository.create_snapshot;
end;
/

Use V$SQL to find the SQL_ID, but it will be the same as below if you use the exact same text as above. The query execution is only counted in one snapshot, but the time is recorded in two snapshots.

select sql_id, plan_hash_value, snap_id,
    sum(executions_delta),
    sum(elapsed_time_delta)
from dba_hist_sqlstat
where sql_id = '09pgf63pczkxg'
group by sql_id, plan_hash_value, snap_id;

SQL_ID        PLAN_HASH_VALUE SNAP_ID SUM(EXECUTIONS_DELTA) SUM(ELAPSED_TIME_DELTA)
09pgf63pczkxg 3377121179      5570    1                     22001734
09pgf63pczkxg 3377121179      5571    0                      6010267
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top