



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
如何收集统计信息dbms_stats.gather_table_stats与analyze table 的区别转贴 - 参考 /viewthread.php?tid=845777&extra=&page=1Analyze StatementThe ANALYZE statement can be used to gather statistics for a specific table, index or cluster. The statistics can be computed exactly, or estimated based on a specific number of rows, or a percentage of rows:ANALYZE TABLE employees COMPUTE STATISTICS;ANALYZE INDEX employees_pk COMPUTE STATISTICS;ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 100 ROWS;ANALYZE TABLE employees ESTIMATE STATISTICS SAMPLE 15 PERCENT;DBMS_UTILITYThe DBMS_UTILITY package can be used to gather statistics for a whole schema or database. Both methods follow the same format as the analyze statement:EXEC DBMS_UTILITY.analyze_schema(SCOTT,COMPUTE);EXEC DBMS_UTILITY.analyze_schema(SCOTT,ESTIMATE, estimate_rows = 100);EXEC DBMS_UTILITY.analyze_schema(SCOTT,ESTIMATE, estimate_percent = 15);EXEC DBMS_UTILITY.analyze_database(COMPUTE);EXEC DBMS_UTILITY.analyze_database(ESTIMATE, estimate_rows = 100);EXEC DBMS_UTILITY.analyze_database(ESTIMATE, estimate_percent = 15);DBMS_STATSThe DBMS_STATS package was introduced in Oracle 8i and is Oracles preferred method of gathering object statistics. Oracle list a number of benefits to using it including parallel execution, long term storage of statistics and transfer of statistics between servers. Once again, it follows a similar format to the other methods:EXEC DBMS_STATS.gather_database_stats;EXEC DBMS_STATS.gather_database_stats(estimate_percent = 15);EXEC DBMS_STATS.gather_schema_stats(SCOTT);EXEC DBMS_STATS.gather_schema_stats(SCOTT, estimate_percent = 15);EXEC DBMS_STATS.gather_table_stats(SCOTT, EMPLOYEES);EXEC DBMS_STATS.gather_table_stats(SCOTT, EMPLOYEES, estimate_percent = 15);EXEC DBMS_STATS.gather_index_stats(SCOTT, EMPLOYEES_PK);EXEC DBMS_STATS.gather_index_stats(SCOTT, EMPLOYEES_PK, estimate_percent = 15);This package also gives you the ability to delete statistics:EXEC DBMS_STATS.delete_database_stats;EXEC DBMS_STATS.delete_schema_stats(SCOTT);EXEC DBMS_STATS.delete_table_stats(SCOTT, EMPLOYEES);EXEC DBMS_STATS.delete_index_stats(SCOTT, EMPLOYEES_PK);-自从Oracle8.1.5引入dbms_stats包,Experts们便推荐使用dbms_stats取代analyze。 理由如下dbms_stats可以并行分析dbms_stats有自动分析的功能(alter table monitor )analyze 分析统计信息的不准确some times1,2好理解,且第2点实际上在VLDB中是最吸引人的;3以前比较模糊,看了metalink236935.1 解释,analyze在分析Partition表的时候,有时候会计算出不准确的Global statistics .原因是,dbms_stats会实在的去分析表全局统计信息(当指定参数);而analyze是将表分区(局部)的statistics 汇总计算成表全局statistics ,可能导致误差。如果想分析整个用户或数据库,还可以采用工具包,可以并行分析Dbms_utility(8i以前的工具包)Dbms_stats(8i以后提供的工具包)如dbms_stats.gather_schema_stats(User,estimate_percent=100,cascade= TRUE);dbms_stats.gather_table_stats(User,TableName,degree = 4,cascade = true);这是对命令与工具包的一些总结1、对于分区表,建议使用DBMS_STATS,而不是使用Analyze语句。a) 可以并行进行,对多个用户,多个Tableb) 可以得到整个分区表的数据和单个分区的数据。c) 可以在不同级别上Compute Statistics:单个分区,子分区,全表,所有分区d) 可以倒出统计信息e) 可以用户自动收集统计信息2、DBMS_STATS的缺点a) 不能Validate Structureb) 不能收集CHAINED ROWS, 不能收集CLUSTER TABLE的信息,这两个仍旧需要使用Analyze语句。c) DBMS_STATS 默认不对索引进行Analyze,因为默认Cascade是False,需要手工指定为True3、对于oracle 9里面的External Table,Analyze不能使用,只能使用DBMS_STATS来收集信息。-10G的文档是这么说的:Do not use the COMPUTE and ESTIMATE clauses of ANALYZE to collect optimizer statistics. These clauses are supported for backward compatibility. Instead, use the DBMS_STATS package, which lets you collect statistics in parallel, collect global statistics for partitioned objects, and fine tune your statistics collection in other ways. The cost-based optimizer, which depends upon statistics, will eventually use only statistics that have been collected by DBMS_STATSanalyze的功能已经明确:Use the ANALYZE statement (rather than DBMS_STATS) forstatistics collection not related to the cost-based optimizer:To use the VALIDATE or LIST CHAINED ROWS clausesTo collect information on freelist blocks在收集与CBO优化器不相关的统计信息的时候ANALYZE语句要优于DBMS_STATS包-EX:beginfor owner in (select username from dba_users where username not in (SYS,SYSTEM)loopdbms_output.disable;dbms_output.enable(1000000);dbms_output.put_line(Schema: |owner.username);select sysdate into start_time from dual;dbms_output.put_line(Analyze start from : |start_time);dbms_stats.gather_schema_stats(ownname = owner.username, estimate_percent = 20, block_sample= true, cascade=true);select sysdate into end_time from dual;dbms_output.put_line(Analyze complete at : |end_time);dbms_output.put_line(-);end loop;dbms_st
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年安徽师范大学出版社招聘4人考前自测高频考点模拟试题及参考答案详解一套
- 2025年甘肃交通职业技术学院招聘工作人员模拟试卷含答案详解
- 2025江西吉水县某行政单位招聘4人模拟试卷及答案详解(考点梳理)
- 2025江苏南通市公安局招聘警务辅助人员66人考前自测高频考点模拟试题及一套答案详解
- 2025届春季中核集团校园招聘正式启动考前自测高频考点模拟试题及答案详解(典优)
- 2025年洛阳古墓博物馆人才引进招录专业技术人员2名模拟试卷及完整答案详解1套
- 2025年延安通和电业有限责任公司招聘(5人)模拟试卷及答案详解(易错题)
- 2025湖南湘西州泸溪县妇幼保健计划生育服务中心招聘高校见习生5人模拟试卷及完整答案详解一套
- 2025年陕西师范大学校医院招聘(2人)考前自测高频考点模拟试题及1套参考答案详解
- 2025年滁州职业技术学院引进急需紧缺高层次人才25人模拟试卷及答案详解(易错题)
- 2025四川成都高新投资集团有限公司选聘中高层管理人员4人笔试参考题库附答案解析
- 水利工程水利工程施工技术规范
- 从安全感缺失剖析《榆树下的欲望》中爱碧的悲剧根源与启示
- 2025中证金融研究院招聘11人考试参考题库及答案解析
- 人教版(2024)八年级上册英语Unit 2 Home Sweet Home教案
- 城镇住宅建设调查技术实施方案
- 渔民安全培训课件
- 时空数据建模与预测算法-洞察阐释
- 汽车电路原理培训课件
- 2025年长江引航中心招聘笔试备考题库(带答案详解)
- 压力性损伤的个案护理
评论
0/150
提交评论