Oracle直方圖 32位元組限制

csbin發表於2014-01-26

1、建立測試表

create table t as 
select rownum rn,
       object_name,
       rpad('*', 32, '*') || object_type object_type
  from all_objects
 where rownum <= 10000;
   
select object_type ,count(1) from t group by object_type;

 

2、收集統計資訊

begin 
  dbms_stats.gather_table_stats(user,
                                'T',
                                method_opt => 'FOR COLUMNS object_type SIZE 254');
end;
/

select *
  from t
 where object_type = '********************************TABLE';

3、檢視直方圖

select table_name,
       column_name,
       --endpoint_value,
       --endpoint_number,
       endpoint_actual_value,
       endpoint_number - lag(endpoint_number, 1, 0) over(order by endpoint_number) as frequency
  from user_tab_histograms
 where table_name = 'T'
 --and endpoint_number > 0
 --and endpoint_actual_value is not null
 order by 1, 2, 4;

 

image

4、更新列,收集統計資訊,查詢直方圖

update t set object_type = substr(object_type, 2);

image

從上面的結果看,oracle直方圖的取值,僅取32位。

如果前32位相同,收集直方圖後,oracle會認為是相同的,導致生成錯誤的執行計劃。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/720091/viewspace-1075475/,如需轉載,請註明出處,否則將追究法律責任。

相關文章