0

I'm using tables - dba_hist_sqlstat, dba_hist_snapshot and dba_hist_sqltext to get stats for groups of similar sql statements over the entire period of time since instance start up. I just found the same sql_id belonging to two different snapids (snapshots).

+-------+---------+---------------+-------------+---------------+--------------+--------------+
|SNAP_ID|DBID     |INSTANCE_NUMBER|SQL_ID       |PLAN_HASH_VALUE|OPTIMIZER_COST|OPTIMIZER_MODE|
+-------+---------+---------------+-------------+---------------+--------------+--------------+
|63618  |622294766|1              |0ps2wsx1rjv8q|2871982686     |4             |ALL_ROWS      |
|63522  |622294766|1              |0ps2wsx1rjv8q|2871982686     |4             |ALL_ROWS      |
+-------+---------+---------------+-------------+---------------+--------------+--------------+

So, is a "group by sql_id" sufficient ? should i group by "sql_text" ? Is there a better way ?

[UPDATE]

Here is the query i've written so far -

 select
         dh_sql.sql_id,
         dh_sql.plan_hash_value,
         dh_sql.parsing_schema_name,
         dh_sql.module,
         trunc(dh_snap.end_interval_time) "DATE",
         max(dh_sql.snap_id),
         max(dh_sql.dbid),
         sum(dh_sql.executions_delta),
         .
         .
         .
         .
 from
         dba_hist_sqlstat dh_sql,
         dba_hist_snapshot dh_snap
 where
         dh_sql.snap_id = dh_snap.snap_id
         and dh_snap.begin_interval_time > to_date(?, 'MM/DD/YYYY')
         and dh_snap.begin_interval_time < to_date(?, 'MM/DD/YYYY') + 1
         and dh_sql.executions_delta > 0
         and dh_sql.module is not null
 group by
         dh_sql.sql_id,
         dh_sql.plan_hash_value,
         dh_sql.parsing_schema_name,
         dh_sql.module,
         trunc(dh_snap.end_interval_time)
4

0 に答える 0