`
MicroJoey
  • 浏览: 87072 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Histogram

阅读更多
1,Viewing Histograms
Column statistics may be stored as histograms. These histograms provide accurate estimates of the distribution of column data. Histograms provide improved selectivity estimates in the presence of data skew, resulting in optimal execution plans with nonuniform data distributions.

列的统计信息有可能包含柱状图.柱状图提供列数据的精确分布的情况.它在列数据倾斜的时提供更加的选择性评估,从而使optimizer能够选择出正确的执行计划.

Oracle uses two types of histograms for column statistics: height-balanced histograms and frequency histograms. The type of histogram is stored in the HISTOGRAM column of the *TAB_COL_STATISTICS views (USER and DBA). This column can have values of HEIGHT BALANCED, FREQUENCY, or NONE.

2,Height-Balanced Histograms
In a height-balanced histogram, the column values are divided into bands so that each band contains approximately the same number of rows. The useful information that the histogram provides is where in the range of values the endpoints fall.

Consider a column C with values between 1 and 100 and a histogram with 10 buckets. If the data in C is uniformly distributed, then the histogram looks similar to Figure 14-1, where the numbers are the endpoint values.

Figure 14-1 height-Balanced Histogram with Uniform Distribution


Description of "Figure 14-1 height-Balanced Histogram with Uniform Distribution"


The number of rows in each bucket is one tenth the total number of rows in the table. Four-tenths of the rows have values that are between 60 and 100 in this example of uniform distribution.

If the data is not uniformly distributed, then the histogram might look similar to Figure 14-2.

Figure 14-2 height-Balanced Histogram with Non-Uniform Distribution


Description of "Figure 14-2 height-Balanced Histogram with Non-Uniform Distribution"


In this case, most of the rows have the value 5 for the column. Only 1/10 of the rows have values between 60 and 100.

Height-balanced histograms can be viewed using the *TAB_HISTOGRAMS tables, as shown in Example 14-1.



3,Viewing Height-Balanced Histogram Statistics

BEGIN
  DBMS_STATS.GATHER_table_STATS (OWNNAME => 'OE', TABNAME => 'INVENTORIES', 
  METHOD_OPT => 'FOR COLUMNS SIZE 10 quantity_on_hand');
END;
/

SELECT column_name, num_distinct, num_buckets, histogram 
  FROM USER_TAB_COL_STATISTICS
 WHERE table_name = 'INVENTORIES' AND column_name = 'QUANTITY_ON_HAND';

COLUMN_NAME                    NUM_DISTINCT NUM_BUCKETS HISTOGRAM
------------------------------ ------------ ----------- ---------------
QUANTITY_ON_HAND                        237          10 HEIGHT BALANCED

SELECT endpoint_number, endpoint_value 
  FROM USER_HISTOGRAMS
 WHERE table_name = 'INVENTORIES' and column_name = 'QUANTITY_ON_HAND'
  ORDER BY endpoint_number;

ENDPOINT_NUMBER ENDPOINT_VALUE
--------------- --------------
              0              0
              1             27
              2             42
              3             57
              4             74
              5             98
              6            123
              7            149
              8            175
              9            202
             10            353
In the query output, one row corresponds to one bucket in the histogram.




Demo

SQL> alter session set statistics_level=all;

Session altered.

SQL> create table his
  2  as
  3  select rownum id,'a'||rownum from dba_objects
  where rownum<20001;

Table created.

SQL> create index his_idx_id on his(id);

Index created.

SQL> exec dbms_stats.gather_table_stats('u01','his',
method_opt=>'FOR ALL INDEXED COLUMNS size 254');


--用skewonly时,oracle不会收集histogram,因为oracle认为该列的数据分布均匀.
exec dbms_stats.gather_table_stats('u01','his',
method_opt=>'FOR ALL INDEXED COLUMNS size skewonly');


PL/SQL procedure successfully completed.

SQL> set lin 120
SQL> select * from his where id=10;

        ID NAME
---------- -----------------------------------------
        10 a10

SQL> select * from table(dbms_xplan.display_cursor
(null,null,'last allstats'));

PLAN_TABLE_OUTPUT
--------------------------------------------------
SQL_ID  75pauyhkmn80u, child number 0
-------------------------------------
select * from his where id=10

Plan hash value: 2080926353

--------------------------------------------------
| Id  | Operation                   | Name       |
--------------------------------------------------
|   1 |  TABLE ACCESS BY INDEX ROWID| HIS        |
|*  2 |   INDEX RANGE SCAN          | HIS_IDX_ID |--使用index正确

PLAN_TABLE_OUTPUT
--------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("ID"=10)


18 rows selected.

SQL> update his set id=10 where id<19996;

19995 rows updated.

SQL> commit;

Commit complete.

SQL> exec dbms_stats.gather_table_stats('u01','his',
method_opt=>'FOR ALL INDEXED COLUMNS size 254');--柱状图统计信息已经修改

PL/SQL procedure successfully completed.

SQL> select * from his where id=10;

19995 rows selected.

SQL> select * from table(dbms_xplan.display_cursor
(null,null,'last allstats'));

PLAN_TABLE_OUTPUT
--------------------------------------------------
SQL_ID  75pauyhkmn80u, child number 0
-------------------------------------
select * from his where id=10

Plan hash value: 2080926353

PLAN_TABLE_OUTPUT
--------------------------------------------------
| Id  | Operation                   | Name       |
--------------------------------------------------
|   1 |  TABLE ACCESS BY INDEX ROWID| HIS        |
|*  2 |   INDEX RANGE SCAN          | HIS_IDX_ID |--execution plan不对
--------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access("ID"=10)


18 rows selected.

按道理说,如下3种情况都会导致execution plan失效:
a.alter system flush shared_pool;
b.对语句中的对象做个ddl ;
c.重新收集统计信息

然而通过above lab发现没有导致execution plan 失效,只能采取如下方式导致它失效,看optimizer是否可以做出正确的choose.

SQL> alter system flush shared_pool;

System altered.

SQL> select * from his where id=10;


19995 rows selected.

SQL> select * from table(dbms_xplan.display_cursor
(null,null,'last allstats'));

PLAN_TABLE_OUTPUT
------------------------------------------------
SQL_ID  75pauyhkmn80u, child number 0
-------------------------------------
select * from his where id=10

Plan hash value: 4154987155

PLAN_TABLE_OUTPUT
----------------------------------
| Id  | Operation         | Name |
----------------------------------
|*  1 |  TABLE ACCESS FULL| HIS  |---正确的选择
----------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("ID"=10)


17 rows selected.


  


  
分享到:
评论

相关推荐

    基于Matlab直方图Histogram的人脸识别程序-Processed histogram based Face Recognition.part3.rar

    基于Matlab直方图Histogram的人脸识别程序-Processed histogram based Face Recognition.part3.rar 基于Matlab 直方图Histogram的人脸识别程序 因为数据库图片太大,所以分成几个压缩文件。 Face ...

    基于Matlab直方图Histogram的人脸识别程序-Processed histogram based Face Recognition.part2.rar

    基于Matlab直方图Histogram的人脸识别程序-Processed histogram based Face Recognition.part2.rar 基于Matlab 直方图Histogram的人脸识别程序 因为数据库图片太大,所以分成几个压缩文件。 Face ...

    前端开源库-histogram

    《前端开源库-histogram:构建柱状图的艺术》 在前端开发中,数据可视化是至关重要的,它能够帮助用户快速理解和解析复杂的数据信息。而柱状图作为一种常见且直观的图表类型,被广泛应用于各种场景,如数据分析、...

    Histogram1D.rar

    《使用Histogram1D实现图像直方图与对比度调整》 在数字图像处理领域,直方图和对比度调整是两个至关重要的概念。本程序"Histogram1D.rar"旨在提供一个与ImageJ软件类似的功能,它能够显示图像的直方图,并对图像的...

    ADC Histogram_labview_

    本项目“ADC Histogram_labview_”显然关注的是利用LabVIEW来处理ADC(模拟数字转换器)数据,并创建直方图进行数据分析。ADC是将连续的模拟信号转换为离散的数字信号的关键组件,常见于各种电子设备中,如数据采集...

    Stochastic_Histogram_HTF - MetaTrader 5脚本.zip

    《MetaTrader 5中的Stochastic Histogram HTF:深入解析与应用》 MetaTrader 5(MT5)是一款广泛应用于外汇、期货和股票交易市场的交易平台,它提供了丰富的技术分析工具和自定义指标,使得交易者能够根据自己的...

    Gray Histogram

    在给定的“Gray Histogram”项目中,显然我们聚焦于视频帧的灰度值统计,利用了OpenCV库的2.2版本。OpenCV是一个广泛使用的计算机视觉库,提供了丰富的图像和视频处理功能。 首先,让我们来了解一下灰度图像。在...

    Exp_CCI_Histogram - MetaTrader 5EA.zip

    《基于MetaTrader 5的CCI_Histogram交易系统详解》 在金融市场的交易世界里,智能交易系统(Expert Advisor,简称EA)是自动化交易策略的重要工具,它能够帮助交易者实现无需人工干预的自动买卖。本文将详细介绍名...

    SpearmanRankCorrelation_Histogram_HTF - MetaTrader 5脚本.zip

    《MetaTrader 5中的Spearman Rank Correlation Histogram技术分析》 Spearman Rank Correlation Histogram,即斯皮尔曼等级相关直方图,是一种在金融交易领域中用于度量两个变量之间线性关系强度和方向的技术指标。...

    matlab开发-Histogram2D

    在MATLAB中,`Histogram2D`是一种可视化工具,用于绘制二维直方图,它可以将大量数据点在平面上按照网格分布进行统计,形成一种表示数据分布情况的图形。这种图表在数据分析、图像处理和科学计算等领域有着广泛的...

    ColorSTD_Histogram_HTF - MetaTrader 5脚本.zip

    《MetaTrader 5中的ColorSTD_Histogram_HTF脚本详解》 MetaTrader 5(MT5)是一款全球广泛使用的外汇交易和分析平台,其强大的功能和丰富的技术指标库深受交易者喜爱。今天我们将深入探讨一个名为"ColorSTD_...

    结合实例深入讲解oracle中的直方图histogram

    ### 结合实例深入讲解Oracle中的直方图Histogram #### 一、直方图的基本概念 直方图是一种统计图表,在多种领域中都有广泛的应用,它并非Oracle数据库所独有的功能。直方图通常用来描绘一组数据的分布情况,通过一...

    hutc-Vertical Histogram 代码参考

    ### hutc-Vertical Histogram 代码解析 #### 一、代码概览 本代码实现了一个简单的垂直直方图绘制功能,其主要目的是统计输入字符串中大写字母出现的次数,并以直方图的形式输出这些统计数据。这里使用的编程语言...

    Histogram Equalization_HistogramEqualizati_

    直方图均衡化(Histogram Equalization)是一种在图像处理领域中广泛应用的技术,它通过改变图像的灰度级分布,使得图像的整体亮度和对比度得到显著提升。这种方法特别适用于那些原始直方图分布不均匀,或者暗部和亮...

    XCCI_Histogram_Vol_Direct - MetaTrader 5脚本.zip

    《XCCI_Histogram_Vol_Direct - MetaTrader 5脚本》是一款专为MetaTrader 5交易平台设计的技术分析工具。该脚本的核心是XRSI_Histogram_Vol指标,它结合了RSI(相对强弱指数)和成交量的特征,通过在直方图上用彩色...

    CCI_Histogram_Vol - MetaTrader 5脚本.zip

    本篇文章将详细探讨一个名为"CCI_Histogram_Vol"的MetaTrader 5脚本,它巧妙地将商品通道指数(Commodity Channel Index, CCI)振荡器与交易量结合,形成了一种直观的颜色直方图,以帮助交易者更好地理解和利用市场...

    DRAW_COLOR_HISTOGRAM2 - MetaTrader 5脚本.zip

    《DRAW_COLOR_HISTOGRAM2 - MetaTrader 5 脚本详解》 在金融交易领域,MetaTrader 5(MT5)是一个广泛使用的交易平台,它提供了丰富的技术分析工具和编程语言MQL5,用于创建自定义指标和交易机器人。本篇文章将详细...

    Histogram of Oriented Gradient

    **直方图定向梯度(Histogram of Oriented Gradients,HOG)** 直方图定向梯度是一种在计算机视觉和图像处理中广泛使用的特征提取方法,由Dalal和Triggs在2005年提出。它主要用于行人检测,但后来也被应用于其他...

    Histogram Equalization直方图均衡化

    直方图均衡化(Histogram Equalization)是一种图像处理技术,主要目的是增强图像的对比度,使其在视觉上更加鲜明。这种技术尤其适用于低对比度图像,通过改变像素的强度分布来改善图像的整体视觉效果。 首先,我们...

    alexf_histogram_demo源码

    "alexf_histogram_demo"是一个基于C++编写的源码示例,主要展示了如何实现直方图的绘制功能。这个项目包含了一系列的源文件和工程配置文件,为学习和理解C++编程,特别是图形用户界面(GUI)开发以及数据可视化提供...

Global site tag (gtag.js) - Google Analytics