SQL ordered by Reads(源码)
2011-11-22 11:44
218 查看
select *
from (select sqt.dskr,
sqt.exec,
decode(sqt.exec, 0, to_number(null), (sqt.dskr / sqt.exec)),
(100 * sqt.dskr) /
(SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = &beg_snap
AND E.SNAP_ID = &end_snap
AND B.DBID = &DBID
AND E.DBID = &DBID
AND B.INSTANCE_NUMBER = &INST_NUM
AND E.INSTANCE_NUMBER = &INST_NUM
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') norm_val,
nvl((sqt.cput / 1000000), to_number(null)),
nvl((sqt.elap / 1000000), to_number(null)),
sqt.sql_id,
decode(sqt.module, null, null, 'Module: ' || sqt.module),
nvl(st.sql_text, to_clob('** SQL Text Not Available **'))
from (select sql_id,
max(module) module,
sum(disk_reads_delta) dskr,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) elap
from dba_hist_sqlstat
where dbid = &dbid
and instance_number = &inst_num
and &beg_snap < snap_id
and snap_id <= &end_snap
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = &dbid
and (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = &beg_snap
AND E.SNAP_ID = &end_snap
AND B.DBID = &DBID
AND E.DBID = &DBID
AND B.INSTANCE_NUMBER = &INST_NUM
AND E.INSTANCE_NUMBER = &INST_NUM
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') > 0
order by nvl(sqt.dskr, -1) desc, sqt.sql_id)
where rownum < 65and(rownum <= 10
or norm_val > 1)
---------------------------------------------------实际应用的SQL--------------------------------------------------------
select *
from (select sqt.dskr "Physical Reads",
sqt.exec,
decode(sqt.exec, 0, to_number(null), (sqt.dskr / sqt.exec)) "Reads per Exec",
(100 * sqt.dskr) /
(SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 08')
AND E.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 18')
AND B.DBID = 911569205
AND E.DBID = 911569205
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') "%Total",
nvl((sqt.cput / 1000000), to_number(null)) "CPU Time (s)",
nvl((sqt.elap / 1000000), to_number(null)) "Elapsed Time (s)",
sqt.sql_id,
decode(sqt.module, null, null, 'Module: ' || sqt.module) "SQL Module",
nvl(st.sql_text, to_clob('** SQL Text Not Available **')) "SQL Text"
from (select sql_id,
max(module) module,
sum(disk_reads_delta) dskr,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) elap
from dba_hist_sqlstat
where dbid = 911569205
and instance_number = 1
and snap_id >
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 08')
and snap_id <=
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 18')
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = 911569205
and (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 08')
AND E.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 18')
AND B.DBID = 911569205
AND E.DBID = 911569205
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') > 0
order by nvl(sqt.dskr, -1) desc, sqt.sql_id)
where rownum < 65and(rownum <= 10
or "%Total" > 1)
from (select sqt.dskr,
sqt.exec,
decode(sqt.exec, 0, to_number(null), (sqt.dskr / sqt.exec)),
(100 * sqt.dskr) /
(SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = &beg_snap
AND E.SNAP_ID = &end_snap
AND B.DBID = &DBID
AND E.DBID = &DBID
AND B.INSTANCE_NUMBER = &INST_NUM
AND E.INSTANCE_NUMBER = &INST_NUM
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') norm_val,
nvl((sqt.cput / 1000000), to_number(null)),
nvl((sqt.elap / 1000000), to_number(null)),
sqt.sql_id,
decode(sqt.module, null, null, 'Module: ' || sqt.module),
nvl(st.sql_text, to_clob('** SQL Text Not Available **'))
from (select sql_id,
max(module) module,
sum(disk_reads_delta) dskr,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) elap
from dba_hist_sqlstat
where dbid = &dbid
and instance_number = &inst_num
and &beg_snap < snap_id
and snap_id <= &end_snap
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = &dbid
and (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID = &beg_snap
AND E.SNAP_ID = &end_snap
AND B.DBID = &DBID
AND E.DBID = &DBID
AND B.INSTANCE_NUMBER = &INST_NUM
AND E.INSTANCE_NUMBER = &INST_NUM
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') > 0
order by nvl(sqt.dskr, -1) desc, sqt.sql_id)
where rownum < 65and(rownum <= 10
or norm_val > 1)
---------------------------------------------------实际应用的SQL--------------------------------------------------------
select *
from (select sqt.dskr "Physical Reads",
sqt.exec,
decode(sqt.exec, 0, to_number(null), (sqt.dskr / sqt.exec)) "Reads per Exec",
(100 * sqt.dskr) /
(SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 08')
AND E.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 18')
AND B.DBID = 911569205
AND E.DBID = 911569205
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') "%Total",
nvl((sqt.cput / 1000000), to_number(null)) "CPU Time (s)",
nvl((sqt.elap / 1000000), to_number(null)) "Elapsed Time (s)",
sqt.sql_id,
decode(sqt.module, null, null, 'Module: ' || sqt.module) "SQL Module",
nvl(st.sql_text, to_clob('** SQL Text Not Available **')) "SQL Text"
from (select sql_id,
max(module) module,
sum(disk_reads_delta) dskr,
sum(executions_delta) exec,
sum(cpu_time_delta) cput,
sum(elapsed_time_delta) elap
from dba_hist_sqlstat
where dbid = 911569205
and instance_number = 1
and snap_id >
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 08')
and snap_id <=
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 18')
group by sql_id) sqt,
dba_hist_sqltext st
where st.sql_id(+) = sqt.sql_id
and st.dbid(+) = 911569205
and (SELECT sum(e.VALUE) - sum(b.value)
FROM DBA_HIST_SYSSTAT b, DBA_HIST_SYSSTAT e
WHERE B.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 08')
AND E.SNAP_ID =
(select snap_id
from DBA_HIST_SNAPSHOT
where to_char(end_interval_time, 'yyyymmdd hh24') =
'20111121 18')
AND B.DBID = 911569205
AND E.DBID = 911569205
AND B.INSTANCE_NUMBER = 1
AND E.INSTANCE_NUMBER = 1
and e.STAT_NAME = 'physical reads'
and b.stat_name = 'physical reads') > 0
order by nvl(sqt.dskr, -1) desc, sqt.sql_id)
where rownum < 65and(rownum <= 10
or "%Total" > 1)
相关文章推荐
- How to Interpret the "SQL ordered by Physical Reads (UnOptimized)" Section in AWR (文档 ID 1466035.1)
- Oracle 通过AWR的SQL ordered by Gets和SQL ordered by Reads诊断问题
- 用SQL生成awr报表中的“SQL ordered by Elapsed Time” 部分
- Scripts:找出磁盘读最多的SQL的脚本 perf_top_sql_by_disk_reads.sql
- SQL ordered by Version Count
- 用SQL生成awr报表中的“SQL ordered by Elapsed Time” 部分
- 《Microsoft SQL Server 2008 Analysis Services Step by Step》学习笔记十三:实施安全
- 《Microsoft SQL Server 2008 Analysis Services Step by Step》学习笔记十七:管理分区及数据库处理(下)
- android SQLite数据库组装sql的源码
- sql server group by 分组带sum avg求和需要注意的一点
- 《Microsoft SQL Server 2008 Analysis Services Step by Step》学习笔记十四:设计聚合(Aggregation)(上)
- DbHelperSQL.cs数据访问抽象基础类Copyright (C) 2004-2008 By LiTianPing
- mybatis源码分析(1)——SqlSessionFactory实例的产生过程
- Get GMT time from timestamp by SQL
- 简单的优化处理 By LINQ TO SQL
- Microsoft ASP.NET MVC Preview 5 及LINQ TO SQL最新版开发示例演示(提供源码下载)
- SQL学习--group by
- sql的insert语句自动生成器_c#源码
- 如何高效快速地优化MySQL、SQL语句(附源码)
- This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法