我正在使用表 - dba_hist_sqlstat、dba_hist_snapshot 和 dba_hist_sqltext 来获取自实例启动以来整个时间段内相似 sql 语句组的统计信息。我刚刚发现属于两个不同快照(快照)的相同 sql_id。
+-------+---------+---------------+-------------+---------------+--------------+--------------+
|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 |
+-------+---------+---------------+-------------+---------------+--------------+--------------+
那么,“按 sql_id 分组”就足够了吗?我应该按“sql_text”分组吗?有没有更好的办法 ?
[更新]
这是我到目前为止写的查询 -
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)