-
create table t1 as select * from dba_objects;
-
-
create index idx_t1 on t1(object_id);
-
-
exec dbms_stats.gather_table_stats('SYS','T1',estimate_percent=>100,no_invalidate=>false,cascade=>true,method_opt=>'for all columns size 1');
-
-
select count(*) from t1 where object_id between :x and :y;
-
-
select * from table(dbms_xplan.display_cursor(null,null,'advanced');
-
-
--使用绑定变量窥探后的cardinality和selectivity的计算方法:
-
cardinality = num_rows * selectivity
-
-
selectivity = ((y-x)/(high_value - low_value) + 2/num_distinct) * null_adjust
-
-
null_adjust = (num_rows - num_nulls)/num_rows
1.上述计算公司适用于启用了绑定变量窥探且where条件为“目标列between x and y”的selectivity和cardinality的计算,且x和y均处于目标列的low_value和high_value之间;
2.num_rows表示目标列所在表的记录数;
3.low_value和high_value分别表示目标列的最小值和最大值;
4.num_distinct表示目标列的distinct值的数量;
5.num_nulls表示目标列的null值的数量.