影响CBO计算成本的参数通过对成本计算的影响,从而影响oracle对执行计划的选择。影响CBO计算成本的参数有很多,有2个最有影响力的:
optimizer_index_caching
optimizer_index_cost_adj
这两个参数是在oracle 9i对执行计划的优化开始发挥影响。数据库对这两个参数值都是使用默认值,应该进行调整。同时这两个参数的调整不仅是对windchill应用,对所有的OLTP应用甚至OLAP应用都有性能上的影响,只不过设置的标准不一样,要根据应用的具体情况来进行不同值的测试。下面就着重介绍一下这两个参数。
OPTIMIZER_INDEX_CACHING
该初始化参数表示一个百分比,0%~99%,缺省值0 ,对cbo来说,意味着0%的数据块(使用索引访问)可以在oracle的SGA的buffer cache中发现。即所有的对索引的访问都将需要物理读(每一个对buffer cache的逻辑读都产生一个对I/O子系统的物理读),也可以看作是:对buffer cache 0%的hit ratio。该参数只影响CBO计算访问索引块时候的成本,和涉及的表无关。
对一般的OLTP来说,OPTIMIZER_INDEX_CACHING 应该设成 90
OPTIMIZER_INDEX_COST_ADJ
该初始化参数也表示一个百分比,0~10000,表示索引访问的I/O开销相对于全表扫描的I/O开销。缺省值100 ,对cbo来说,表示索引访问的开销和全表扫描是等效的。(索引访问花费的时间和全表扫描花费的时间几乎是相等的。)
The default value of 100 indicates to the cost-based optimizer that indexed access is 100% as costly (i.e., equally costly) as FULL table scan access.
对于大多数的OLTP系统 OPTIMIZER_INDEX_COST_ADJ 的范围应该在10到50之间;而对于数据仓库或其他DSS, 就需要小心的设置成50。a valid value for OPTIMIZER_INDEX_COST_ADJ can easily be retrieved from the Oracle database itself. The answers lie in the V$SYSTEM_EVENT view, in the column AVERAGE_WAIT.After the database has been up and running normally for a sufficient period of time (i.e., a couple hours or more)下面有一个好方法用来确定如何设置该参数:
SQL>SELECT EVENT,AVERAGE_WAIT FROM V$SYSTEM_EVENT
WHERE EVENT LIKE ‘db file s%’;
This query will retrieve information on the two I/O wait events db file scattered reads (a.k.a. FULL table scans) and db file sequential reads (a.k.a. indexed scans). The AVERAGE_WAIT column contains the average timing, in 1/100ths of a second, of these events:
EVENT AVERAGE_WAITS
========================= ==============
db file sequential reads .33178629
db file scattered reads 2.190087
In this example, indexed scan I/O requests takes only 15% as long as each FULL table scan I/O request. So, set OPTIMIZER_INDEX_COST_ADJ to 15.
SQL>select .33178629/2.190087 from dual;
.33178629/2.190087
------------------
.151494571
设置OPTIMIZER_INDEX_COST_ADJ=15。