[oracle@jumper oracle]$ sqlplus eqsp/eqsp
SQL*Plus: Release 9.2.0.3.0 - Production on Thu Nov 20 23:13:20 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production
准备试验数据
SQL>
SQL>
SQL> drop table t;
Table dropped.
SQL> create table t as select 1 id,a.* from dba_objects a;
Table created.
SQL> insert into t select * from t;
10168 rows created.
SQL> /
20336 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from t;
COUNT(*)
----------
40672
SQL> update t set id = 99 where rownum <2; --构造试验数据,id=99的纪录只有一条.其余id=1
1 row updated.
SQL> commit;
Commit complete.
SQL> create index t_ind1 on t(id);
Index created.
SQL> analyze table t compute statistics for table for all indexed columns;
Table analyzed.
SQL> exit
测试脚本
[oracle@jumper oracle]$ vi eygle.sql
set term off
set head off
alter session set sql_trace = true;
select * from t where id = :v;
alter session set sql_trace = false;
~
~
~
"eygle.sql" [ò?×a??] 6L, 131C ò?D′è?
[oracle@jumper oracle]$ more eygle2.sql
set term off
set head off
alter session set sql_trace = true;
select * from t n_1 where id = :v;
alter session set sql_trace = false;
第一步测试:
SQL> var v number SQL> exec :v :=1 ---传入参数为1 ,此时Oracle应该放弃索引,使用全表扫描
PL/SQL procedure successfully completed.
SQL> @$ORACLE_BASE/eygle.sql
[oracle@jumper udump]$ tkprof *.trc e1.log
TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:49:28 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
[oracle@jumper udump]$ vi e1.log
TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:49:28 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
******************************************************************************** count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call ********************************************************************************
Misses in library cache during parse: 0 Optimizer goal: CHOOSE Parsing user id: 96 ********************************************************************************
TKPROF: Release 9.2.0.3.0 - Production on Thu Nov 20 23:50:44 2003
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
[oracle@jumper udump]$ vi e2.log
cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call ********************************************************************************
Misses in library cache during parse: 0 Optimizer goal: CHOOSE Parsing user id: 96 ********************************************************************************
Connected to: Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production With the Partitioning, OLAP and Oracle Data Mining options JServer Release 9.2.0.3.0 - Production
******************************************************************************** count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call ********************************************************************************
Misses in library cache during parse: 0 Optimizer goal: CHOOSE Parsing user id: 96 ********************************************************************************
Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: 96
index scan is right here.
Rows Row Source Operation ------- --------------------------------------------------- 99 TABLE ACCESS BY INDEX ROWID T (cr=18 r=1 w=0 time=1963 us) 99 INDEX RANGE SCAN T_IND1 (cr=9 r=1 w=0 time=1264 us)(object id 13674)
******************************************************************************** count = number of times OCI procedure was executed cpu = cpu time in seconds executing elapsed = elapsed time in seconds executing disk = number of physical reads of buffers from disk query = number of buffers gotten for consistent read current = number of buffers gotten in current mode (usually for update) rows = number of rows processed by the fetch or execute call ********************************************************************************
Misses in library cache during parse: 0 Optimizer goal: CHOOSE Parsing user id: 96 ********************************************************************************
Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: 96
Rows Row Source Operation ------- --------------------------------------------------- 99 TABLE ACCESS BY INDEX ROWID T (cr=18 r=1 w=0 time=1963 us) 99 INDEX RANGE SCAN T_IND1 (cr=9 r=1 w=0 time=1264 us)(object id 13674)
请问盖老师
绑定变量的这个问题现在已经开始严重影响到我们的系统。
最开始所有的查询都是使用的绑定变量。随着数据量的增多,第一次窥视出来的结果已经不能满足每次查询。导致特定值时查询很快,其他值时查询慢的一沓糊涂。
为了解决这个问题。我们用动态SQL重写了大约5%的最常用查询语句。查询速度倒是提高了不少,但是用TOAD看SQL AREA HIT RATE 居然降低到了6X%。。
那么您认为这个问题在10.2.0上有什么好的解决方法呢(升级到11g就先不考虑了)
可以动态写程序,计算统计信息的选择行,然后在执行的前加HINT。