ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 最浪费内存的前10 个语句占所有语句的比例

最浪费内存的前10 个语句占所有语句的比例

原创 Linux操作系统 作者:golden_zhou 时间:2011-09-16 15:28:58 0 删除 编辑
在没有调整的情况下,大多数系统中10 个最常使用的SQL 语句的访问量占了整个系统中内存读操作
的50%以上。本节测量了最影响性能的代码对整个系统所造成危害的严重性,以百分比表示。
获得这个百分比的脚本
set serverout on
DECLARE
CURSOR c1 is
select buffer_gets
from v$sqlarea
order by buffer_gets DESC;
CURSOR c2 is
select sum(buffer_gets)
from v$sqlarea;
sumof10 NUMBER:=0;
mybg NUMBER;
mytotbg NUMBER;
BEGIN
dbms_output.put_line('Percent');
dbms_output.put_line('-------');
OPEN c1;
FOR i IN 1..10 LOOP
FETCH c1 INTO mybg;
sumof10 := sumof10 + mybg;
END
LOOP;
CLOSE c1;
OPEN c2;
FETCH c2 INTO mytotbg;
CLOSE c2;
dbms_output.put_line(sumof10/mytotbg*100);
END;
/
338
示例输出
percent
-------
44.07087097075974761701818030622745652422
PL/SQL procedure successfully completed.
另一个SQL 语句,但速度更快一点(仅运行于Oracle 9i 和10g 中)
select sum(pct_bufgets) "Percent"
from (select rank() over ( order by buffer_gets desc ) as rank_bufgets,
to_char(100 * ratio_to_report(buffer_gets) over (), '999.99') pct_bufgets
from v$sqlarea )
where rank_bufgets < 11;
Percent
----------
44.03

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/25198367/viewspace-707721/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-03-09

  • 博文量
    238
  • 访问量
    344444