density和selective值相等,但不是每个环境下都相等,有前提条件:没直方图、加非null比例
如下是对frequency频率直方图的查询:
以上条件都有可能load histogram,另外ROB使用直方图,而CBO不使用。
12c之后可能最大桶数变为508,甚至更大。
对于大批量的insert、update操作后,有必要收集直方图及统计信息,因为这些信息时静态的。
字符超过32位不在直方图上体现,数字和日期在直方图上被精确 体现。
Popular and non-popular是height histgram高度直方图的值。
假设没有直方图,查询同一个列的不同值,实际上分布是不均匀的,例如一个值有100万记录,一个值有1条记录,该列上同时存在索引,但是两个列查询都使用全表扫描,原因是cbo不知道对应列值得分布,selective=(100万+1)/2,cob就认为走全表好,原因就是没有收集直方图信息。但是,同时在该sql执行一段时间后,由于谓词条件是该列的过滤条件,oracle知道该列做过谓词,oracle在自动收集统计信息时会收集关于该列的统计信息及直方图信息。
高度平衡直方图除了第一个和最后一个列外,中间高度基本一样。
NDV<=最大桶数buckets 254个时使用频率直方图;但当你指定要收集的的直方图buckets不等于NDV时,即NDV<=采样的直方图BUCKETS,且NDV<=最大桶数buckets 254,cbo仍会使用频率直方图,而当NDV>采样的直方图BUCKETS,即使NDV<=最大桶数buckets 254,CBO将会使用Height Balanced Histogram高度平衡直方图。
Frequency Histogram(Value-Based )?频率直方图,每个列都对应一个桶。
高度直方图相邻的桶数相减大于1即为popular流行值,流行值得奇数算法为:相邻桶数相减/总得桶数*原始基数(Card: Origina)
POPVALCNT(popular value count):
select count(*) PopValCnt from (select
endpoint_number,hexstr(endpoint_value) endstr,
endpoint_number- lag( endpoint_number,1,0) over (order by
endpoint_number ) as buckets from dba_tab_histograms where
table_name='DATA_SKEW_HB' and column_name='SOURCE')
end_diff where buckets>1;
POPVALCNT
----------
11
PopBktCnt(popular bucket count):
select sum(buckets) PopValCnt from (select
endpoint_number,hexstr(endpoint_value) endstr,
endpoint_number- lag( endpoint_number,1,0) over (order by
endpoint_number ) as buckets from dba_tab_histograms where
table_name='DATA_SKEW_HB' and column_name='SOURCE')
end_diff where buckets>1;
POPVALCNT
----------
229
select endpoint_number,
hexstr(endpoint_value) endstr,
endpoint_number - lag(endpoint_number, 1, 0) over(order by endpoint_number)
as rows_cnt
from dba_tab_histograms
where table_name = 'DATA_SKEW'
and column_name = 'SOURCE';