喜欢就来多看看
cost(2)
上一篇 /
下一篇 2006-10-24 00:00:00
/ 个人分类:RDBMS
大家也可以在9i的performance tuning guide and reference里面看到同样的公式:
According to the CPU costing model:
Cost = (
#SRds * sreadtim +
#MRds * mreadtim +
#CPUCycles / cpuspeed
) / sreadtim
where
#SRDs - number of single block reads
#MRDs - number of multi block reads
#CPUCycles - number of CPU Cycles
sreadtim - single block read time
mreadtim - multi block read time
cpuspeed - CPU cycles per second
The cost is the time spent on single-block reads, plus the time spent on multiblock reads, plus the CPU time required, all divided by the time it takes to do a single-block read. Which means the cost is the total predicted execution time for the statement, expressed in units of the single-block read time.
在Oracle9i里,当为一个SQL选择执行计划的时候,Oracle可以预测出执行这个SQL需要多少个单块读取,多少个多块读取,多少次CPU操作。那么我们怎么知道"每个单块读的时间","每个多块读的时间" 和"CPU速度"呢,很简单:通过统计信息,不过这不是我们常说的表的统计信息或schema的统计信息,而是Oracle9i里面才开始有的(8i里面没有哦,所以8i的cost只能考虑单块读:)),叫做system statistics。对于system
statistics的统计我们可以在系统正常workload的时候执行:
execute dbms_stats.gather_system_stats('start')
execute dbms_stats.gather_system_stats('stop')
来统计start和stop期间的系统的真实情况,
也可以手工指定一个确定的值:
begin
dbms_stats.set_system_stats('CPUSPEED',500);
dbms_stats.set_system_stats('SREADTIM',5.0);
dbms_stats.set_system_stats('MREADTIM',30.0);
dbms_stats.set_system_stats('MBRC',12);
end;
/
alter system flush shared_pool;
由于手工指定system statistics不会影响当前shared pool里面的数据,所以如果要想使shared pool里面现有的SQL重新计算执行计划,我们需要flush shared pool。
这里CPUSPEED就是我们告诉Oracle的CPU的速度:500M/s,即500,000,000个操作/秒
SREADTIM就是single block read time,单位是milliseconds,千分之一秒
MREADTIM就是multi-block read time,单位是milliseconds,千分之一秒
MBRC是typical multiblock read size,单位是block,
导入论坛
引用链接
收藏
分享给好友
推荐到圈子
管理
举报
TAG: