|
http://www.itpub.net/thread-1323402-1-1.html提到是否可以关闭data binds peeking功能,查了一下,有个隐含参数_optim_peek_user_binds,顺便做下测试,Oracle版本为10.2.0.4 IA64 Linux
SQL> create table t (id varchar2(10),text varchar2(4000));
表已创建。
SQL> insert into t select '1',object_name from dba_objects;
已创建92220行。
SQL> insert into t values( '2','aaa');
已创建 1 行。
SQL> commit;
提交完成。
SQL> select id,count(*) from t group by id;
ID COUNT(*)
---------- ----------
1 92220
2 1
SQL> create index t_idx on t(id);
索引已创建。
SQL> exec dbms_stats.gather_table_stats(user,'T',method_opt=>'for all indexed co
lumns',cascade=>true);
PL/SQL 过程已成功完成。
SQL> var fid varchar2;
SQL> exec :fid := '2';
PL/SQL 过程已成功完成。
SQL> select * from t where id=:fid;
ID
----------
TEXT
--------------------------------------------------------------------------------
2
aaa
SQL> select * from table(dbms_xplan.display_cursor(null));
SQL_ID fprdgayw5y5vq, child number 0
-------------------------------------
select * from t where id=:fid
Plan hash value: 470836197
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 1 (100)| |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 1 | 23 | 1 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID"=:FID)
已选择19行。
正常的binds peeking,由于2的选择度很高,采用索引扫描方式
SQL> alter session set "_optim_peek_user_binds"=false;
会话已更改。
SQL> select * from t where id=:fid;
ID
----------
TEXT
--------------------------------------------------------------------------------
2
aaa
SQL> select * from table(dbms_xplan.display_cursor(null));
SQL_ID fprdgayw5y5vq, child number 0
-------------------------------------
select * from t where id=:fid
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 85 (100)| |
|* 1 | TABLE ACCESS FULL| T | 92204 | 2070K| 85 (3)| 00:00:02 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"=:FID)
已选择18行。
看看10053的内容:
Table Stats::
Table: T Alias: T
#Rows: 94451 #Blks: 370 AvgRowLen: 23.00
Index Stats::
Index: T_IDX Col#: 1
LVLS: 1 #LB: 168 #DK: 2 LB/K: 84.00 DB/K: 181.00 CLUF: 363.00
***************************************
SINGLE TABLE ACCESS PATH
-----------------------------------------
BEGIN Single Table Cardinality Estimation
-----------------------------------------
*** 2010-07-08 16:24:44.912
** Performing dynamic sampling initial checks. **
** Dynamic sampling initial checks returning FALSE.
Column (#1): ID(VARCHAR2)
AvgLen: 2.00 NDV: 1 Nulls: 0 Density: 5.2937e-06
Histogram: Freq #Bkts: 1 UncompBkts: 5633 EndPtVals: 1
Table: T Alias: T
Card: Original: 94451 Rounded: 94451 Computed: 94451.00 Non Adjusted: 94451.00
-----------------------------------------
END Single Table Cardinality Estimation
-----------------------------------------
Access Path: TableScan
Cost: 84.71 Resp: 84.71 Degree: 0
Cost_io: 83.00 Cost_cpu: 23414153
Resp_io: 83.00 Resp_cpu: 23414153
Access Path: index (AllEqRange)
Index: T_IDX
resc_io: 531.00 resc_cpu: 37904105
ix_sel: 1 ix_sel_with_filters: 1 --受直方图影响,索引选择度变成了1
Cost: 213.51 Resp: 213.51 Degree: 1
Best:: AccessPath: TableScan
Cost: 84.71 Degree: 1 Resp: 84.71 Card: 94451.00 Bytes: 0
OutLine:
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('10.2.0.4')
OPT_PARAM('_optim_peek_user_binds' 'false')
OPT_PARAM('optimizer_dynamic_sampling' 4)
OPT_PARAM('optimizer_index_cost_adj' 40)
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "T"@"SEL$1")
END_OUTLINE_DATA
*/
看看使用HINT:
SQL> select /*+ OPT_PARAM('_optim_peek_user_binds' 'false') */ * from t where id=:fid;
ID
----------
TEXT
--------------------------------------------------------------------------------
2
aaa
SQL> select * from table(dbms_xplan.display_cursor(null));
SQL_ID d487pfc3jdsh8, child number 0
-------------------------------------
select /*+ OPT_PARAM('_optim_peek_user_binds' 'false') */ * from t
where id=:fid
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 85 (100)| |
|* 1 | TABLE ACCESS FULL| T | 92204 | 2070K| 85 (3)| 00:00:02 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("ID"=:FID)
已选择19行。
[ 本帖最后由 sundog315 于 2010-7-8 18:24 编辑 ] |
|