[PT]Column Histogram Statistics
(The descirption is from Oracle Document: Performance Tuning)
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.
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.
Height-Balanced HistogramsIn 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.
Frequency HistogramsIn a frequency histogram, each value of the column corresponds to a single bucket of the histogram. Each bucket contains the number of occurrences of that single value. Frequency histograms are automatically created instead of height-balanced histograms when the number of distinct values is less than or equal to the number of histogram buckets specified.
A test about histogram
SQL> create table hist_test(cola NUMBER, colb VARCHAR2(10));
表已建立。
SQL> begin
2 <
3 for i in 1..20 loop
4 <
5 for j in 1..i loop
6 insert into hist_test values(i,'TEST');
7 end loop inner;
8 end loop outer;
9 end;
10 /
PL/SQL 過程已成功完成。
SQL> select count(*) from hist_test;
COUNT(*)
----------
210
SQL> select dbms_stats.get_param('METHOD_OPT') from dual;
DBMS_STATS.GET_PARAM('METHOD_OPT')
------------------------------------
FOR ALL COLUMNS SIZE AUTO
SQL> exec dbms_stats.gather_table_stats(ownname=>'YCHEN',tabname=>'HIST_TEST');
PL/SQL 過程已成功完成。
SQL> SELECT column_name, num_distinct, num_buckets, histogram
2 FROM USER_TAB_COL_STATISTICS
3 WHERE table_name = 'HIST_TEST';
COLUM NUM_DISTINCT NUM_BUCKETS HISTOGRAM
----- ------------ ----------- ---------------
COLA 20 1 NONE
COLB 1 1 NONE
SQL> SELECT column_name, endpoint_number, endpoint_value
2 FROM USER_TAB_HISTOGRAMS
3 WHERE table_name= 'HIST_TEST'
4 ORDER BY column_name, endpoint_number;
COLUM ENDPOINT_NUMBER ENDPOINT_VALUE
----- --------------- --------------
COLA 0 1
COLA 1 20
COLB 0 4.3756E+35
COLB 1 4.3756E+35
SQL> exec dbms_stats.gather_table_stats(ownname=>'YCHEN',tabname=>'HIST_TEST',me
thod_opt=>'FOR COLUMNS SIZE 10 COLA');
PL/SQL 過程已成功完成。
SQL> SELECT column_name, num_distinct, num_buckets, histogram
2 FROM USER_TAB_COL_STATISTICS
3 WHERE table_name = 'HIST_TEST' and column_name = 'COLA';
COLUM NUM_DISTINCT NUM_BUCKETS HISTOGRAM
----- ------------ ----------- ---------------
COLA 20 10 HEIGHT BALANCED
SQL> SELECT column_name, endpoint_number, endpoint_value
2 FROM USER_TAB_HISTOGRAMS
3 WHERE table_name= 'HIST_TEST' and column_name = 'COLA'
4 ORDER BY column_name, endpoint_number;
COLUM ENDPOINT_NUMBER ENDPOINT_VALUE
----- --------------- --------------
COLA 0 1
COLA 1 7
COLA 2 9
COLA 3 11
COLA 4 13
COLA 5 15
COLA 6 16
COLA 7 17
COLA 8 18
COLA 9 19
COLA 10 20
已選擇11行。
SQL> exec dbms_stats.gather_table_stats(ownname=>'YCHEN',tabname=>'HIST_TEST',me
thod_opt=>'FOR COLUMNS SIZE 30 COLA');
PL/SQL 過程已成功完成。
SQL> SELECT column_name, num_distinct, num_buckets, histogram
2 FROM USER_TAB_COL_STATISTICS
3 WHERE table_name = 'HIST_TEST' and column_name = 'COLA';
COLUM NUM_DISTINCT NUM_BUCKETS HISTOGRAM
----- ------------ ----------- ---------------
COLA 20 20 FREQUENCY
SQL> SELECT column_name, endpoint_number, endpoint_value
2 FROM USER_TAB_HISTOGRAMS
3 WHERE table_name= 'HIST_TEST' and column_name = 'COLA'
4 ORDER BY column_name, endpoint_number;
COLUM ENDPOINT_NUMBER ENDPOINT_VALUE
----- --------------- --------------
COLA 1 1
COLA 3 2
COLA 6 3
COLA 10 4
COLA 15 5
COLA 21 6
COLA 28 7
COLA 36 8
COLA 45 9
COLA 55 10
COLA 66 11
COLA 78 12
COLA 91 13
COLA 105 14
COLA 120 15
COLA 136 16
COLA 153 17
COLA 171 18
COLA 190 19
COLA 210 20
已選擇20行。
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8558093/viewspace-1022264/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle Column Group StatisticsOracle
- Oracle 12C Statistics on Column GroupsOracle
- [轉] oracle統計資訊(statistics)和直方圖(histogram)Oracle直方圖Histogram
- table column histogram .親自實驗檢驗得出的學習筆記。Histogram筆記
- Histogram總結Histogram
- about histogram(2)Histogram
- about histogram(1)Histogram
- 【Mysql】pt工具之-pt-killMySql
- Database StatisticsDatabase
- DELETE STATISTICSdelete
- Error: no such columnError
- percona-toolkit 之 【pt-summary】、【pt-mysql-summary】、【pt-config-diff】、【pt-variable-advisor】說明MySql
- histogram與10053(zt)Histogram
- Histogram Investigation(轉自kamus)Histogram
- histogram一點研究(待整理)Histogram
- Statistics related viewView
- Time Model Statistics
- oracle之StatisticsOracle
- Import parameter: STATISTICSImport
- Saving Original Statistics and Gathering New Statistics
- SciTech-Mathematics-Probability+Statistics-7 Key Statistics Concepts
- pt-table-checksum與pt-table-sync使用實踐
- Column Monitoring
- elasticsearch 聚合之 date_histogram 聚合ElasticsearchHistogram
- elasticsearch 之 histogram 直方圖聚合ElasticsearchHistogram直方圖
- SciTech-Mathmatics-Probability+Statistics-VI-Statistics:Quantifing Uncertainty + Regression Analysis)AI
- How restore CBO statisticsREST
- Explain for the Statistics of Execution PlanAI
- Statistics and Data Analysis for BioinformaticsORM
- SciTech-Statistics-英語授課:Business Statistics商務統計
- Index column size too large. The maximum column size is 767 bytesIndex
- Hibernate 註解@Column(nullable = false) 和 @Column(unique=true)NullFalse
- CSS column-spanCSS
- CSS column-gapCSS
- CSS column-ruleCSS
- MAX or MIN of Indexed ColumnIndex
- oracle直方圖histogram小記(一)Oracle直方圖Histogram
- 轉貼oracle直方圖histogram(二)Oracle直方圖Histogram