Oracle预估的基数算法
2014-02-19 22:09
369 查看
SQL> create table t as select * from dba_objects; Table created. SQL> create index idx_t on t(object_id); Index created. SQL> BEGIN 2 DBMS_STATS.GATHER_TABLE_STATS(ownname => 'TEST', 3 tabname => 'T', 4 estimate_percent => 100, 5 method_opt => 'for all columns size auto', 6 degree => DBMS_STATS.AUTO_DEGREE, 7 cascade => TRUE); 8 END; 9 / SQL> alter session set optimizer_features_enable='9.2.0'; Session altered. SQL> explain plan for select owner from t where object_id<1000; Explained. SQL> select * from table(dbms_xplan.display()); PLAN_TABLE_OUTPUT ------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------- Plan hash value: 1594971208 --------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost | --------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 958 | 10538 | 26 | | 1 | TABLE ACCESS BY INDEX ROWID| T | 958 | 10538 | 26 | |* 2 | INDEX RANGE SCAN | IDX_T | 958 | | 4 | --------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("OBJECT_ID"<1000) Note ----- - cpu costing is off (consider enabling it) 18 rows selected. 那么这个958 Oracle是怎么估算的呢? Oracle预估的基数等于有效选择性*(num_rows-num_nulls) 其中 有效选择性 ,< 的有效选择性算法为: (limit-low_value)/(high_value-low_value) set linesize 200 SQL> select b.num_rows, a.num_distinct, a.num_nulls, utl_raw.cast_to_number(high_value) high_value, utl_raw.cast_to_number(low_value) low_value, (b.num_rows - a.num_nulls) "NUM_ROWS-NUM_NULLS", utl_raw.cast_to_number(high_value) - utl_raw.cast_to_number(low_value) "HIGH_VALUE-LOW_VALUE" from dba_tab_col_statistics a, dba_tables b where a.owner = b.owner and a.table_name = b.table_name and a.owner = 'TEST' and a.table_name = upper('T') and a.column_name = 'OBJECT_ID'; 2 3 4 5 6 7 8 9 10 11 12 13 14 NUM_ROWS NUM_DISTINCT NUM_NULLS HIGH_VALUE LOW_VALUE NUM_ROWS-NUM_NULLS HIGH_VALUE-LOW_VALUE ---------- ------------ ---------- ---------- ---------- ------------------ -------------------- 73964 73964 0 77085 2 73964 77083 那么估算为: SQL> select ceil((1000-2)/77083*73964) from dual;SQL> CEIL((1000-2)/77083*73964) -------------------------- 958 Oracle 就是根据这个算法的
相关文章推荐
- Oracle预估的基数算法
- 基数统计算法狗年旺旺旺
- 第16周项目1-验证算法(8)基数排序
- 五种常用基数估计算法效果实验及实践建议
- 基础数据结构算法_计数排序,基数排序,桶排序
- 用oracle写的二分算法
- 基数排序 算法
- oracle 小计,合计的算法
- 算法记录:MSD基数排序 + qsort 对字符串排序
- 算法导论 第8章 线性时间排序(计数排序、基数排序、桶排序)
- 第16周项目1-验证算法(8)基数排序
- 第16周项目1-验证算法(8)基数排序
- 基于左右值的无限级分类算法-oracle实现--04
- oracle 查询计划中的基数cardinality概念
- 第十六周--项目5算法验证基数排序
- 使用过滤统计信息解决基数预估错误
- oracle exp不生成dumpfile,预估出实际导出文件的大小。
- 第十六周项目1--验证算法--(8)基数排序
- 第十五周项目1-验证算法-基数排序
- 第十六周项目1-验证算法(8)基数排序