在没有调整的情况下,大多数系统中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
的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博客 ” ,链接:http://blog.itpub.net/25198367/viewspace-707721/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/25198367/viewspace-707721/