oracle数据如何采集,Oracle 中列的histogram如何收集

最初由 ZALBB 发布

[B]赵哥怎么不看文档: analyze table table_name compute statistics for columns column_name size 254; [/B]

呵呵。。。没有用到过,所以没有仔细研究,找了一篇文章,不错

Automating histogram sampling with dbms_stats

May 14,  2003

Don Burleson

One exciting feature of dbms_stats is the ability to automatically look for columns that should have histograms, and create the histograms.  Multi-bucket histograms add a huge parsing overhead to SQL statements, and histograms should ONLY be used when the SQL will choose a different execution plan based upon the column value.

To aid in intelligent histogram generation, Oracle uses the method_opt parameter of dbms_stats.  There are also important new options within the method_opt clause, namely skewonly, repeat and auto.

method_opt=>'for all columns size skewonly'

method_opt=>'for all columns size repeat'

method_opt=>'for all columns size auto'

In practice, there is a specific order to use the different options of dbms_stats.  See this article for details.  Let’s take a close look at each method option.

The method_opt=’SKEWONLY’  dbms_stats Option

The first is the “skewonly” option which very time-intensive because it examines the distribution of values for every column within every index.  If dbms_stats discovers an index whose columns are unevenly distributed, it will create histograms for that index to aid the cost-based SQL optimizer in making a decision about index vs. full-table scan access.  For example, if an index has one column that is in 50% of the rows, a full-table scan is faster than and index scan to retrieve these rows.

Histograms are also used with SQL that has bind variables and SQL with cursor_sharing enabled.  In these cases, the CBO determines if the column value could affect the execution plan, and if so, replaced the bind variable with a literal and performs a hard parse.

--*************************************************************

-- SKEWONLY option – Detailed analysis

--

-- Use this method for a first-time analysis for skewed indexes

-- This runs a long time because all indexes are examined

--*************************************************************

begin

dbms_stats.gather_schema_stats(

ownname          => 'SCOTT',

estimate_percent => dbms_stats.auto_sample_size,

method_opt       => 'for all columns size skewonly',

degree           => 7

);

end;

/

The method_opt=’REPEAT’  dbms_stats Option

Following the one-time detailed analysis, the re-analyze task will be less resource intensive with the REPEAT option.  Using the repeat option will only re-analyze indexes with existing histograms, and will not search for other histograms opportunities.  This is the way that you will re-analyze you statistics on a regular basis.

--**************************************************************

-- REPEAT OPTION - Only re-analyze histograms for indexes

-- that have histograms

--

-- Following the initial analysis, the weekly analysis

-- job will use the “repeat” option.  The repeat option

-- tells dbms_stats that no indexes have changed, and

-- it will only re-analyze histograms for

-- indexes that have histograms.

--**************************************************************

begin

dbms_stats.gather_schema_stats(

ownname          => 'SCOTT',

estimate_percent => dbms_stats.auto_sample_size,

method_opt       => 'for all columns size repeat',

degree           => 7

);

end;

/

The method_opt=’AUTO’ dbms_stats Option

The auto option is used when monitoring is implemented and creates histograms based upon data distribution and the manner in which the column is accessed by the application (e.g. the workload on the column as determined by monitoring, especially foreign keys to determine the cardinality of table join result sets).  Using method_opt=>’auto’ is similar to using the gather auto in the option parameter of dbms_stats.

begin

dbms_stats.gather_schema_stats(

ownname          => 'SCOTT',

estimate_percent => dbms_stats.auto_sample_size,

method_opt       => 'for all columns size auto',

degree           => 7

);

end;

/

Remember, analyzing for histograms is time-consuming, and histograms are used under two conditions:

Table join order – The CBO must know the size of the intermediate result sets (cardinality) to properly determine the correct join order the multi-table joins.

Table access method – The CBO needs to know about columns in SQL where clauses, where the column value is skewed such that a full-table scan might be faster than an index range scan. Oracle uses this skew information in conjunction with the clustering_factor columns of the dba_indexes view.

Hence, this is the proper order for using the dbms_stats package to locate proper columns for histograms:

1. Skewonly option - You want to use skewonly to do histograms for skewed columns, for cases where the value will make a difference between a full-table scan and an index scan.

2. Monitor - Next, turn-on monitoring. Issue an “alter table xx monitoring” and “alter index yyy monitoring” command for all segments in your schema. This will monitor workload against

3. Auto option - Once monitoring is in-place, you need to re-analyze with the "auto" option to create histograms for join columns within tables. This is critical for the CBO to determine the proper join order for finding the driving table in multi-table joins.

4. Repeat option - Finally, use the "repeat" option to re-analyze only the existing histograms.

Periodically you will want to re-run the skewonly and auto option to identify any new columns that require histograms. Once located, the repeat option will ensure that they are refreshed with current values.

--------------------------------------------------------------------------------

If you like DBA internal tricks, check-out my new book Creating a Self-tuning Oracle Database by Rampant TechPress.  This book is now available at this link:

http://www.rampant-books.com/book_2003_1_oracle9i_sga.htm

Regards,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
会计软件数据采集 4.1系统概述 1、能采集、转换目前常用的用友、金蝶、安易、新中大、金算盘、浪潮、远光、远方、华兴、灵狐、速达、万能、通用、友强、金蜘蛛、降龙、益和、易统、润嘉、奥林岛、煤碳财务、金思维、复旦天翼、天大天财、小蜜蜂、北京通用、北嘉、兴竹、电信新逸、博科、管家婆、三门、科发通用、中财信事行财务、金财以及Sap/Oracle等80余种财务软件各个版本的数据,并能快速定制特殊财务软件数据采集接口。从6.2版本开始开放了数据采集转换接口,用户可以自己定义转换对应关系,直接读取各种(包括未支持财务软件及手工账数据)财务软件导出的科目汇总数据及凭证分录数据(格式为EXCEL,大多数财务软件有此功能),从而使本审计软件彻底解决数据接口问题。 2、采用只读不写的采集技术,保证了被审单位财务数据的安全性、准确性和完整性。 3、采集、转换工具都使用向导式技术,采集、转换流程清晰、直观、易操作。 4、转换、重新记帐步骤合并到一起,用户将被审单位的数据进行转换完毕后,就可以切换到通用财务审计系统进行审计分析。 登录审计管理平台后如下图4.1-1所示,点击登录平台中间的“快捷切换”右边的下拉式箭头,在弹出的下拉式菜单中选择【02-数据采集转换系统】,数据采集转换系统操作界面功能如下图4.1-1左边树型结构所示: 图4.1-1 数据采集转换系统

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值