12
返回列表 发新帖
楼主: wei-xh

[FAQ] ORACLE的直方图的一些试验

[复制链接]
论坛徽章:
2
2010新春纪念徽章
日期:2010-03-01 11:06:122011新春纪念徽章
日期:2011-02-18 11:43:32
11#
发表于 2011-6-24 13:56 | 只看该作者
SQL> col table_name format a20
SQL> col column_name format a20
SQL> col endpoint_number format a20
SQL> col endpoint_value format a20
SQL> set numwidth 5;
SQL> SELECT table_name,column_name,endpoint_number,endpoint_value FROM U
HISTOGRAMS WHERE TABLE_NAME='TAB';

TABLE_NAME           COLUMN_NAME          ENDPOINT_NUMBER ENDPOINT_VALUE
-------------------- -------------------- --------------- --------------
TAB                  B                         ##########     ##########
TAB                  B                         ##########     ##########

为啥sqlplus是###,请教各位

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
12#
发表于 2011-6-25 00:49 | 只看该作者
> 为啥sqlplus是###

set numw 12

12 should be big enough.

Yong Huang

使用道具 举报

回复
论坛徽章:
1
2011新春纪念徽章
日期:2011-02-18 11:43:35
13#
发表于 2012-6-20 15:07 | 只看该作者
wei-xh 发表于 2010-5-8 14:08
在看看等高直方图的情况。
BEGIN
  DBMS_STATS.GATHER_TABLE_STATS(OWNNAME    => 'SCOTT',

hi,
我测试你例子时trace了下,如下:
***************************************
BASE STATISTICAL INFORMATION
***********************
Table Stats::
  Table: TAB  Alias: TAB
    #Rows: 10000  #Blks:  20  AvgRowLen:  6.00
Index Stats::
  Index: IX_TAB_B  Col#: 2
    LVLS: 1  #LB: 20  #DK: 10  LB/K: 2.00  DB/K: 1.00  CLUF: 19.00
***************************************
SINGLE TABLE ACCESS PATH
  Column (#2): B(NUMBER)
    AvgLen: 4.00 NDV: 10 Nulls: 0 Density: 0.9982 Min: 1 Max: 10000
    Histogram: HtBal  #Bkts: 8  UncompBkts: 8  EndPtVals: 3
  Table: TAB  Alias: TAB     
    Card: Original: 10000  Rounded: 9982  Computed: 9982.01  Non Adjusted: 9982.01
  Access Path: TableScan
    Cost:  6.21  Resp: 6.21  Degree: 0
      Cost_io: 6.00  Cost_cpu: 2342429
      Resp_io: 6.00  Resp_cpu: 2342429
  Access Path: index (AllEqRange)
    Index: IX_TAB_B
    resc_io: 39.00  resc_cpu: 3972296
    ix_sel: 0.9982  ix_sel_with_filters: 0.9982
    Cost: 39.35  Resp: 39.35  Degree: 1
  Best:: AccessPath: TableScan
         Cost: 6.21  Degree: 1  Resp: 6.21  Card: 9982.01  Bytes: 0

tom一篇文章这样写的。
The Selectivity for popular values is calculated as the number of end points
spanned by that value divided by the total number of end points. Formula:

    Selectivity =     Number of end points spanned by this value
                  ------------------------------------------
                   total number of end points

那么如果按这个观点,
select * from tab where b=5;
占据了7个桶,也就是说selectivity=7/8=0.875
user_tab_columns里density确实是0.9982,trace出来ix_sel是0.9982,计算出来的card是9982,不知道是否研究过怎么算的?

使用道具 举报

回复
论坛徽章:
9
ITPUB9周年纪念徽章
日期:2010-10-08 09:31:22奥运会纪念徽章:游泳
日期:2012-07-19 16:38:15奥运会纪念徽章:篮球
日期:2012-10-18 09:31:28奥运会纪念徽章:田径
日期:2012-10-19 10:00:44复活蛋
日期:2013-02-18 15:53:36迷宫蛋
日期:2013-03-05 10:32:55沸羊羊
日期:2015-02-21 23:08:28处女座
日期:2016-02-09 23:01:49妮可·罗宾
日期:2022-02-22 16:23:25
14#
发表于 2012-9-7 17:50 | 只看该作者
那一般收集统计的时候,method_opt =>'for all columns size auto',使用这个方法,是不是一个列的唯一值超过254个值,就是等高直方图,不超过254,就是等频直方图呢...

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
15#
发表于 2012-9-8 00:24 | 只看该作者
本帖最后由 Yong Huang 于 2012-9-7 10:25 编辑

> 那一般收集统计的时候,method_opt =>'for all columns size auto',使用这个方法,是不是一个列的唯一值超过254个值,就是等高直方图,不超过254,就是等频直方图呢...

The type of a histogram is determined by not just the number of distinct values, but also the number of buckets. But I don't know the algorithm of that "size auto" in terms of how many buckets it creates.

I checked the definition of xxx_tab_col_statistics in 10g to see how it determines which of the two types of histogram. See part 2 of
http://yong321.freeshell.org/oranotes/Histogram.html

Although documentation says "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", I see no way to create a histogram with >= 255 buckets. So, if you have >= 255 distinct values, your bucket count is definitely smaller and therefore the histogram is definitely height-balanced. But if you have < 255 distinct values, either type is possible.

使用道具 举报

回复
论坛徽章:
26
2010年世界杯参赛球队:葡萄牙
日期:2012-09-20 14:59:08密尔沃基雄鹿
日期:2012-03-20 16:57:19海蓝宝石
日期:2012-07-26 23:23:38奥运会纪念徽章:乒乓球
日期:2012-09-07 16:24:16奥运会纪念徽章:足球
日期:2012-09-07 16:24:16马上有房
日期:2014-02-18 16:42:022014年新春福章
日期:2014-02-18 16:42:022013年新春福章
日期:2013-02-25 14:51:24灰彻蛋
日期:2012-12-31 12:03:56蜘蛛蛋
日期:2012-11-29 17:20:08
16#
发表于 2012-10-16 09:34 | 只看该作者
nice thank you

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表