根据不同的指标获取TOP 10 SQL

select sql.*,
       (select SQL_TEXT
          from dba_hist_sqltext t
         where t.sql_id = sql.sql_id
           and rownum = 1) SQLTEXT
  from (select a.*,
               RANK() over(order by els desc) as r_els,
               RANK() over(order by phy desc) as r_phy,
               RANK() over(order by get desc) as r_get,
               RANK() over(order by exe desc) as r_exe,
               RANK() over(order by CPU desc) as r_cpu
          from (
                select sql_id,
                        sum(executions_delta) exe,
                        round(sum(elapsed_time_delta) / 1e6, 2) els,
                        round(sum(cpu_time_delta) / 1e6, 2) cpu,
                        round(sum(iowait_delta) / 1e6, 2) iow,
                        sum(buffer_gets_delta) get,
                        sum(disk_reads_delta) phy,
                        sum(rows_processed_delta) RWO,
                        round(sum(elapsed_time_delta) /
                              greatest(sum(executions_delta), 1) / 1e6,
                              4) elsp,
                        round(sum(cpu_time_delta) /
                              greatest(sum(executions_delta), 1) / 1e6,
                              4) cpup,
                        round(sum(iowait_delta) /
                              greatest(sum(executions_delta), 1) / 1e6,
                              4) iowp,
                        round(sum(buffer_gets_delta) /
                              greatest(sum(executions_delta), 1),
                              2) getp,
                        round(sum(disk_reads_delta) /
                              greatest(sum(executions_delta), 1),
                              2) phyp,
                        round(sum(rows_processed_delta) /
                              greatest(sum(executions_delta), 1),
                              2) ROWP
                  from dba_hist_sqlstat s
                --where snap_id between ... and ...
                 group by sql_id) a
        ) SQL
 where r_els <= 10
    or r_phy <= 10
    or r_cpu <= 10
 order by els desc

posted @ 2018-05-23 15:05  钱若梨花落  阅读(669)  评论(0编辑  收藏  举报